diff --git a/debian/install b/debian/install index 243be76..20a2eb7 100644 --- a/debian/install +++ b/debian/install @@ -1,2 +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 diff --git a/pkgcheck b/pkgcheck new file mode 100755 index 0000000..bd61d79 --- /dev/null +++ b/pkgcheck @@ -0,0 +1,16 @@ +#!/bin/bash +branch="$1" +arch=$(dpkg --print-architecture) + +case "${branch}" in + "xenial"*) repo="repo.ubports.com";; + *) repo="repo2.ubports.com";; +esac + +while read pkg +do + status=$(apt-cache policy $pkg|awk '/Installed/{print $2}') + if [[ -n "${status}" && "$status" != "(none)" ]]; then + echo -n "${pkg} " + fi +done < <(awk '/Package/{print $2}' /var/lib/apt/lists/${repo}_dists_${branch//_/%5f}_main_binary-${arch}_Packages|uniq) diff --git a/pkginstall b/pkginstall new file mode 100755 index 0000000..6603521 --- /dev/null +++ b/pkginstall @@ -0,0 +1,4 @@ +#!/bin/bash +branch="$1" +pkgs=$(pkgcheck "$branch") +apt-get install $pkgs diff --git a/pkgremove b/pkgremove new file mode 100755 index 0000000..a8a16ac --- /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/pkgupdate b/pkgupdate new file mode 100755 index 0000000..936c3f4 --- /dev/null +++ b/pkgupdate @@ -0,0 +1,10 @@ +#!/bin/bash +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 < <(ls /etc/apt/sources.list.d/*) +apt-get install ${pkgs} diff --git a/ubports-qa b/ubports-qa index 457abec..7557a97 100755 --- a/ubports-qa +++ b/ubports-qa @@ -83,14 +83,26 @@ 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("Downgrading packages") 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 downgrade packages. See the output above for details.") +def apt_install(repository_name): + LOG.debug("Upgrading packages") + try: + subprocess.run(["pkginstall", repository_name], check=True) + except subprocess.CalledProcessError: + 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. See the output above for details.") def get_list_file(branch): list_file = "/etc/apt/sources.list.d/ubports-{}.list".format(branch) @@ -220,7 +232,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( @@ -238,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): @@ -251,7 +262,7 @@ def update_command(args): """Update all packages using apt""" with WritableRootFS(): apt_update() - apt_upgrade() + apt_upgrade_all() parser = argparse.ArgumentParser(