-
Notifications
You must be signed in to change notification settings - Fork 271
/
pschedule
executable file
·231 lines (216 loc) · 8.19 KB
/
pschedule
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
#! /bin/bash
#pSchedule
#Copyright 2007,2008,2009,2010,2011,2012,2013,2014,2015
#Sigmund Berglund
#------------------------------
#pSchedule is released under the GNU General Public License (GPL). You have the right to use and modify this software in any way you like, so long as any derivative works remain under a GPL license.
#This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY.
#See the GNU General Public License homepage for more details. <http://www.gnu.org/licenses/>.
#------------------------------
VERSION="1.1.7"
export PROGPATH="/usr/local/pschedule"
export BROWSER="defaultbrowser"
export GTKDIALOG=gtkdialog
#gettext
export TEXTDOMAIN=pschedule
export OUTPUT_CHARSET=UTF-8
mkdir -p /var/local/cron/crontabs #150401
#parameters
while [ $# != 0 ]; do
I=1
while [ $I -le `echo $# | wc -c` ]; do #check -xft
case $1 in
-e) MODE='-edit';;
-n) MODE='-new';;
-s) SILENT=true;;
-v|--version) echo pSchedule $VERSION; exit;;
-h|--help) echo '
Usage: pschedule [Options(s)] [Command] [Task Name]
Options
-e Edit given task
-n Edit new task
-h | --help Show this help message
-s Do not show main window. Go straight to task editor
-v | --version Show pSchedule version'; exit;;
*) export TASK="$1"; export TASKNAME="$2"
shift; shift; break; break;;
esac
shift
I=$[$I+1]
done
done
#cron check
if [ -f $HOME/.config/autostart/cron-check ]; then #150401
[ "$(grep '/var/local/cron/crontabs' $HOME/.config/autostart/cron-check)" == "" ] && rm -f $HOME/.config/autostart/cron-check
fi
if [ ! -f $HOME/.config/autostart/cron-check ]; then
#include a link to crond in ~/.config/autostart for autostart cron daemon at boot
mkdir $HOME/.config/autostart > /dev/null 2>&1
#150401 use busybox crond, set working path:
echo '
TMP="`busybox ps`"
TMP2=`echo "$TMP" | grep " crond"`
if [ -z "$TMP2" ]; then #cron is not running
busybox crond -c /var/local/cron/crontabs
fi' > $HOME/.config/autostart/cron-check
chmod 722 $HOME/.config/autostart/cron-check
#---
PS="`busybox ps`" #150401
kill `echo "$PS" | grep 'crond' | sed -e 's%^ %%g' | cut -f 1 -d ' ' | tr '\n' ' '` 2>/dev/null #150401
busybox crond -c /var/local/cron/crontabs #restart cron 150401
#Did these really happen. Do user has permission.
TMP=`busybox ps`; TMP="`echo "$TMP" | grep " crond"`" #150401
if [ -z "$TMP" ]; then #cron is not running
FRAME="Error"; TXT2="$(gettext 'Cron deamon is not running. You need root-access to start cron')"; IMG="dialog-error"
. "$PROGPATH"/box_ok
fi
fi
#build treeitems for 'Add task' --- better have the delay at startup
COUNT=0; ITEMS_HOUR="$ITEMS_HOUR<item>$(gettext 'any')</item>"
while [ $COUNT -lt 24 ]; do
if [ $COUNT -lt 10 ]; then COUNT=0"$COUNT"; fi #always 02 digits
export ITEMS_HOUR="$ITEMS_HOUR<item>$COUNT</item>"
COUNT=`echo "$COUNT + 1" | bc`
done
COUNT=0; ITEMS_MINUTE="$ITEMS_MINUTE<item>$(gettext 'any')</item>"
while [ $COUNT -lt 60 ]; do
if [ $COUNT -lt 10 ]; then COUNT=0"$COUNT"; fi #always 02 digits
export ITEMS_MINUTE="$ITEMS_MINUTE<item>$COUNT</item>"
COUNT=`echo "$COUNT + 1" | bc`
done
COUNT=1; ITEMS_DAY="$ITEMS_DAY<item>$(gettext 'any')</item>"
while [ $COUNT -lt 32 ]; do
export ITEMS_DAY="$ITEMS_DAY<item>$COUNT.</item>"
COUNT=`echo "$COUNT + 1" | bc`
done
export ITEMS_WEEKDAY="$ITEMS_WEEKDAY
<item>$(gettext 'any')</item>
<item>$(gettext 'Mondays')</item>
<item>$(gettext 'Tuesdays')</item>
<item>$(gettext 'Wednesdays')</item>
<item>$(gettext 'Thursdays')</item>
<item>$(gettext 'Fridays')</item>
<item>$(gettext 'Saturdays')</item>
<item>$(gettext 'Sundays')</item>"
export ITEMS_MONTH="$ITEMS_MONTH
<item>$(gettext 'any')</item>
<item>$(gettext 'January')</item>
<item>$(gettext 'February')</item>
<item>$(gettext 'March')</item>
<item>$(gettext 'April')</item>
<item>$(gettext 'May')</item>
<item>$(gettext 'June')</item>
<item>$(gettext 'July')</item>
<item>$(gettext 'August')</item>
<item>$(gettext 'September')</item>
<item>$(gettext 'October')</item>
<item>$(gettext 'November')</item>
<item>$(gettext 'December')</item>"
#---
export about='
<window title="pSschedule - about" icon-name="pschedule">
<notebook labels="About|License|Credits">
<frame>
<text><label>""</label></text>'"
<text use-markup=\"true\"><label>\"<b><span size='"'x-large'"'>pSchedule</span> $VERSION</b>\"</label></text>
<text use-markup=\"true\"><label>Sigmund Berglund, Copyright 2007-2014</label></text>
<text><label>\"\"</label></text>
<button>
<label>\"http://www.murga-linux.com/puppy/viewtopic.php?t=22166\"</label>
<action>$BROWSER http:\/\/www.murga-linux.com/puppy/viewtopic.php?t=22166 &</action>
</button>
</frame>
<frame>
<text use-markup=\"true\"><label>\"pSchedule is released under the <b>GNU General Public License</b> (GPL). You have the right to use and modify this software in any way you like, so long as any derivative works remain under a GPL license.\"</label></text>
<text use-markup=\"true\"><label>\"This program is distributed in the hope that it will be useful, but <b><span color='"'red'"'>WITHOUT ANY WARRANTY</span></b>. See the GNU General Public License homepage for more details.\"</label></text>
<hbox>
<button label=\"http://www.gnu.org/licenses/\"><action>$BROWSER http:\/\/www.gnu.org\/licenses\/</action></button>
</hbox>
</frame>
<frame>
<edit><default>\"Translators:
German - Lutz-Ulrich Ringel (L18L)
Others:
jake_take for improvements.
HairyWill for advanced bash help.
mcewanw for cli options
\"</default></edit>
</frame>
</notebook>
</window>"
S='
<window title="pSchedule '$VERSION' - '$(gettext 'Task on time')'" icon-name="pschedule">
<vbox>
<hbox>
<button space-expand="false" space-fill="false" tooltip-text="'$(gettext 'Launch settings window')'">
<variable>BUTTON_ADD</variable>
<label>'$(gettext 'Schedule new task')'</label>'
[ -f /usr/share/pixmaps/puppy/clock_interval.svg ] && S=$S'<input file>/usr/share/pixmaps/puppy/clock_interval.svg</input>' || S=$S'<input file stock="gtk-add"></input>'
S=$S'<height>22</height>
<action>. '$PROGPATH'/func_new</action>
<action>. '$PROGPATH'/func_cron_to_human</action>
<action>refresh:TREE</action>
</button>
<text space-expand="true" space-fill="true"><label>""</label></text>
<button>
<variable>BUTTON_EDIT</variable>
<label>'$(gettext 'Edit')'</label>
<input file stock="gtk-edit"></input>
<visible>disabled</visible>
<action>. '$PROGPATH'/func_new -edit</action>
<action>. '$PROGPATH'/func_cron_to_human</action>
<action>refresh:TREE</action>
</button>
<button>
<variable>BUTTON_DEL</variable>
<label>'$(gettext 'Delete')'</label>
<input file stock="gtk-delete"></input>
<visible>disabled</visible>
<action>. '$PROGPATH'/func_delete</action>
<action>. '$PROGPATH'/func_cron_to_human</action>
<action>refresh:TREE</action>
</button>
<button>
<variable>BUTTON_RUN</variable>
<label>'$(gettext 'Execute now')'</label>
<input file stock="gtk-execute"></input>
<visible>disabled</visible>
<action>. '$PROGPATH'/func_run</action>
</button>
</hbox>
<tree rules_hint="true" exported_column="0">
<width>500</width><height>200</height>
<label>"'$(gettext 'Task')'|'$(gettext 'Schedule')'|'$(gettext 'Cron command')'"</label>
<variable>TREE</variable>
<input>cat /tmp/pschedule-treeitems</input>
<action signal="button-release-event">enable:BUTTON_DEL</action>
<action signal="button-release-event">enable:BUTTON_EDIT</action>
<action signal="button-release-event">enable:BUTTON_RUN</action>
</tree>
<hbox>
<button tooltip-text="'$(gettext 'About')'">
<input file stock="gtk-about"></input>
<action>launch:about</action>
</button>
<button tooltip-text="'$(gettext 'Quit')'">
<input file stock="gtk-quit"></input>
<action type="exit">EXIT</action>
</button>
</hbox>
</vbox>
</window>'
export pschedule="$S"
. $PROGPATH/func_cron_to_human
[ "$SILENT" ] && export TREE="$TASK" #no tree with no gui.
[ "$TASK" ] && . $PROGPATH/func_new "$MODE" "$TASK" "$TASKNAME" &
if [ ! "$SILENT" ]; then
I=$IFS; IFS=""
for STATEMENTS in $($GTKDIALOG -p pschedule); do
eval $STATEMENTS
done
IFS=$I
case $EXIT in
*) rm /tmp/pschedule*
exit;;
esac
fi