diff --git a/src/aptmanager.cpp b/src/aptmanager.cpp index 5c2d9de..1f628d8 100644 --- a/src/aptmanager.cpp +++ b/src/aptmanager.cpp @@ -144,6 +144,22 @@ void AptManager::handleUpdateProcessBuffer() conffileList.append(confLine); } } + } else if (line == "Lubuntu Update !!! NEW LTS RELEASE") { + // Same busy-wait technique, but here we're just getting one extra line, the model code. + while (!aptProcess->canReadLine()) { + QThread::msleep(20); + } + aptProcess->readLine(lineBuf, 2048); + QString ltsReleaseCode = QString(lineBuf); + emit newLtsRelease(ltsReleaseCode); + } else if (line == "Lubuntu Update !!! NEW STABLE RELEASE") { + // Ditto + while (!aptProcess->canReadLine()) { + QThread::msleep(20); + } + aptProcess->readLine(lineBuf, 2048); + QString stableReleaseCode = QString(lineBuf); + emit newStableRelease(stableReleaseCode); } double percentageDone = (static_cast(internalUpdateProgress) / (((internalUpdateInfo[0].count() + internalUpdateInfo[1].count()) * 4) + internalUpdateInfo[2].count())) * 100; diff --git a/src/aptmanager.h b/src/aptmanager.h index 49e0062..b946e1e 100644 --- a/src/aptmanager.h +++ b/src/aptmanager.h @@ -28,6 +28,8 @@ signals: void progressUpdated(int progress); void logLineReady(QString logLine); void conffileListReady(QStringList conffileList); + void newLtsRelease(QString code); + void newStableRelease(QString code); private slots: void handleUpdateProcessBuffer(); diff --git a/src/lubuntu-update-backend b/src/lubuntu-update-backend index da4af65..4c0ba2a 100755 --- a/src/lubuntu-update-backend +++ b/src/lubuntu-update-backend @@ -4,6 +4,43 @@ set -e export LC_ALL='C' +# Returns 0 if the release is supported, 1 if unsupported, 2 if if didn't exist at all, and 3 if something went wrong. +isReleaseSupported () { + releaseYear="${1:-}"; + releaseMonth="${2:-}"; + metaReleaseStr="${3:-}"; + + if [ -z "$releaseYear" ]; then + echo '! ! ! releaseYear is blank'; + return 3; + elif [ -z "$releaseMonth" ]; then + echo '! ! ! releaseMonth is blank'; + return 3; + elif [ -z "$metaReleaseStr" ]; then + echo '! ! ! metaReleaseStr is blank'; + return 3; + fi + + releaseCode="$releaseYear.$releaseMonth"; + scanForSupported='n'; + + while IFS= read -r line || [[ -n $line ]]; do + if [[ "$line" =~ $releaseCode ]]; then + scanForSupported='y'; + fi + if [ "$scanForSupported" = 'y' ]; then + if [[ "$line" =~ Supported ]]; then + if [ "$(echo "$line" | cut -d':' -f2 | tail -c+2)" = '0' ]; then + return 1; + else + return 0; + fi + fi + fi + done < <(printf '%s' "$metaReleaseStr") + return 2; +} + if [ "$1" = 'pkgver' ]; then shift while [ "$1" != '' ]; do @@ -90,5 +127,42 @@ elif [ "$1" = 'doupdate' ]; then fi done + echo 'Checking release status...' + + releaseCode="$(cat /etc/lsb-release | grep "DISTRIB_RELEASE" | cut -d'=' -f2)"; + releaseYear="$(cut -d'.' -f1 <<< "$releaseCode")"; + releaseMonth="$(cut -d'.' -f2 <<< "$releaseCode")"; + metaReleaseData="$(curl https://changelogs.ubuntu.com/meta-release)"; + nextReleaseMonth=''; + nextReleaseYear=''; + nextLTSReleaseMonth=''; + nextLTSReleaseYear=''; + + if ((releaseMonth == 4)); then + nextReleaseMonth=((releaseMonth + 6)); + nextReleaseYear="$releaseYear"; + if (((releaseYear % 2) == 0)); then + nextLTSReleaseMonth='04'; + nextLTSReleaseYear=((releaseYear + 2)); + fi + else + nextReleaseMonth="$releaseMonth"; + nextReleaseYear=((releaseYear + 1)); + fi + + if [ -n "$nextLTSReleaseYear" ]; then + if isReleaseSupported "$nextLTSReleaseYear" "$nextLTSReleaseMonth" "$metaReleaseData"; then + echo 'Lubuntu Update !!! NEW LTS RELEASE'; + echo "$nextLTSReleaseYear.$nextLTSReleaseMonth"; + fi + fi + + if ! (((nextReleaseYear == nextLTSReleaseYear) && (nextReleaseMonth == nextLTSReleaseMonth))); then + if isReleaseSupported "$nextReleaseYear" "$nextReleaseMonth" "$metaReleaseData"; then + echo 'Lubuntu Update !!! NEW STABLE RELEASE'; + echo "$nextReleaseYear.$nextReleaseMonth"; + fi + fi + echo 'Update installation complete.' fi diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 9eceba3..b2c23fa 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -25,6 +25,8 @@ MainWindow::MainWindow(QWidget *parent) connect(aptManager, &AptManager::progressUpdated, this, &MainWindow::onProgressUpdate); connect(aptManager, &AptManager::logLineReady, this, &MainWindow::onLogLineReady); connect(aptManager, &AptManager::conffileListReady, this, &MainWindow::onConffileListReady); + connect(aptManager, &AptManager::newLtsRelease, this, &MainWindow::onNewLtsRelease); + connect(aptManager, &AptManager::newStableRelease, this, &MainWindow::onNewStableRelease); } MainWindow::~MainWindow() @@ -143,6 +145,7 @@ void MainWindow::onUpdateCompleted() ui->progressBar->setVisible(false); ui->statLabel->setText(tr("Update installation complete.")); emit updatesInstalled(); // this tells the orchestrator to hide the tray icon + handleNewReleases(); } void MainWindow::onCheckUpdatesCompleted() @@ -175,3 +178,20 @@ void MainWindow::onConffileListReady(QStringList conffileList) } aptManager->doneWithConffiles(); } + +void MainWindow::onNewLtsRelease(QString code) +{ + newLtsReleaseAvailable = true; +} + +void MainWindow::onNewStableRelease(QString code) +{ + newStableReleaseAvailable = true; +} + +void MainWindow::handleNewReleases() +{ + // TODO: Write code that informs the user when a new release is available here + newLtsReleaseAvailable = false; + newStableReleaseAvailable = false; +} diff --git a/src/mainwindow.h b/src/mainwindow.h index c5415e5..5748b1c 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -39,9 +39,15 @@ private slots: void onProgressUpdate(int progress); void onLogLineReady(QString logLine); void onConffileListReady(QStringList conffileList); + void onNewLtsRelease(QString code); + void onNewStableRelease(QString code); private: Ui::MainWindow *ui; AptManager *aptManager; + bool newLtsReleaseAvailable = false; + bool newStableReleaseAvailable = false; + + void handleNewReleases(); }; #endif // MAINWINDOW_H