Difference between revisions of "Dextrose/Updater"
< Dextrose
Jump to navigation
Jump to search
(Created page with "== Configuration == Edit {{Code|/etc/default/dextrose-update}} configuration file: DEXTROSE_YUM_REPO=''name-of-yum-repository-with-dextrose-packages'' == Install == Create {...") |
|||
Line 12: | Line 12: | ||
name="dextrose-update" | name="dextrose-update" | ||
+ | . /etc/default/${name} | ||
+ | |||
+ | logfile="/var/log/${name}" | ||
− | + | reboot_pkgs="kernel kernel-firmware" | |
+ | relogin_pkgs="sugar sugar-artwork sugar-base sugar-datastore sugar-presence-service sugar-toolkit" | ||
yum="/usr/bin/yum --disablerepo=* --enablerepo=${DEXTROSE_YUM_REPO} --skip-broken --quiet" | yum="/usr/bin/yum --disablerepo=* --enablerepo=${DEXTROSE_YUM_REPO} --skip-broken --quiet" | ||
− | |||
− | updates | + | updates() { |
− | [ "${ | + | ${yum} -e0 check-update | awk '/./{print $1 "-" $2}' |
+ | } | ||
+ | |||
+ | to_update=$(updates) | ||
+ | [ "${to_update}" ] || exit 0 | ||
+ | |||
+ | parse() { | ||
+ | for i in $@; do | ||
+ | echo ${to_update} | grep "\(^\| \)$i\." >/dev/null && echo $i | ||
+ | done | ||
+ | } | ||
+ | |||
+ | need_reboot=$(parse ${reboot_pkgs}) | ||
+ | need_relogin=$(parse ${relogin_pkgs}) | ||
− | echo "$(date) | + | echo "$(date)" >> $logfile |
− | echo ${ | + | echo -e "\tRepository:" ${DEXTROSE_YUM_REPO} >> $logfile |
+ | echo -e "\tPackages to update:" ${to_update} >> $logfile | ||
${yum} -y update >> $logfile 2>&1 | ${yum} -y update >> $logfile 2>&1 | ||
+ | to_update=$(updates) | ||
+ | |||
+ | if [ "${need_reboot}" ]; then | ||
+ | if [ "${need_reboot}" != "$(parse ${reboot_pkgs})" ]; then | ||
+ | echo -e "\tNeed to reboot..." >> $logfile | ||
+ | dbus-send --system /org/sugarlabs/system org.sugarlabs.system.Reboot | ||
+ | fi | ||
+ | fi | ||
+ | |||
+ | if [ "${need_relogin}" ]; then | ||
+ | if [ "${need_relogin}" != "$(parse ${relogin_pkgs})" ]; then | ||
+ | echo -e "\tNeed to relogin..." >> $logfile | ||
+ | dbus-send --system /org/sugarlabs/system org.sugarlabs.system.Relogin | ||
+ | fi | ||
+ | fi | ||
Create cron task: | Create cron task: | ||
ln -s /usr/sbin/dextrose-update /etc/cron.daily/ | ln -s /usr/sbin/dextrose-update /etc/cron.daily/ | ||
+ | |||
+ | Python client code: | ||
+ | |||
+ | _DBUS_SYSTEM_IFACE = 'org.sugarlabs.system' | ||
+ | _DBUS_SYSTEM_PATH = '/org/sugarlabs/system' | ||
+ | _SYSTEM_REBOOT_ID = -1 | ||
+ | _SYSTEM_RELOGIN_ID = -2 | ||
+ | _SYSTEM_TIMEOUT = 5 | ||
+ | |||
+ | systembus = dbus.SystemBus() | ||
+ | systembus.add_signal_receiver(self.__reboot_cb, 'Reboot', _DBUS_SYSTEM_IFACE) | ||
+ | systembus.add_signal_receiver(self.__relogin_cb, 'Relogin', _DBUS_SYSTEM_IFACE) | ||
+ | |||
+ | def _system_alert(self, replaces_id, app_icon, message): | ||
+ | self.notification_received.send(self,app_name='system', | ||
+ | replaces_id=replaces_id, app_icon=app_icon, | ||
+ | summary=_('System alert'), body=message, | ||
+ | actions=[], hints={}, expire_timeout=_SYSTEM_TIMEOUT) | ||
+ | |||
+ | def __reboot_cb(self): | ||
+ | self._system_alert(_SYSTEM_REBOOT_ID, 'system-restart', | ||
+ | _('Please, reboot your computer to take into account ' \ | ||
+ | 'new updates')) | ||
+ | |||
+ | def __relogin_cb(self): | ||
+ | self._system_alert(_SYSTEM_RELOGIN_ID, 'system-logout', | ||
+ | _('Please, restart Sugar to take into account ' \ | ||
+ | 'new updates')) | ||
== Logs == | == Logs == | ||
Logging records are collected in {{Code|/var/log/dextrose-update}}. | Logging records are collected in {{Code|/var/log/dextrose-update}}. |
Revision as of 22:49, 27 November 2010
Configuration
Edit /etc/default/dextrose-update
configuration file:
DEXTROSE_YUM_REPO=name-of-yum-repository-with-dextrose-packages
Install
Create /usr/sbin/dextrose-update
, main execution file:
#!/bin/sh name="dextrose-update" . /etc/default/${name} logfile="/var/log/${name}" reboot_pkgs="kernel kernel-firmware" relogin_pkgs="sugar sugar-artwork sugar-base sugar-datastore sugar-presence-service sugar-toolkit" yum="/usr/bin/yum --disablerepo=* --enablerepo=${DEXTROSE_YUM_REPO} --skip-broken --quiet" updates() { ${yum} -e0 check-update | awk '/./{print $1 "-" $2}' } to_update=$(updates) [ "${to_update}" ] || exit 0 parse() { for i in $@; do echo ${to_update} | grep "\(^\| \)$i\." >/dev/null && echo $i done } need_reboot=$(parse ${reboot_pkgs}) need_relogin=$(parse ${relogin_pkgs}) echo "$(date)" >> $logfile echo -e "\tRepository:" ${DEXTROSE_YUM_REPO} >> $logfile echo -e "\tPackages to update:" ${to_update} >> $logfile ${yum} -y update >> $logfile 2>&1 to_update=$(updates) if [ "${need_reboot}" ]; then if [ "${need_reboot}" != "$(parse ${reboot_pkgs})" ]; then echo -e "\tNeed to reboot..." >> $logfile dbus-send --system /org/sugarlabs/system org.sugarlabs.system.Reboot fi fi if [ "${need_relogin}" ]; then if [ "${need_relogin}" != "$(parse ${relogin_pkgs})" ]; then echo -e "\tNeed to relogin..." >> $logfile dbus-send --system /org/sugarlabs/system org.sugarlabs.system.Relogin fi fi
Create cron task:
ln -s /usr/sbin/dextrose-update /etc/cron.daily/
Python client code:
_DBUS_SYSTEM_IFACE = 'org.sugarlabs.system' _DBUS_SYSTEM_PATH = '/org/sugarlabs/system' _SYSTEM_REBOOT_ID = -1 _SYSTEM_RELOGIN_ID = -2 _SYSTEM_TIMEOUT = 5 systembus = dbus.SystemBus() systembus.add_signal_receiver(self.__reboot_cb, 'Reboot', _DBUS_SYSTEM_IFACE) systembus.add_signal_receiver(self.__relogin_cb, 'Relogin', _DBUS_SYSTEM_IFACE) def _system_alert(self, replaces_id, app_icon, message): self.notification_received.send(self,app_name='system', replaces_id=replaces_id, app_icon=app_icon, summary=_('System alert'), body=message, actions=[], hints={}, expire_timeout=_SYSTEM_TIMEOUT) def __reboot_cb(self): self._system_alert(_SYSTEM_REBOOT_ID, 'system-restart', _('Please, reboot your computer to take into account ' \ 'new updates')) def __relogin_cb(self): self._system_alert(_SYSTEM_RELOGIN_ID, 'system-logout', _('Please, restart Sugar to take into account ' \ 'new updates'))
Logs
Logging records are collected in /var/log/dextrose-update
.