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