04.01.2010

update-notifier для Gentoo на коленке

Простые скрипты обновляют portage и выводят в иксы сообщение с количеством обновлений.

Топорно, но вроде бы работает!

скрипт уведомления (зависит от notification-daemon или notify-osd или где там в вашем дистрибутиве команда notify-send)

#!/bin/sh
# notify.sh 
# (c) init_6 

user=`ps -C plasma-desktop -o user=` #find UID user who start plasma-desktop 
pids=`pgrep -u $user plasma-desktop` #find PID
#Ищем лузера с рабочими кедами. Если у вас не кеды -- подставляете вашу DE-специфичную вещь.
title=$1
text=$2
timeout=$3
urgency=$4
icon=$5
category=$6

if [ -z "$urgency" ]; then 
#low, normal, critical 
urgency=normal 
fi 
if [ -z "$timeout" ]; then 
timeout=60000 
fi 
if [ -z "$icon" ]; then 
icon=/usr/share/icons/gnome/scalable/status/dialog-information.svg 
#dialog-error.svg dialog-warning.svg 
fi 
if [ -z "$category" ]; then 
#"device" A generic device-related notification that doesn't fit into any other category. 
#"device.added" A device, such as a USB device, was added to the system. 
#"device.error" A device had some kind of error. 
#"device.removed" A device, such as a USB device, was removed from the system. 
#"email" A generic e-mail-related notification that doesn't fit into any other category. 
#"email.arrived" A new e-mail notification. 
#"email.bounced" A notification stating that an e-mail has bounced. 
#"im" A generic instant message-related notification that doesn't fit into any other category. 
#"im.error" An instant message error notification. 
#"im.received" A received instant message notification. 
#"network" A generic network notification that doesn't fit into any other category. 
#"network.connected" A network connection notification, such as successful sign-on to a network service. This should not be confused with device.added for new network devices. 
#"network.disconnected" A network disconnected notification. This should not be confused with device.removed for disconnected network devices. 
#"network.error" A network-related or connection-related error. 
#"presence" A generic presence change notification that doesn't fit into any other category, such as going away or idle. 
#"presence.offline" An offline presence change notification. 
#"presence.online" An online presence change notification. 
#"transfer" A generic file transfer or download notification that doesn't fit into any other category. 
#"transfer.complete" A file transfer or download complete notification. 
#"transfer.error" A file transfer or download error. 
category=transfer 
fi 
if [ -z "$title" ]; then 
echo You need to give me a title >&2 
exit 1 
fi 
if [ -z "$text" ]; then 
text=$title 
fi 

for pid in $pids; do 
su $user -c "notify-send -u $urgency -t $timeout -i $icon -c $category '$title' '$text' "
done


Скрипт обновлялки:
#!/bin/sh
#update for gentoo
#emerge --sync
export XAUTHORITY="/home/fat-troll/.Xauthority"
export DISPLAY=":0"
#Это, чтобы в иксы пробиться
eix-sync
eix-remote update
#Овчинка, которую мы и выделываем
/usr/local/bin/notify.sh "Обновление" "Portage обновлены до "$(date)". Доступно "$(emerge -pavuDN world | grep -c - )" обновлений. Не забудьте выполнить emerge -avuDN world!" 60000 normal /usr/share/icons/gnome/scalable/status/dialog-information.svg transfer.complete || /usr/local/bin/notify.sh "Обновление" "Обновление portage завершилось неудачей" 60000 critical /usr/share/icons/gnome/scalable/status/dialog-error.svg transfer.error; 
#Мессага!

Прописывается в cron так, как вам удобно.

Комментариев нет:

Отправить комментарий