From 9a41afd01199472d337377af65728313ec08b20b Mon Sep 17 00:00:00 2001 From: Aaron Rainbolt Date: Fri, 2 Feb 2024 11:09:29 -0600 Subject: [PATCH] Major bugfixes to do-release-upgrade code --- src/aptmanager.cpp | 9 +- src/aptmanager.h | 3 +- src/lubuntu-update-backend | 173 ++++++++++++++++++++----------------- src/mainwindow.cpp | 6 +- src/orchestrator.cpp | 7 +- 5 files changed, 111 insertions(+), 87 deletions(-) diff --git a/src/aptmanager.cpp b/src/aptmanager.cpp index 171846b..bf773c5 100644 --- a/src/aptmanager.cpp +++ b/src/aptmanager.cpp @@ -144,14 +144,15 @@ void AptManager::handleUpdateProcessBuffer() conffileList.append(confLine); } } - } else if (line == "Lubuntu Update !!! NEW RELEASE") { - // Same busy-wait technique, but here we're just getting one extra line, the model code. + } else if (line == "Lubuntu Update !!! NEW RELEASE\r\n") { + // Same busy-wait technique, but here we're just getting one extra line, the release code. while (!aptProcess->canReadLine()) { QThread::msleep(20); } aptProcess->readLine(lineBuf, 2048); - QString ltsReleaseCode = QString(lineBuf); - emit newLtsRelease(ltsReleaseCode); + QString releaseCode = QString(lineBuf); + releaseCode = releaseCode.left(releaseCode.count() - 2); + emit newRelease(releaseCode); } 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 b946e1e..5d625c5 100644 --- a/src/aptmanager.h +++ b/src/aptmanager.h @@ -28,8 +28,7 @@ signals: void progressUpdated(int progress); void logLineReady(QString logLine); void conffileListReady(QStringList conffileList); - void newLtsRelease(QString code); - void newStableRelease(QString code); + void newRelease(QString code); private slots: void handleUpdateProcessBuffer(); diff --git a/src/lubuntu-update-backend b/src/lubuntu-update-backend index 6af78b7..ce47f85 100755 --- a/src/lubuntu-update-backend +++ b/src/lubuntu-update-backend @@ -69,63 +69,66 @@ elif [ "$1" = 'doupdate' ]; then DEBIAN_FRONTEND='kde' apt-get -o Dpkg::Options::='--force-confdef' -o Dpkg::Options::='--force-confold' -o Apt::Color='0' -o Dpkg::Use-Pty='0' -y dist-upgrade |& tee /run/lubuntu-update-apt-log # Find all the conffiles + doConffiles='y'; mapfile conffileRawList <<< "$(grep -P "^Configuration file \'.*\'$" '/run/lubuntu-update-apt-log')" if [ "$(echo "${conffileRawList[0]}" | head -c1)" != 'C' ]; then # Empty or invalid list, we're done - exit 0 + doConffiles='n'; fi - conffileList=() - counter=0 - while [ "$counter" -lt "${#conffileRawList[@]}" ]; do - # Cut off "Configuration file '" from the start and "'" plus a couple trailing characters from the end - conffileList[counter]="$(echo "${conffileRawList[$counter]}" | tail -c+21 | head -c-3)" - counter=$((counter+1)) - done - - echo "Lubuntu Update !!! CONFIGURATION FILE LIST START"; - counter=0 - while [ "$counter" -lt "${#conffileList[@]}" ]; do - echo "${conffileList[$counter]}" - counter=$((counter+1)) - done - echo "Lubuntu Update !!! CONFIGURATION FILE LIST END"; - - # If we make it this far, there were conffiles to deal with - breakLoop='no' - gotCommand='no' - commandName='' - while [ "$breakLoop" = 'no' ]; do - read -r inputVal - if [ "$gotCommand" = 'no' ]; then - if [ "$inputVal" = 'done' ]; then - breakLoop='yes' + if [ "$doConffiles" = 'y' ]; then + conffileList=() + counter=0 + while [ "$counter" -lt "${#conffileRawList[@]}" ]; do + # Cut off "Configuration file '" from the start and "'" plus a couple trailing characters from the end + conffileList[counter]="$(echo "${conffileRawList[$counter]}" | tail -c+21 | head -c-3)" + counter=$((counter+1)) + done + + echo "Lubuntu Update !!! CONFIGURATION FILE LIST START"; + counter=0 + while [ "$counter" -lt "${#conffileList[@]}" ]; do + echo "${conffileList[$counter]}" + counter=$((counter+1)) + done + echo "Lubuntu Update !!! CONFIGURATION FILE LIST END"; + + # If we make it this far, there were conffiles to deal with + breakLoop='no' + gotCommand='no' + commandName='' + while [ "$breakLoop" = 'no' ]; do + read -r inputVal + if [ "$gotCommand" = 'no' ]; then + if [ "$inputVal" = 'done' ]; then + breakLoop='yes' + else + commandName="$inputVal" + gotCommand='yes' + fi else - commandName="$inputVal" - gotCommand='yes' - fi - else - if [ "$commandName" = 'replace' ]; then # Replace an existing file - counter=0 - while [ "$counter" -lt "${#conffileList[@]}" ]; do - if [ "$inputVal" = "${conffileList[$counter]}" ]; then - mv "$inputVal.dpkg-dist" "$inputVal" - break - fi - counter=$((counter+1)) - done - elif [ "$commandName" = 'keep' ]; then # Keep an existing file - counter=0 - while [ "$counter" -lt "${#conffileList[@]}" ]; do - if [ "$inputVal" = "${conffileList[$counter]}" ]; then - rm "$inputVal.dpkg-dist" - break - fi - counter=$((counter+1)) - done + if [ "$commandName" = 'replace' ]; then # Replace an existing file + counter=0 + while [ "$counter" -lt "${#conffileList[@]}" ]; do + if [ "$inputVal" = "${conffileList[$counter]}" ]; then + mv "$inputVal.dpkg-dist" "$inputVal" + break + fi + counter=$((counter+1)) + done + elif [ "$commandName" = 'keep' ]; then # Keep an existing file + counter=0 + while [ "$counter" -lt "${#conffileList[@]}" ]; do + if [ "$inputVal" = "${conffileList[$counter]}" ]; then + rm "$inputVal.dpkg-dist" + break + fi + counter=$((counter+1)) + done + fi + gotCommand='no' fi - gotCommand='no' - fi - done + done + fi echo 'Checking release status...' @@ -133,36 +136,52 @@ elif [ "$1" = 'doupdate' ]; then 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)); + #nextReleaseMonth=''; + #nextReleaseYear=''; + #nextLTSReleaseMonth=''; + #nextLTSReleaseYear=''; + + while true; do + if ((releaseMonth == 4)); then + releaseMonth='10'; + else + releaseMonth='04'; + ((releaseYear++)); fi - else - nextReleaseMonth="$releaseMonth"; - nextReleaseYear=((releaseYear + 1)); - fi - - if [ -n "$nextLTSReleaseYear" ]; then - if isReleaseSupported "$nextLTSReleaseYear" "$nextLTSReleaseMonth" "$metaReleaseData"; then + if isReleaseSupported "$releaseYear" "$releaseMonth" "$metaReleaseData"; then echo 'Lubuntu Update !!! NEW RELEASE'; - echo "$nextLTSReleaseYear.$nextLTSReleaseMonth"; + echo "$releaseYear.$releaseMonth"; + break; fi - fi + done - if ! (((nextReleaseYear == nextLTSReleaseYear) && (nextReleaseMonth == nextLTSReleaseMonth))); then - if isReleaseSupported "$nextReleaseYear" "$nextReleaseMonth" "$metaReleaseData"; then - echo 'Lubuntu Update !!! NEW RELEASE'; - echo "$nextReleaseYear.$nextReleaseMonth"; - fi - fi +# 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 RELEASE'; +# echo "$nextLTSReleaseYear.$nextLTSReleaseMonth"; +# fi +# fi +# +# if ! (((nextReleaseYear == nextLTSReleaseYear) && (nextReleaseMonth == nextLTSReleaseMonth))); then +# if isReleaseSupported "$nextReleaseYear" "$nextReleaseMonth" "$metaReleaseData"; then +# echo 'Lubuntu Update !!! NEW RELEASE'; +# echo "$nextReleaseYear.$nextReleaseMonth"; +# else +# echo "Unsupported release: $nextReleaseYear.$nextReleaseMonth"; +# fi +# fi echo 'Update installation complete.' elif [ "$1" = 'doReleaseUpgrade' ]; then diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 6ecd419..b9b2022 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -25,7 +25,7 @@ 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::onNewRelease); + connect(aptManager, &AptManager::newRelease, this, &MainWindow::onNewRelease); } MainWindow::~MainWindow() @@ -144,7 +144,9 @@ 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(); + if (releaseCodes.count() > 0) { + handleNewReleases(); + } } void MainWindow::onCheckUpdatesCompleted() diff --git a/src/orchestrator.cpp b/src/orchestrator.cpp index 135a8f2..fc1440b 100644 --- a/src/orchestrator.cpp +++ b/src/orchestrator.cpp @@ -26,7 +26,7 @@ Orchestrator::Orchestrator(QObject *parent) bool success = configFile.open(QFile::ReadOnly); if (success) { char lineBuf[2048]; - while (configFile.canReadLine()) { + while (!configFile.atEnd()) { configFile.readLine(lineBuf, 2048); QString line(lineBuf); line = line.trimmed(); @@ -107,7 +107,7 @@ void Orchestrator::onNewReleaseAvailable(QStringList releaseCodes) QString druType; if (success) { char lineBuf[2048]; - while (druTypeFile.canReadLine()) { + while (!druTypeFile.atEnd()) { druTypeFile.readLine(lineBuf, 2048); QString line(lineBuf); line = line.trimmed(); @@ -125,6 +125,9 @@ void Orchestrator::onNewReleaseAvailable(QStringList releaseCodes) break; } } + } else { + druType="normal"; + druTypeFile.close(); } for (int i = 0;i < releaseCodes.count();i++) {