| 1 | #!/bin/bash |
| 2 | #BANNER####################################### |
| 3 | echo -n ' |
| 4 | ____ ____ __ _ _ _ __ __ _ |
| 5 | (__ )( __)( ( \( \/ ) / _\ ( ( \ |
| 6 | / _/ ) _) / // \/ \/ \/ / |
| 7 | (____)(____)\_)__)\_)(_/\_/\_/\_)__) v1.8 |
| 8 | |
| 9 | Zenity based frontend for pacman |
| 10 | <~Harvie (http://blog.harvie.cz) |
| 11 | 2oo9 |
| 12 | |
| 13 | '; |
| 14 | |
| 15 | #HELP/FEATURES################################ |
| 16 | if [ "$1" == '--help' ]; then |
| 17 | cat << END |
| 18 | HELP/FEATURES: |
| 19 | - note this script is not much secure since it uses gksu to execute user defined scripts |
| 20 | - this is not good idea for server, but it should be OK for personal workstation |
| 21 | - root rights can be obtained by gksu anyway |
| 22 | - to defeat this risk please do not use 'remember password' in gksu |
| 23 | - zenman --help prints this help |
| 24 | - when zenman started, kills last zenman runned by this user |
| 25 | - you can kill zenman by zenman --stop (click on tray icon or wait after this) |
| 26 | - last pid is stored in ~/.config/zenman/zenman.pid |
| 27 | - shows splashscreen (can be disabled...) |
| 28 | - shows tray icon for each state (on mouse over shows state) |
| 29 | - system is up to date |
| 30 | - refreshing pacman database |
| 31 | - updates available |
| 32 | - shows notification when updates available and listing them |
| 33 | - optionally can notify also using speech output |
| 34 | - clicking on icon will begin upgrade in new xterm |
| 35 | - this is disabled only when refreshing |
| 36 | - if pacman db is locked it will be automaticaly unlocked |
| 37 | - only if there is any pacman related process running |
| 38 | - if there is some pacman related operation, error message appears |
| 39 | - auto refreshing of pacman db is disabled (somebody will want to use cron) |
| 40 | - all settings are hardcoded to zenman (/usr/bin/zenman) |
| 41 | - all settings can be overrided |
| 42 | - system wide: /etc/zenman.conf |
| 43 | - single user only: ~/.config/zenman/zenman.conf |
| 44 | - you can also write your own translation to this files |
| 45 | |
| 46 | TODO: |
| 47 | ( Don't shy and get involved! ;o) |
| 48 | - Bugtracking/Bugfixing |
| 49 | - Port to another package managers |
| 50 | - apt-zen (apt-get) |
| 51 | - zenmerge (emerge) |
| 52 | - ipkg-zen (ipkg) |
| 53 | - etc... |
| 54 | - Localization to your native language |
| 55 | END |
| 56 | exit; |
| 57 | fi; |
| 58 | |
| 59 | #SETTINGS##################################### |
| 60 | #main############################# |
| 61 | zenman_caption='ZenMan'; |
| 62 | zenman_interval=$[10*60]; |
| 63 | zenman_splash=true; |
| 64 | zenman_autorefresh=false; |
| 65 | zenman_speech=true; |
| 66 | zenman_configdir=~/.config/zenman; |
| 67 | zenman_pid="$zenman_configdir/zenman.pid"; |
| 68 | zenman_true_ico='/usr/share/icons/gnome/48x48/status/software-update-urgent.png'; #software-update-available.svg |
| 69 | zenman_false_ico='/usr/share/icons/gnome/48x48/emotes/face-cool.png'; |
| 70 | zenman_refresh_ico='/usr/share/icons/gnome/48x48/actions/view-refresh.png'; |
| 71 | |
| 72 | #files/commands################### |
| 73 | gksu='gksu'; #gksu/gksudo/... |
| 74 | pacman='/usr/bin/pacman'; #want to use pacman-color, yaourt or powerpill instead? |
| 75 | xterm='/usr/bin/xterm'; #xterm/... |
| 76 | espeak='/usr/bin/espeak' #espeak (for spoken notification) |
| 77 | pacman_refresh='-Syuw'; # -Sy ? |
| 78 | pacman_upgrade='-Syu'; # -Syuf ? |
| 79 | pacman_check='-Qu'; |
| 80 | pacman_lock='/var/lib/pacman/db.lck'; #file to delete, when pacman locked (only if not running) |
| 81 | |
| 82 | #Translate here################### |
| 83 | zenman_true='New package(s) found! ;-)\n\nPacman output follows:\n'; |
| 84 | zenman_false='No packages to update. ;-('; |
| 85 | zenman_refreshing='Refreshing pacman database. ;-) Please wait...'; |
| 86 | zenman_usage="[i] $0 --stop to kill zenman\n[i] $0 --help to show help\n" |
| 87 | zenman_upgrade="[*] ZenMan will now execute full system upgrade! ;-)\n\n'$pacman' '$pacman_upgrade'\n\n"; |
| 88 | zenman_close='[*] Press [ENTER] to close window...'; |
| 89 | zenman_config='[*] Loading configuration from: '; |
| 90 | zenman_done='[DONE]'; |
| 91 | zenman_locked="ZenMan can't execute system upgrade! ;-( |
| 92 | Please stop all pacman related applications and try again."; |
| 93 | zenman_start="ZenMan started! ;-) |
| 94 | by: Harvie 2oo9 |
| 95 | For more informations please visit: |
| 96 | http://blog.harvie.cz/"; |
| 97 | |
| 98 | #voice |
| 99 | espeak_voice='en'; #see: espeak --voices |
| 100 | espeak_volume='200'; #0-200 |
| 101 | speech_true='New packages found!'; |
| 102 | |
| 103 | #INIT######################################### |
| 104 | if [ "$2" != '' ]; then zenman_configdir="$2"; fi; #when called with --upgrade |
| 105 | mkdir -p "$zenman_configdir" |
| 106 | touch "$zenman_configdir/zenman.conf" |
| 107 | #read configuration files (can contain localization also)... |
| 108 | for i in\ |
| 109 | '/etc/zenman.conf'\ |
| 110 | "$zenman_configdir/zenman.conf"\ |
| 111 | ; do |
| 112 | echo "$zenman_config" "$i"; |
| 113 | source "$i" >/dev/null 2>&1; |
| 114 | done; |
| 115 | if [ "$2" != '' ]; then zenman_configdir="$2"; fi; #when called with --upgrade |
| 116 | |
| 117 | #fallback icons |
| 118 | if [ ! -e "$zenman_true_ico" ]; then zenman_true_ico='warning'; fi; |
| 119 | if [ ! -e "$zenman_false_ico" ]; then zenman_false_ico='info'; fi; |
| 120 | if [ ! -e "$zenman_refresh_ico" ]; then zenman_false_ico='question'; fi; |
| 121 | |
| 122 | |
| 123 | #CODE######################################### |
| 124 | #pid |
| 125 | if [ -e "$zenman_pid" ]; then |
| 126 | kill $(cat "$zenman_pid") >/dev/null 2>&1; |
| 127 | kill -KILL $(cat "$zenman_pid") >/dev/null 2>&1; |
| 128 | fi; |
| 129 | if [ "$1" == '--stop' ]; then |
| 130 | echo '[!] exit'; |
| 131 | exit; |
| 132 | fi; |
| 133 | echo "$$" > "$zenman_pid"; |
| 134 | |
| 135 | #this procedure is called internally... |
| 136 | if [ "$1" == '--upgrade' ]; then |
| 137 | echo -ne "$zenman_upgrade"; |
| 138 | "$pacman" $pacman_upgrade; |
| 139 | if [ $? != 0 ]; then |
| 140 | echo -e "\n$zenman_close"; |
| 141 | read; |
| 142 | else |
| 143 | sleep 2; |
| 144 | fi; |
| 145 | exit; |
| 146 | fi; |
| 147 | |
| 148 | #splash |
| 149 | echo -e "$zenman_usage" |
| 150 | if "$zenman_splash"; then |
| 151 | notify-send -i info --expire-time=5000 "$zenman_caption" "$zenman_start"; |
| 152 | fi; |
| 153 | |
| 154 | |
| 155 | #text-to-speech |
| 156 | zenman_speech() { |
| 157 | if "$zenman_speech" && [[ -x "$espeak" ]] ; then |
| 158 | "$espeak" -a "$espeak_volume" -v "$espeak_voice" "$1" & |
| 159 | fi; |
| 160 | } |
| 161 | |
| 162 | #unlocker |
| 163 | zenman_force_unlock() { |
| 164 | if [ -e "$pacman_lock" ]; then #check if db locked... |
| 165 | ps -eo comm | grep -i '^\(pacman\|yaourt\|powerpill\|gtkpacman\|pacupdate\|kpacupdate\|guzuta\|YAPG\|Shaman\)' >/dev/null; #check if pacman is running... |
| 166 | if [ $? != 0 ]; then |
| 167 | "$gksu" "rm -rf '$pacman_lock'"; |
| 168 | if [ $? != 0 ]; then |
| 169 | return 1; #gksu failed ;-( |
| 170 | else |
| 171 | return 0; #unlocked!!! |
| 172 | fi; |
| 173 | else |
| 174 | return 1; #pacman is running ;-( |
| 175 | fi; |
| 176 | else |
| 177 | return 0; #no locked!!! |
| 178 | fi; |
| 179 | } |
| 180 | |
| 181 | |
| 182 | while true; do |
| 183 | #uncomment next line if not running -Syuw from cron (and you better set higher zenman_interval) |
| 184 | if "$zenman_autorefresh"; then |
| 185 | echo -ne "$zenman_refreshing "; |
| 186 | zenity --notification --text "$zenman_refreshing" --window-icon="$zenman_refresh_ico" & |
| 187 | zenman_force_unlock; |
| 188 | "$gksu" "'$pacman' $pacman_refresh --noconfirm" >/dev/null 2>&1 |
| 189 | kill $! >/dev/null 2>&1; |
| 190 | kill -KILL $! >/dev/null 2>&1; |
| 191 | echo "$zenman_done"; |
| 192 | fi; |
| 193 | #check for new packages |
| 194 | pacman_new_packages=$("$pacman" $pacman_check --noconfirm 2>&1); |
| 195 | if [ $? == 0 ] && [ "$pacman_new_packages" != '' ]; then #fixed pacman always returning 0 issue... |
| 196 | #new packages found |
| 197 | zenman_speech "$speech_true"; |
| 198 | notify-send -i info "$zenman_caption" "$(echo -e "$zenman_true" "$pacman_new_packages")" |
| 199 | zenity --notification --timeout="$zenman_interval" --text "$(echo -e "$zenman_true" "$pacman_new_packages")" --window-icon="$zenman_true_ico"; |
| 200 | else |
| 201 | #no packages to update |
| 202 | zenity --notification --timeout="$zenman_interval" --text "$zenman_false" --window-icon="$zenman_false_ico"; |
| 203 | fi; |
| 204 | |
| 205 | #run full system upgrade if notification icon clicked |
| 206 | if [ $? == 0 ]; then |
| 207 | #try to unlock pacman db if locked and pacman is not running |
| 208 | zenman_force_unlock; |
| 209 | if [ $? == 0 ]; then |
| 210 | #update if unlocked |
| 211 | "$gksu" " '$xterm' -T '$zenman_caption' -e '$0 --upgrade \\\\'$zenman_configdir\\\\\''" ###TODO: fix quotes and escaping for configdir here later!!!! |
| 212 | zenman_force_unlock; |
| 213 | else |
| 214 | #show error if locked |
| 215 | notify-send -i error "$zenman_caption" "$zenman_locked"; |
| 216 | fi; |
| 217 | fi; |
| 218 | done; |