From dd5382e42fa450a839ab5a19ddbeb6ccbdfa729b Mon Sep 17 00:00:00 2001 From: Rahammetoela Toekiman Date: Sun, 20 Feb 2022 15:13:19 -0300 Subject: [PATCH 01/13] upgrade only the related installed packages --- debian/install | 1 + pkginstall | 17 +++++++++++++++++ ubports-qa | 9 ++++++++- 3 files changed, 26 insertions(+), 1 deletion(-) create mode 100755 pkginstall diff --git a/debian/install b/debian/install index 243be76..87bdd64 100644 --- a/debian/install +++ b/debian/install @@ -1,2 +1,3 @@ ubports-qa /usr/bin +pkginstall /usr/bin ubports-qa_completion /etc/bash_completion.d diff --git a/pkginstall b/pkginstall new file mode 100755 index 0000000..a3b32af --- /dev/null +++ b/pkginstall @@ -0,0 +1,17 @@ +#!/bin/bash +branch=$1 +arch=$(dpkg --print-architecture) + +case "${branch}" in + "xenial"*) repo="repo.ubports.com";; + *) repo="repo2.ubports.com";; +esac + +readarray -t pkgs < <(awk '/Package/{print $2}' /var/lib/apt/lists/${repo}_dists_${branch//_/%5f}_main_binary-${arch}_Packages|uniq) +relpkgs=() +for pkg in "${pkgs[@]}" +do + status=$(apt-cache policy $pkg|awk '/Installed/{print $2}') + [ "$status" != "(none)" ] && relpkgs=${relpkgs}" "${pkg} +done +apt install $relpkgs diff --git a/ubports-qa b/ubports-qa index 457abec..7725e13 100755 --- a/ubports-qa +++ b/ubports-qa @@ -91,6 +91,13 @@ def apt_upgrade(): except subprocess.CalledProcessError: LOG.error("Failed to run 'apt full-upgrade'. See the output above for details.") +def apt_install(repository_name): + LOG.debug("upgrading package") + try: + subprocess.run(["pkginstall", repository_name], check=True) + except subprocess.CalledProcessError: + LOG.error("Failed to install Package") + def get_list_file(branch): list_file = "/etc/apt/sources.list.d/ubports-{}.list".format(branch) @@ -220,7 +227,7 @@ def install_command(args): add_list(repository_name) add_pref(repository_name) apt_update() - apt_upgrade() + apt_install(repository_name) LOG.info( "You can remove this repository by running 'sudo ubports-qa remove {}'".format( From f6b4b5e279b9fd25c7d01f1f16509c5bc1cc1f24 Mon Sep 17 00:00:00 2001 From: fuseteam Date: Sun, 6 Mar 2022 03:08:04 -0300 Subject: [PATCH 02/13] use apt-get instead of apt --- pkginstall | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkginstall b/pkginstall index a3b32af..42586bd 100755 --- a/pkginstall +++ b/pkginstall @@ -14,4 +14,4 @@ do status=$(apt-cache policy $pkg|awk '/Installed/{print $2}') [ "$status" != "(none)" ] && relpkgs=${relpkgs}" "${pkg} done -apt install $relpkgs +apt-get install $relpkgs From aed29cc9814d0a6c2e9a5c7105aef6670b7cbeac Mon Sep 17 00:00:00 2001 From: fuseteam Date: Mon, 7 Mar 2022 02:38:19 -0300 Subject: [PATCH 03/13] upgrade only the packages related to pr repos --- pkgupdate | 10 ++++++++++ ubports-qa | 8 +++++++- 2 files changed, 17 insertions(+), 1 deletion(-) create mode 100755 pkgupdate diff --git a/pkgupdate b/pkgupdate new file mode 100755 index 0000000..0a19636 --- /dev/null +++ b/pkgupdate @@ -0,0 +1,10 @@ +#!/bin/bash +readarray -t lists < <(ls /etc/apt/sources.list.d/*) +for list in "${lists[@]}" +do + list=$(basename "${list}") + if [[ "${list}" != "ubports.list" && "${list}" != "ubports-android9.list" ]]; then + list="${list/ubports-/}" + pkginstall "${list/.list/}" + fi +done diff --git a/ubports-qa b/ubports-qa index 7725e13..237ad3d 100755 --- a/ubports-qa +++ b/ubports-qa @@ -98,6 +98,12 @@ def apt_install(repository_name): except subprocess.CalledProcessError: LOG.error("Failed to install Package") +def apt_upgrade_all(): + LOG.debug("upgrading all qa package") + try: + subprocess.run(["pkgupdate"], check=True) + except subprocess.CalledProcessError: + LOG.error("Failed to install Package") def get_list_file(branch): list_file = "/etc/apt/sources.list.d/ubports-{}.list".format(branch) @@ -258,7 +264,7 @@ def update_command(args): """Update all packages using apt""" with WritableRootFS(): apt_update() - apt_upgrade() + apt_upgrade_all() parser = argparse.ArgumentParser( From c97c1f231dfbadb476146df1158b88f69613214f Mon Sep 17 00:00:00 2001 From: fuseteam Date: Mon, 7 Mar 2022 16:15:41 -0300 Subject: [PATCH 04/13] downgrades only the related packages ubports-qa remove --- pkgcheck | 17 +++++++++++++++++ pkgremove | 5 +++++ ubports-qa | 12 +++++------- 3 files changed, 27 insertions(+), 7 deletions(-) create mode 100755 pkgcheck create mode 100755 pkgremove diff --git a/pkgcheck b/pkgcheck new file mode 100755 index 0000000..254f187 --- /dev/null +++ b/pkgcheck @@ -0,0 +1,17 @@ +#!/bin/bash +branch=$1 +arch=$(dpkg --print-architecture) + +case "${branch}" in + "xenial"*) repo="repo.ubports.com";; + *) repo="repo2.ubports.com";; +esac + +readarray -t pkgs < <(awk '/Package/{print $2}' /var/lib/apt/lists/${repo}_dists_${branch//_/%5f}_main_binary-${arch}_Packages|uniq) +relpkgs=() +for pkg in "${pkgs[@]}" +do + status=$(apt-cache policy $pkg|awk '/Installed/{print $2}') + [ "$status" != "(none)" ] && relpkgs=${relpkgs}" "${pkg} +done +echo $relpkgs diff --git a/pkgremove b/pkgremove new file mode 100755 index 0000000..60dfc62 --- /dev/null +++ b/pkgremove @@ -0,0 +1,5 @@ +#!/bin/bash +branch=$1 +pkgs=$(pkgcheck "${branch}") +apt-get update +apt-get install $pkgs diff --git a/ubports-qa b/ubports-qa index 237ad3d..8383fd0 100755 --- a/ubports-qa +++ b/ubports-qa @@ -83,13 +83,12 @@ def apt_update(): LOG.error("Failed to run 'apt update'. See the output above for details.") -def apt_upgrade(): - LOG.debug("Running 'apt full-upgrade'.") +def apt_remove(repository): + LOG.debug("Running 'apt remove'.") try: - subprocess.run(["apt", "full-upgrade"], check=True) - subprocess.run(["apt", "autoremove"], check=True) + subprocess.run(["pkgremove", repository], check=True) except subprocess.CalledProcessError: - LOG.error("Failed to run 'apt full-upgrade'. See the output above for details.") + LOG.error("Failed to run 'apt remove'. See the output above for details.") def apt_install(repository_name): LOG.debug("upgrading package") @@ -251,8 +250,7 @@ def remove_command(args): with WritableRootFS(): remove_list(repository) remove_pref(repository) - apt_update() - apt_upgrade() + apt_remove(repository) def list_command(args): From f5f3deba11f017ba61711f45270a3e7982e61384 Mon Sep 17 00:00:00 2001 From: fuseteam Date: Mon, 7 Mar 2022 16:16:31 -0300 Subject: [PATCH 05/13] make pkginstall make use of the new pkgcheck --- pkginstall | 17 ++--------------- 1 file changed, 2 insertions(+), 15 deletions(-) diff --git a/pkginstall b/pkginstall index 42586bd..b5c7fcf 100755 --- a/pkginstall +++ b/pkginstall @@ -1,17 +1,4 @@ #!/bin/bash branch=$1 -arch=$(dpkg --print-architecture) - -case "${branch}" in - "xenial"*) repo="repo.ubports.com";; - *) repo="repo2.ubports.com";; -esac - -readarray -t pkgs < <(awk '/Package/{print $2}' /var/lib/apt/lists/${repo}_dists_${branch//_/%5f}_main_binary-${arch}_Packages|uniq) -relpkgs=() -for pkg in "${pkgs[@]}" -do - status=$(apt-cache policy $pkg|awk '/Installed/{print $2}') - [ "$status" != "(none)" ] && relpkgs=${relpkgs}" "${pkg} -done -apt-get install $relpkgs +pkgs=$(pkgcheck $branch) +apt-get install $pkgs From 44f05e33be0b1d0013a1140267b1ad1da72ef8f4 Mon Sep 17 00:00:00 2001 From: fuseteam Date: Mon, 7 Mar 2022 16:21:49 -0300 Subject: [PATCH 06/13] also utilize pkgcheck for ubports-qa update --- pkgupdate | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pkgupdate b/pkgupdate index 0a19636..0102ff1 100755 --- a/pkgupdate +++ b/pkgupdate @@ -1,10 +1,12 @@ #!/bin/bash readarray -t lists < <(ls /etc/apt/sources.list.d/*) +pkgs="" for list in "${lists[@]}" do list=$(basename "${list}") if [[ "${list}" != "ubports.list" && "${list}" != "ubports-android9.list" ]]; then list="${list/ubports-/}" - pkginstall "${list/.list/}" + pkgs=$(pkgcheck "${list/.list/}")" "${pkgs} fi done +apt-get install ${pkgs} From 42b5924d5fcc633684a27583a7f98978906370d3 Mon Sep 17 00:00:00 2001 From: fuseteam Date: Mon, 7 Mar 2022 16:25:01 -0300 Subject: [PATCH 07/13] actually install all the needed scripts --- debian/install | 3 +++ 1 file changed, 3 insertions(+) diff --git a/debian/install b/debian/install index 87bdd64..20a2eb7 100644 --- a/debian/install +++ b/debian/install @@ -1,3 +1,6 @@ ubports-qa /usr/bin pkginstall /usr/bin +pkgcheck /usr/bin +pkgremove /usr/bin +pkgupdate /usr/bin ubports-qa_completion /etc/bash_completion.d From f3c8a7bca946d8ec8cadd445f4f27b81e65058f2 Mon Sep 17 00:00:00 2001 From: fuseteam Date: Mon, 7 Mar 2022 19:11:59 -0300 Subject: [PATCH 08/13] check if $status exists --- pkgcheck | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pkgcheck b/pkgcheck index 254f187..3e72c33 100755 --- a/pkgcheck +++ b/pkgcheck @@ -12,6 +12,8 @@ relpkgs=() for pkg in "${pkgs[@]}" do status=$(apt-cache policy $pkg|awk '/Installed/{print $2}') - [ "$status" != "(none)" ] && relpkgs=${relpkgs}" "${pkg} + if [[ -n "${status}" && "$status" != "(none)" ]]; then + relpkgs=${relpkgs}" "${pkg} + fi done echo $relpkgs From fe2e22d21925ab56ef295c2c0b88938e445f5c4d Mon Sep 17 00:00:00 2001 From: fuseteam Date: Tue, 8 Mar 2022 10:16:07 -0300 Subject: [PATCH 09/13] quote variables for extra safety --- pkgcheck | 2 +- pkginstall | 4 ++-- pkgremove | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/pkgcheck b/pkgcheck index 3e72c33..a7fd664 100755 --- a/pkgcheck +++ b/pkgcheck @@ -1,5 +1,5 @@ #!/bin/bash -branch=$1 +branch="$1" arch=$(dpkg --print-architecture) case "${branch}" in diff --git a/pkginstall b/pkginstall index b5c7fcf..6603521 100755 --- a/pkginstall +++ b/pkginstall @@ -1,4 +1,4 @@ #!/bin/bash -branch=$1 -pkgs=$(pkgcheck $branch) +branch="$1" +pkgs=$(pkgcheck "$branch") apt-get install $pkgs diff --git a/pkgremove b/pkgremove index 60dfc62..a8a16ac 100755 --- a/pkgremove +++ b/pkgremove @@ -1,5 +1,5 @@ #!/bin/bash -branch=$1 +branch="$1" pkgs=$(pkgcheck "${branch}") apt-get update apt-get install $pkgs From 8bdb818701057a37df0070a392386c9252089e6f Mon Sep 17 00:00:00 2001 From: fuseteam Date: Tue, 8 Mar 2022 10:40:58 -0300 Subject: [PATCH 10/13] pass the list of packages directly into the loop --- pkgcheck | 8 +++----- pkgupdate | 6 ++---- 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/pkgcheck b/pkgcheck index a7fd664..5d27568 100755 --- a/pkgcheck +++ b/pkgcheck @@ -7,13 +7,11 @@ case "${branch}" in *) repo="repo2.ubports.com";; esac -readarray -t pkgs < <(awk '/Package/{print $2}' /var/lib/apt/lists/${repo}_dists_${branch//_/%5f}_main_binary-${arch}_Packages|uniq) -relpkgs=() -for pkg in "${pkgs[@]}" +while read pkg do status=$(apt-cache policy $pkg|awk '/Installed/{print $2}') if [[ -n "${status}" && "$status" != "(none)" ]]; then relpkgs=${relpkgs}" "${pkg} fi -done -echo $relpkgs +done < <(awk '/Package/{print $2}' /var/lib/apt/lists/${repo}_dists_${branch//_/%5f}_main_binary-${arch}_Packages|uniq) +echo "${relpkgs}" diff --git a/pkgupdate b/pkgupdate index 0102ff1..936c3f4 100755 --- a/pkgupdate +++ b/pkgupdate @@ -1,12 +1,10 @@ #!/bin/bash -readarray -t lists < <(ls /etc/apt/sources.list.d/*) -pkgs="" -for list in "${lists[@]}" +while read list do list=$(basename "${list}") if [[ "${list}" != "ubports.list" && "${list}" != "ubports-android9.list" ]]; then list="${list/ubports-/}" pkgs=$(pkgcheck "${list/.list/}")" "${pkgs} fi -done +done < <(ls /etc/apt/sources.list.d/*) apt-get install ${pkgs} From 748d5cbe12b5d9087fe9adab268b660dac4727be Mon Sep 17 00:00:00 2001 From: fuseteam Date: Tue, 8 Mar 2022 10:41:42 -0300 Subject: [PATCH 11/13] directly echo in the loop --- pkgcheck | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/pkgcheck b/pkgcheck index 5d27568..bd61d79 100755 --- a/pkgcheck +++ b/pkgcheck @@ -11,7 +11,6 @@ while read pkg do status=$(apt-cache policy $pkg|awk '/Installed/{print $2}') if [[ -n "${status}" && "$status" != "(none)" ]]; then - relpkgs=${relpkgs}" "${pkg} + echo -n "${pkg} " fi done < <(awk '/Package/{print $2}' /var/lib/apt/lists/${repo}_dists_${branch//_/%5f}_main_binary-${arch}_Packages|uniq) -echo "${relpkgs}" From 2e6669e6fe478072c7d4464f85f861e26f47a871 Mon Sep 17 00:00:00 2001 From: fuseteam Date: Tue, 8 Mar 2022 10:50:25 -0300 Subject: [PATCH 12/13] start all log line with uppercase xd --- ubports-qa | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ubports-qa b/ubports-qa index 8383fd0..48974cf 100755 --- a/ubports-qa +++ b/ubports-qa @@ -91,14 +91,14 @@ def apt_remove(repository): LOG.error("Failed to run 'apt remove'. See the output above for details.") def apt_install(repository_name): - LOG.debug("upgrading package") + LOG.debug("Upgrading package") try: subprocess.run(["pkginstall", repository_name], check=True) except subprocess.CalledProcessError: LOG.error("Failed to install Package") def apt_upgrade_all(): - LOG.debug("upgrading all qa package") + LOG.debug("Upgrading all qa package") try: subprocess.run(["pkgupdate"], check=True) except subprocess.CalledProcessError: From ebdff7fd3ae9803fb102ff11a451dfa7a140e6d7 Mon Sep 17 00:00:00 2001 From: fuseteam Date: Tue, 8 Mar 2022 10:58:26 -0300 Subject: [PATCH 13/13] improve the log messages to be more accurate --- ubports-qa | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/ubports-qa b/ubports-qa index 48974cf..7557a97 100755 --- a/ubports-qa +++ b/ubports-qa @@ -84,25 +84,25 @@ def apt_update(): def apt_remove(repository): - LOG.debug("Running 'apt remove'.") + LOG.debug("Downgrading packages") try: subprocess.run(["pkgremove", repository], check=True) except subprocess.CalledProcessError: - LOG.error("Failed to run 'apt remove'. See the output above for details.") + LOG.error("Failed to downgrade packages. See the output above for details.") def apt_install(repository_name): - LOG.debug("Upgrading package") + LOG.debug("Upgrading packages") try: subprocess.run(["pkginstall", repository_name], check=True) except subprocess.CalledProcessError: - LOG.error("Failed to install Package") + LOG.error("Failed to upgrade Packages. See the output above for details.") def apt_upgrade_all(): LOG.debug("Upgrading all qa package") try: subprocess.run(["pkgupdate"], check=True) except subprocess.CalledProcessError: - LOG.error("Failed to install Package") + LOG.error("Failed to install Package. See the output above for details.") def get_list_file(branch): list_file = "/etc/apt/sources.list.d/ubports-{}.list".format(branch)