From 1fdc5e2d15665e2778b9d30480760d30b3856f4e Mon Sep 17 00:00:00 2001 From: abeudin Date: Tue, 11 Mar 2014 17:58:26 +0100 Subject: [PATCH 01/20] Update action_map.yml --- action_map.yml | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/action_map.yml b/action_map.yml index 42568c7a..adfba131 100644 --- a/action_map.yml +++ b/action_map.yml @@ -855,6 +855,21 @@ tools: help: Subscribe domain to a DynDNS service action: store_true + ### tools_update() + update: + action_help: YunoHost update + api: POST /update + + ### tools_changelog() + changelog: + action_help: YunoHost changelog + api: POST /changelog + + ### tools_upgrade() + upgrade: + action_help: YunoHost upgrade + api: POST /upgrade + ############################# # Hook # From 292000ec541119988df17ff08891576fc62531db Mon Sep 17 00:00:00 2001 From: abeudin Date: Tue, 11 Mar 2014 17:59:18 +0100 Subject: [PATCH 02/20] Update yunohost_tools.py --- yunohost_tools.py | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/yunohost_tools.py b/yunohost_tools.py index 5fc68786..82ce4d19 100644 --- a/yunohost_tools.py +++ b/yunohost_tools.py @@ -262,3 +262,36 @@ def tools_postinstall(domain, password, dyndns=False): win_msg(_("YunoHost has been successfully configured")) +def tools_update(): + """ + Update distribution + + """ + + process = Popen("/usr/local/bin/checkupdate", stdout=PIPE) + stdout, stderr = process.communicate() + if process.returncode == 1: + win_msg( _("Not upgrade found")) + elif process.returncode == 2: + raise YunoHostError(17, _("Error during update")) + else: + return { "Update" : stdout.splitlines() } + +def tools_changelog(): + """ + Show Changelog + + """ + + + +def tools_upgrade(): + """ + Upgrade distribution + + """ + + if os.path.isfile('/tmp/update_status'): + os.system('at now -f /etc/yunohost/upgrade') + else: + raise YunoHostError(17, _("Launch update before upgrade")) From 6d8a89dcf89b1af562335eb0b5d2a75662ff112c Mon Sep 17 00:00:00 2001 From: abeudin Date: Tue, 11 Mar 2014 18:00:20 +0100 Subject: [PATCH 03/20] Update yunohost_tools.py --- yunohost_tools.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/yunohost_tools.py b/yunohost_tools.py index 82ce4d19..c3253af0 100644 --- a/yunohost_tools.py +++ b/yunohost_tools.py @@ -267,7 +267,6 @@ def tools_update(): Update distribution """ - process = Popen("/usr/local/bin/checkupdate", stdout=PIPE) stdout, stderr = process.communicate() if process.returncode == 1: @@ -282,7 +281,7 @@ def tools_changelog(): Show Changelog """ - + win_msg(_("TODO Show Changelog")) def tools_upgrade(): @@ -290,7 +289,6 @@ def tools_upgrade(): Upgrade distribution """ - if os.path.isfile('/tmp/update_status'): os.system('at now -f /etc/yunohost/upgrade') else: From f64a9bc3497cc2536805816038a930fc3885e73e Mon Sep 17 00:00:00 2001 From: abeudin Date: Tue, 11 Mar 2014 18:12:58 +0100 Subject: [PATCH 04/20] Create checkupdate --- checkupdate | 62 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 checkupdate diff --git a/checkupdate b/checkupdate new file mode 100644 index 00000000..85a9d9d2 --- /dev/null +++ b/checkupdate @@ -0,0 +1,62 @@ +#!/bin/bash + +if [ -f /tmp/changelog ]; +then + rm /tmp/changelog +fi + +apt-get update -y > /dev/null 2>&1 +if [[ $? != 0 ]]; +then + exit 2 +else + echo OK > /tmp/update_status +fi + +# Set $DIRCACHE +eval `/usr/bin/apt-config shell DIRCACHE Dir::Cache` + + +# get the list of packages which are pending an upgrade +PKGNAMES=`/usr/bin/apt-get -q -y --ignore-hold --allow-unauthenticated -s dist-upgrade | \ + /bin/grep ^Inst | /usr/bin/cut -d\ -f2 | /usr/bin/sort` + +if [[ $PKGNAMES = "" ]]; +then + exit 1 +fi + +if [ -n "$PKGNAMES" ] ; then + + # do the upgrade downloads + /usr/bin/apt-get --ignore-hold -qq -d --allow-unauthenticated --force-yes dist-upgrade > /dev/null +fi + + +PKGPATH="/${DIRCACHE}archives/" +for PKG in $PKGNAMES ; do + VER=`LC_ALL=C /usr/bin/apt-cache policy $PKG |\ + /bin/grep Candidate: | /usr/bin/cut -f 4 -d \ ` + OLDVER=`LC_ALL=C /usr/bin/apt-cache policy $PKG |\ + /bin/grep Installed: | /usr/bin/cut -f 4 -d \ ` + VERFILE=`echo "$VER" | /bin/sed -e "s/:/%3a/g"` + if ls ${PKGPATH}${PKG}_${VERFILE}_*.deb >& /dev/null ; then + DEBS="$DEBS ${PKGPATH}${PKG}_${VERFILE}_*.deb" + fi + echo -e "$PKG $OLDVER -> $VER" +done + +MISSING_DEBS=`apt-get -y --ignore-hold --allow-unauthenticated --print-uris dist-upgrade \ + | grep "file:" \ + | sed "s/'file:\(.*\)' .*/\1/g"` + +DEBS=`echo $MISSING_DEBS $DEBS | /usr/bin/sort` + +if [[ $DEBS = "" ]]; +then + exit 3 +else + if [ -x /usr/bin/apt-listchanges ] ; then + /usr/bin/apt-listchanges --which=both -f text $DEBS > /tmp/changelog 2>/dev/null + fi +fi From 76b2809f08dd9c5647d83deccc66da299cabaa15 Mon Sep 17 00:00:00 2001 From: abeudin Date: Tue, 11 Mar 2014 18:15:39 +0100 Subject: [PATCH 05/20] Update yunohost_tools.py --- yunohost_tools.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/yunohost_tools.py b/yunohost_tools.py index c3253af0..df427938 100644 --- a/yunohost_tools.py +++ b/yunohost_tools.py @@ -276,12 +276,15 @@ def tools_update(): else: return { "Update" : stdout.splitlines() } + def tools_changelog(): """ Show Changelog """ - win_msg(_("TODO Show Changelog")) + with open('/tmp/changelog', 'r') as f: + read_data = f.read() + return { "Changelog" : read_data.splitlines() } def tools_upgrade(): From 7f8b1f601b188b11d9917a90f43da9e52ef92b78 Mon Sep 17 00:00:00 2001 From: abeudin Date: Tue, 11 Mar 2014 18:15:55 +0100 Subject: [PATCH 06/20] Update yunohost_tools.py --- yunohost_tools.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/yunohost_tools.py b/yunohost_tools.py index df427938..468c074c 100644 --- a/yunohost_tools.py +++ b/yunohost_tools.py @@ -267,7 +267,7 @@ def tools_update(): Update distribution """ - process = Popen("/usr/local/bin/checkupdate", stdout=PIPE) + process = Popen("./checkupdate", stdout=PIPE) stdout, stderr = process.communicate() if process.returncode == 1: win_msg( _("Not upgrade found")) From 0d814d2ea10f74c0b05ad545ce04a670b301bca4 Mon Sep 17 00:00:00 2001 From: abeudin Date: Tue, 11 Mar 2014 18:18:21 +0100 Subject: [PATCH 07/20] Update yunohost_tools.py --- yunohost_tools.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/yunohost_tools.py b/yunohost_tools.py index 468c074c..14bc4f5f 100644 --- a/yunohost_tools.py +++ b/yunohost_tools.py @@ -293,6 +293,6 @@ def tools_upgrade(): """ if os.path.isfile('/tmp/update_status'): - os.system('at now -f /etc/yunohost/upgrade') + os.system('at now -f /usr/share/pyshared/yunohost-cli/upgrade') else: raise YunoHostError(17, _("Launch update before upgrade")) From 6dbf50e77ef2e995fc77e249e9ba407cf3fff9a9 Mon Sep 17 00:00:00 2001 From: abeudin Date: Tue, 11 Mar 2014 18:18:48 +0100 Subject: [PATCH 08/20] Create upgrade --- upgrade | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 upgrade diff --git a/upgrade b/upgrade new file mode 100644 index 00000000..1a035218 --- /dev/null +++ b/upgrade @@ -0,0 +1,3 @@ +rm /tmp/update_status +sudo apt-get upgrade -y > /tmp/update_log 2>&1 +if [[ $? = 0 ]]; then echo "OK" > /tmp/upgrade_status; else echo "NOK" > /tmp/upgrade_status; fi From 034de511d3553b5cce141d2911a44b03ccab7f5a Mon Sep 17 00:00:00 2001 From: Adrien Beudin Date: Tue, 11 Mar 2014 18:23:58 +0100 Subject: [PATCH 09/20] add safe update --- checkupdate => bash/checkupdate | 0 upgrade => config/upgrade | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename checkupdate => bash/checkupdate (100%) rename upgrade => config/upgrade (100%) diff --git a/checkupdate b/bash/checkupdate similarity index 100% rename from checkupdate rename to bash/checkupdate diff --git a/upgrade b/config/upgrade similarity index 100% rename from upgrade rename to config/upgrade From e42ede89d46a82de772ab70984f62cb7a717069f Mon Sep 17 00:00:00 2001 From: abeudin Date: Tue, 11 Mar 2014 18:27:06 +0100 Subject: [PATCH 10/20] Update yunohost_tools.py --- yunohost_tools.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/yunohost_tools.py b/yunohost_tools.py index 14bc4f5f..134b9b8b 100644 --- a/yunohost_tools.py +++ b/yunohost_tools.py @@ -267,7 +267,7 @@ def tools_update(): Update distribution """ - process = Popen("./checkupdate", stdout=PIPE) + process = Popen("./bash/checkupdate", stdout=PIPE) stdout, stderr = process.communicate() if process.returncode == 1: win_msg( _("Not upgrade found")) From 706880f03c3336d9d6cf9852fe43b3ca27c1e092 Mon Sep 17 00:00:00 2001 From: abeudin Date: Wed, 12 Mar 2014 10:13:06 +0100 Subject: [PATCH 11/20] Update yunohost_tools.py --- yunohost_tools.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/yunohost_tools.py b/yunohost_tools.py index 134b9b8b..ebe67101 100644 --- a/yunohost_tools.py +++ b/yunohost_tools.py @@ -267,7 +267,7 @@ def tools_update(): Update distribution """ - process = Popen("./bash/checkupdate", stdout=PIPE) + process = Popen("/usr/bin/checkupdate", stdout=PIPE) stdout, stderr = process.communicate() if process.returncode == 1: win_msg( _("Not upgrade found")) @@ -293,6 +293,6 @@ def tools_upgrade(): """ if os.path.isfile('/tmp/update_status'): - os.system('at now -f /usr/share/pyshared/yunohost-cli/upgrade') + os.system('at now -f /etc/yunohost/upgrade') else: raise YunoHostError(17, _("Launch update before upgrade")) From c84406583ef1491dcf183c078e76dfe8885db540 Mon Sep 17 00:00:00 2001 From: abeudin Date: Thu, 13 Mar 2014 11:15:58 +0100 Subject: [PATCH 12/20] Update yunohost_tools.py --- yunohost_tools.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/yunohost_tools.py b/yunohost_tools.py index ebe67101..7c8c9a19 100644 --- a/yunohost_tools.py +++ b/yunohost_tools.py @@ -276,23 +276,28 @@ def tools_update(): else: return { "Update" : stdout.splitlines() } - def tools_changelog(): """ Show Changelog """ - with open('/tmp/changelog', 'r') as f: + with open('/tmp/yunohost/changelog', 'r') as f: read_data = f.read() return { "Changelog" : read_data.splitlines() } - def tools_upgrade(): """ Upgrade distribution """ - if os.path.isfile('/tmp/update_status'): + if os.path.isfile('/tmp/yunohost/update_status'): os.system('at now -f /etc/yunohost/upgrade') + with open('/tmp/yunohost/upgrade_status', 'r') as f: + read_data = f.read() + os.system('rm /tmp/yunohost/upgrade_status') + if read_data.strip() == "OK": + win_msg( _("YunoHost has been successfully upgraded")) + else: + raise YunoHostError(17, _("Error during upgrade")) else: raise YunoHostError(17, _("Launch update before upgrade")) From 4d7398622fe1893af4ab8a4d45a672205007a181 Mon Sep 17 00:00:00 2001 From: abeudin Date: Thu, 13 Mar 2014 11:17:01 +0100 Subject: [PATCH 13/20] Update checkupdate --- bash/checkupdate | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/bash/checkupdate b/bash/checkupdate index 85a9d9d2..30534bdf 100644 --- a/bash/checkupdate +++ b/bash/checkupdate @@ -1,8 +1,13 @@ #!/bin/bash -if [ -f /tmp/changelog ]; +if [ ! -d /tmp/yunohost ]; then - rm /tmp/changelog + mkdir /tmp/yunohost +fi + +if [ -f /tmp/yunohost/changelog ]; +then + rm /tmp/yunohost/changelog fi apt-get update -y > /dev/null 2>&1 @@ -10,7 +15,7 @@ if [[ $? != 0 ]]; then exit 2 else - echo OK > /tmp/update_status + echo OK > /tmp/yunohost/update_status fi # Set $DIRCACHE @@ -57,6 +62,6 @@ then exit 3 else if [ -x /usr/bin/apt-listchanges ] ; then - /usr/bin/apt-listchanges --which=both -f text $DEBS > /tmp/changelog 2>/dev/null + /usr/bin/apt-listchanges --which=both -f text $DEBS > /tmp/yunohost/changelog 2>/dev/null fi fi From 524489edaa106bcb92e315e857ce7c073d344b51 Mon Sep 17 00:00:00 2001 From: abeudin Date: Thu, 13 Mar 2014 12:04:37 +0100 Subject: [PATCH 14/20] Update yunohost_tools.py --- yunohost_tools.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/yunohost_tools.py b/yunohost_tools.py index 7c8c9a19..e9a695ea 100644 --- a/yunohost_tools.py +++ b/yunohost_tools.py @@ -281,9 +281,12 @@ def tools_changelog(): Show Changelog """ - with open('/tmp/yunohost/changelog', 'r') as f: - read_data = f.read() - return { "Changelog" : read_data.splitlines() } + if os.path.isfile('/tmp/yunohost/update_status'): + with open('/tmp/yunohost/changelog', 'r') as f: + read_data = f.read() + return { "Changelog" : read_data.splitlines() } + else: + raise YunoHostError(17, _("Launch update before upgrade")) def tools_upgrade(): """ From 6a9a8f082d1ec684c579698f23ffe92e272c589c Mon Sep 17 00:00:00 2001 From: abeudin Date: Thu, 13 Mar 2014 12:22:54 +0100 Subject: [PATCH 15/20] Update yunohost_tools.py --- yunohost_tools.py | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/yunohost_tools.py b/yunohost_tools.py index e9a695ea..36116de5 100644 --- a/yunohost_tools.py +++ b/yunohost_tools.py @@ -293,14 +293,17 @@ def tools_upgrade(): Upgrade distribution """ - if os.path.isfile('/tmp/yunohost/update_status'): - os.system('at now -f /etc/yunohost/upgrade') - with open('/tmp/yunohost/upgrade_status', 'r') as f: - read_data = f.read() - os.system('rm /tmp/yunohost/upgrade_status') - if read_data.strip() == "OK": - win_msg( _("YunoHost has been successfully upgraded")) - else: - raise YunoHostError(17, _("Error during upgrade")) + if os.path.isfile('/tmp/yunohost/upgrade.run'): + win_msg( _("Upgrade in progress")) else: - raise YunoHostError(17, _("Launch update before upgrade")) + if os.path.isfile('/tmp/yunohost/update_status'): + os.system('at now -f /etc/yunohost/upgrade') + with open('/tmp/yunohost/upgrade_status', 'r') as f: + read_data = f.read() + os.system('rm /tmp/yunohost/upgrade_status') + if read_data.strip() == "OK": + win_msg( _("YunoHost has been successfully upgraded")) + else: + raise YunoHostError(17, _("Error during upgrade")) + else: + raise YunoHostError(17, _("Launch update before upgrade")) From a2e02c56cff67d8f4100986ca85b23c72c9b2a1a Mon Sep 17 00:00:00 2001 From: abeudin Date: Thu, 13 Mar 2014 12:23:21 +0100 Subject: [PATCH 16/20] Update upgrade --- config/upgrade | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/config/upgrade b/config/upgrade index 1a035218..0d0323b0 100644 --- a/config/upgrade +++ b/config/upgrade @@ -1,3 +1,5 @@ -rm /tmp/update_status -sudo apt-get upgrade -y > /tmp/update_log 2>&1 -if [[ $? = 0 ]]; then echo "OK" > /tmp/upgrade_status; else echo "NOK" > /tmp/upgrade_status; fi +/bin/bash +rm /tmp/yunohost/update_status +sudo apt-get upgrade -y -s > /tmp/yunohost/update_log 2>&1 +if [ $(echo $?) = 0 ]; then echo "OK" > /tmp/yunohost/upgrade_status; else echo "NOK" > /tmp/yunohost/upgrade_status; fi +rm /tmp/yunohost/upgrade.run From 8fbfb57ffbeafd64c24911a3f74730ec4c31880f Mon Sep 17 00:00:00 2001 From: abeudin Date: Thu, 13 Mar 2014 12:37:51 +0100 Subject: [PATCH 17/20] Update yunohost_tools.py --- yunohost_tools.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/yunohost_tools.py b/yunohost_tools.py index 36116de5..0bf35932 100644 --- a/yunohost_tools.py +++ b/yunohost_tools.py @@ -275,6 +275,7 @@ def tools_update(): raise YunoHostError(17, _("Error during update")) else: return { "Update" : stdout.splitlines() } + def tools_changelog(): """ @@ -287,6 +288,7 @@ def tools_changelog(): return { "Changelog" : read_data.splitlines() } else: raise YunoHostError(17, _("Launch update before upgrade")) + def tools_upgrade(): """ @@ -296,8 +298,7 @@ def tools_upgrade(): if os.path.isfile('/tmp/yunohost/upgrade.run'): win_msg( _("Upgrade in progress")) else: - if os.path.isfile('/tmp/yunohost/update_status'): - os.system('at now -f /etc/yunohost/upgrade') + if os.path.isfile('/tmp/yunohost/upgrade_status'): with open('/tmp/yunohost/upgrade_status', 'r') as f: read_data = f.read() os.system('rm /tmp/yunohost/upgrade_status') @@ -305,5 +306,8 @@ def tools_upgrade(): win_msg( _("YunoHost has been successfully upgraded")) else: raise YunoHostError(17, _("Error during upgrade")) + elif os.path.isfile('/tmp/yunohost/update_status'): + os.system('at now -f /etc/yunohost/upgrade') + win_msg( _("Upgrade in progress")) else: raise YunoHostError(17, _("Launch update before upgrade")) From 34e03c437cb038668de9711fb949b7f8c14b1427 Mon Sep 17 00:00:00 2001 From: abeudin Date: Thu, 13 Mar 2014 12:45:28 +0100 Subject: [PATCH 18/20] Update action_map.yml --- action_map.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/action_map.yml b/action_map.yml index adfba131..0325ee30 100644 --- a/action_map.yml +++ b/action_map.yml @@ -869,6 +869,11 @@ tools: upgrade: action_help: YunoHost upgrade api: POST /upgrade + + ### tools_upgradelog() + upgradelog: + action_help: Show dpkg log + api: POST /upgradelog ############################# From f40f386add31b5f9c621c3ef72633abc72fee711 Mon Sep 17 00:00:00 2001 From: abeudin Date: Thu, 13 Mar 2014 12:46:08 +0100 Subject: [PATCH 19/20] Update yunohost_tools.py --- yunohost_tools.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/yunohost_tools.py b/yunohost_tools.py index 0bf35932..b831f9d0 100644 --- a/yunohost_tools.py +++ b/yunohost_tools.py @@ -311,3 +311,16 @@ def tools_upgrade(): win_msg( _("Upgrade in progress")) else: raise YunoHostError(17, _("Launch update before upgrade")) + + +def tools_upgradelog(): + """ + Show upgrade log + + """ + if os.path.isfile('/tmp/yunohost/upgrade.run'): + win_msg( _("Upgrade in progress")) + else: + with open('/tmp/yunohost/update_log', 'r') as f: + read_data = f.read() + return { "DPKG LOG" : read_data.splitlines() } From 9452c95dc692bebafa24031110a83d05f9ebb260 Mon Sep 17 00:00:00 2001 From: abeudin Date: Thu, 13 Mar 2014 16:18:55 +0100 Subject: [PATCH 20/20] Update yunohost_tools.py --- yunohost_tools.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/yunohost_tools.py b/yunohost_tools.py index b831f9d0..2f2fce6c 100644 --- a/yunohost_tools.py +++ b/yunohost_tools.py @@ -307,7 +307,7 @@ def tools_upgrade(): else: raise YunoHostError(17, _("Error during upgrade")) elif os.path.isfile('/tmp/yunohost/update_status'): - os.system('at now -f /etc/yunohost/upgrade') + os.system('at now -f /usr/share/yunohost/upgrade') win_msg( _("Upgrade in progress")) else: raise YunoHostError(17, _("Launch update before upgrade"))