diff --git a/action_map.yml b/action_map.yml index 42568c7a..0325ee30 100644 --- a/action_map.yml +++ b/action_map.yml @@ -855,6 +855,26 @@ 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 + + ### tools_upgradelog() + upgradelog: + action_help: Show dpkg log + api: POST /upgradelog + ############################# # Hook # diff --git a/bash/checkupdate b/bash/checkupdate new file mode 100644 index 00000000..30534bdf --- /dev/null +++ b/bash/checkupdate @@ -0,0 +1,67 @@ +#!/bin/bash + +if [ ! -d /tmp/yunohost ]; +then + mkdir /tmp/yunohost +fi + +if [ -f /tmp/yunohost/changelog ]; +then + rm /tmp/yunohost/changelog +fi + +apt-get update -y > /dev/null 2>&1 +if [[ $? != 0 ]]; +then + exit 2 +else + echo OK > /tmp/yunohost/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/yunohost/changelog 2>/dev/null + fi +fi diff --git a/config/upgrade b/config/upgrade new file mode 100644 index 00000000..0d0323b0 --- /dev/null +++ b/config/upgrade @@ -0,0 +1,5 @@ +/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 diff --git a/yunohost_tools.py b/yunohost_tools.py index 5fc68786..2f2fce6c 100644 --- a/yunohost_tools.py +++ b/yunohost_tools.py @@ -262,3 +262,65 @@ def tools_postinstall(domain, password, dyndns=False): win_msg(_("YunoHost has been successfully configured")) +def tools_update(): + """ + Update distribution + + """ + process = Popen("/usr/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 + + """ + 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(): + """ + Upgrade distribution + + """ + if os.path.isfile('/tmp/yunohost/upgrade.run'): + win_msg( _("Upgrade in progress")) + else: + 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') + if read_data.strip() == "OK": + 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 /usr/share/yunohost/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() }