This repository has been archived by the owner on Nov 13, 2017. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 10
/
peppercarrot-main-menu.sh
executable file
·372 lines (314 loc) · 13 KB
/
peppercarrot-main-menu.sh
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
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
#!/bin/bash
#: Title : Pepper&Carrot Main Menu
#: Author : David REVOY < [email protected] >
#: License : GPL
scriptversion="1.0b"
# DEPENDENCIES :
# * Zenity (for GUI interface)
# * Gnome-terminal ( for launching task )
# Custom preferences
export texteditor="geany"
export filebrowser="nemo"
# Utils
export scriptpath="`dirname \"$0\"`"
export projectname="${PWD##*/}"
export workingpath="${PWD}"
export isodate=$(date +%Y-%m-%d)
export version=$(date +%Y-%m-%d_%Hh%M)
export versiondaily=$(date +%Y%m%d)
export Off=$'\e[0m'
export Purple=$'\e[1;35m'
export Blue=$'\e[1;34m'
export Green=$'\e[1;32m'
export Red=$'\e[1;31m'
export Yellow=$'\e[1;33m'
export White=$'\e[1;37m'
export BlueBG=$'\e[1;44m'
export RedBG=$'\e[1;41m'
export PurpleBG=$'\e[1;45m'
export Black=$'\e[1;30m'
# Config.sh external file (gitignored)
if [ -f "$scriptpath"/config.sh ]; then
source "$scriptpath"/config.sh
echo "${Green}* config.sh found${Off}"
echo "* Welcome $configuser"
else
echo "${Red}* config.sh not found, creating it${Off}"
# Write file
echo '#!/bin/bash' > "$scriptpath"/config.sh
echo '' >> "$scriptpath"/config.sh
echo '# Global config' >> "$scriptpath"/config.sh
echo 'export projectroot="/home/username/peppercarrot"' >> "$scriptpath"/config.sh
echo '' >> "$scriptpath"/config.sh
echo '# Uploaders' >> "$scriptpath"/config.sh
echo 'confighost="ftp.yourhostname.net"' >> "$scriptpath"/config.sh
echo 'configuser="username"' >> "$scriptpath"/config.sh
echo 'configpass="password"' >> "$scriptpath"/config.sh
# Verbose
echo "${Yellow} ==> done${Off}"
echo "* please configure your config.sh file now"
echo "* and launch this script again"
exit
fi
# Define absolute path to folders in usage
export folder_webcomics="$projectroot"/webcomics
export folder_scripts="$projectroot"/scripts
export folder_wiki="$projectroot"/wiki
# Move folder cursor to webcomic
# zenity --info --text="Debug 1: $folder_webcomics"
cd "$folder_webcomics"
_main_menu()
{
# Populate the menu with all webcomic folder found
for directories in $(find $folder_webcomics -maxdepth 1 -type d -printf '%f\n' | sort ); do
episodefolder=$directories
if [[ $episodefolder == "ep"* ]]; then
items+=( "$episodefolder"* )
fi
done
if [ -d "$folder_webcomics/New" ]; then
items+=( "New"* )
fi
items+=( "+ Add a new episode" )
items+=( " " )
items+=( "Update everything" )
items+=( "Edit All README.md" )
items+=( "Upload FTP (low)" )
items+=( "Upload FTP (hi)" )
items+=( "Upload RSYNC-SSH (hi)" )
items+=( "Update Wiki" )
items+=( "Generate Markdown files" )
items+=( "Render all episodes" )
menuchoice=$(zenity --list --title='Pepper&Carrot Main Menu' \
--width=400 --height=570 --window-icon="$folder_scripts/lib/peppercarrot_icon.png" \
--text='Select an episode or an action' \
--column='menu' "${items[@]}");
clear
# Avoid Zenity bug with trailing | on option selected
menuchoicecleaned=${menuchoice%|*}
}
_sub_menu()
{
echo "=> rendering script"
echo "$folder_webcomics"/"$menuchoicecleaned"/
subitems+=( "★ Render $menuchoicecleaned" )
subitems+=( " " )
subitems+=( "Open $menuchoicecleaned folder with $filebrowser" )
subitems+=( "Open lang folder with $filebrowser" )
subitems+=( "Open lang folder in a terminal" )
subitems+=( "Edit README.md" )
subitems+=( " " )
subitems+=( "Upload FTP (low)" )
subitems+=( "Upload FTP (hi)" )
subitems+=( "Upload RSYNC-SSH (hi)" )
subitems+=( " " )
subitems+=( "← Back" )
while :
do
submenuchoice=$(zenity --list --title=''$menuchoicecleaned'' \
--width=400 --height=450 --window-icon="$folder_scripts/lib/peppercarrot_icon.png" \
--text='Select an action' \
--column='menu' "${subitems[@]}");
clear
submenuchoicecleaned=${submenuchoice%|*}
if [ "$submenuchoicecleaned" = "★ Render $menuchoicecleaned" ]; then
cd "$folder_webcomics"/"$menuchoicecleaned"/
gnome-terminal --command="$folder_scripts"/renderfarm.sh &
elif [ "$menuchoicecleaned" = " " ]; then
echo "${Green}* mistake!! ${Off}"
zenity --error --text "You selected a spacer, try again."; echo $?
# reload homepage
bash "$folder_scripts"/peppercarrot-main-menu.sh
elif [ "$submenuchoicecleaned" = "Open $menuchoicecleaned folder with $filebrowser" ]; then
"$filebrowser" "$folder_webcomics"/"$menuchoicecleaned"/ &
elif [ "$submenuchoicecleaned" = "Open lang folder with $filebrowser" ]; then
"$filebrowser" "$folder_webcomics"/"$menuchoicecleaned"/lang/ &
elif [ "$submenuchoicecleaned" = "Open lang folder in a terminal" ]; then
gnome-terminal --working-directory="$folder_webcomics"/"$menuchoicecleaned"/lang/ &
elif [ "$submenuchoicecleaned" = "Edit README.md" ]; then
"$texteditor" "$folder_webcomics"/"$menuchoicecleaned"/lang/README.md &
elif [ "$submenuchoicecleaned" = "Upload FTP (low)" ]; then
cd $folder_webcomics
gnome-terminal --command="$folder_scripts"/lowres_uploader.sh
elif [ "$submenuchoicecleaned" = "Upload FTP (hi)" ]; then
cd $folder_webcomics
gnome-terminal --command="$folder_scripts"/hires_uploader.sh
elif [ "$submenuchoicecleaned" = "Upload RSYNC-SSH (hi)" ]; then
cd $folder_webcomics
gnome-terminal --command="$folder_scripts"/hires_uploader-ssh.sh
else
# reload homepage
bash "$folder_scripts"/peppercarrot-main-menu.sh
break
exit
fi
done
}
# Execute
_main_menu
# Filter answers
if [ "$menuchoicecleaned" = " " ]; then
echo "${Green}* mistake!! ${Off}"
zenity --error --text "You selected a spacer, try again."; echo $?
# reload homepage
bash "$folder_scripts"/peppercarrot-main-menu.sh
elif [ "$menuchoicecleaned" = "" ]; then
# OK or Cancel is pressed without selection, we exit.
exit
elif [ "$menuchoicecleaned" = "Edit All README.md" ]; then
# Loop on all episode folder
for directories in $(find $folder_webcomics -maxdepth 1 -type d -printf '%f\n' | sort ); do
episodefolder=$directories
if [[ $episodefolder == "ep"* ]]; then
# Then open README.md in text-editor
"$texteditor" "$folder_webcomics"/"$episodefolder"/lang/README.md &
fi
done
# Reload homepage
bash "$folder_scripts"/peppercarrot-main-menu.sh
elif [ "$menuchoicecleaned" = "Render all episodes" ]; then
# loop on episode
for directories in $(find $folder_webcomics -maxdepth 1 -type d -printf '%f\n' | sort ); do
episodefolder=$directories
if [[ $episodefolder == *"ep"* ]]; then
cd "$folder_webcomics"/"$episodefolder"/
gnome-terminal --command="$folder_scripts"/renderfarm.sh &
sleep 40
fi
done
elif [ "$menuchoicecleaned" = "Generate Markdown files" ]; then
###########################
# GENERATE MARKDOWN FILES #
###########################
# Remove previous markdown generated
cd "$folder_webcomics"
rm "$folder_webcomics"/README-GENERAL-LICENSE.md
rm "$folder_webcomics"/.episodes-list.md
rm "$folder_webcomics"/episode.json
# Generate .episode-list.md
# =========================
for directories in $(find $folder_webcomics -maxdepth 1 -type d -printf '%f\n' | sort ); do
episodefolder=$directories
if [[ $episodefolder == *"ep"* ]]; then
cd "$folder_webcomics"
echo "$episodefolder" >> "$folder_webcomics"/.episodes-list.md
fi
done
# Generate episode.json
# =====================
touch "$folder_webcomics"/episode.json
echo "[" >> "$folder_webcomics"/episode.json
for directories in $(find $folder_webcomics -maxdepth 1 -type d -printf '%f\n' | sort ); do
episodefolder=$directories
if [[ $episodefolder == *"ep"* ]]; then
cd "$folder_webcomics"/"$episodefolder"/lang/
pagecount=0
# subloop: find the number of page
for files in $(find $folder_webcomics/"$episodefolder"/lang/ -maxdepth 1 -type f -printf '%f\n' | sort ); do
if [[ $files == *.png ]]; then
pagecount=$((pagecount+1))
fi
done
# remove cover and header from the count.
pagecount=$((pagecount-2))
# Generate with jo
jo -p name=$episodefolder total_page=$pagecount translated_languages=$(jo -a */) >> "$folder_webcomics"/episode.json
echo "," >> "$folder_webcomics"/episode.json
fi
done
# remove last line, to remove the exeeding "," comma
sed -i '$ d' "$folder_webcomics"/episode.json
# close the global bracket
echo "]" >> "$folder_webcomics"/episode.json
# clean trailing / printed on lang folders
sed -i 's/\///g' "$folder_webcomics"/episode.json
# Generate CONTRIBUTORS.md
# ========================
cd "$folder_webcomics"
for directories in $(find $folder_webcomics -maxdepth 1 -type d -printf '%f\n' | sort ); do
episodefolder=$directories
if [[ $episodefolder == "ep"* ]]; then
cat "$folder_webcomics"/"$episodefolder"/lang/README.md >> "$folder_webcomics"/A.tmp
fi
done
# Sort of the lines together
sort -u A.tmp >> B.tmp
# Keep only lines starting with a *
sed -n -e '/^\*/p' B.tmp >> C.tmp
# remove line containing this strings:
sed -i '/zip folder/d' C.tmp
sed -i '/high-resolution/d' C.tmp
sed -i '/gfx-only subfolder/d' C.tmp
sed -i '/Jpeg 92/d' C.tmp
sed -i '/www.peppercarrot.com/d' C.tmp
# try to enhance formating (line break)
sed -i 's/* /\n* /g' C.tmp
# fix formating double space, or extra space
sed -i 's/ / /g' C.tmp
sed -i 's/ :/:/g' C.tmp
# Mega cleanup merging thanks the python script of M1dgard:
"$folder_scripts"/merge_translators.py C.tmp > D.tmp
# move the file to final:
cp D.tmp "$folder_webcomics"/CONTRIBUTORS.md
cd "$folder_webcomics"
# cleanup
rm A.tmp
rm B.tmp
rm C.tmp
rm D.tmp
# add the header
echo "" >> "$folder_webcomics"/README-GENERAL-LICENSE.md
echo "PEPPER&CARROT - README - GENERAL LICENSE" >> "$folder_webcomics"/README-GENERAL-LICENSE.md
echo "========================================" >> "$folder_webcomics"/README-GENERAL-LICENSE.md
echo "" >> "$folder_webcomics"/README-GENERAL-LICENSE.md
echo " This file is an autogenerated stiching of the README(s) of each episode." >> "$folder_webcomics"/README-GENERAL-LICENSE.md
echo " Each episode has their own contributors. Respect them when attributing a large work with many pages." >> "$folder_webcomics"/README-GENERAL-LICENSE.md
echo " This document (updated monthly) will help you to get an overview of the license." >> "$folder_webcomics"/README-GENERAL-LICENSE.md
echo "" >> "$folder_webcomics"/README-GENERAL-LICENSE.md
echo "## List of all translator and correctors" >> "$folder_webcomics"/README-GENERAL-LICENSE.md
echo "_Note: this list is autogenerated. Check full README(s) pasted under this list._" >> "$folder_webcomics"/README-GENERAL-LICENSE.md
cat "$folder_webcomics"/CONTRIBUTORS.md >> "$folder_webcomics"/README-GENERAL-LICENSE.md
echo "" >> "$folder_webcomics"/README-GENERAL-LICENSE.md
echo "________________________________________________________________________________" >> "$folder_webcomics"/README-GENERAL-LICENSE.md
echo "" >> "$folder_webcomics"/README-GENERAL-LICENSE.md
echo "" >> "$folder_webcomics"/README-GENERAL-LICENSE.md
# Loop on episodes
for directories in $(find $folder_webcomics -maxdepth 1 -type d -printf '%f\n' | sort ); do
episodefolder=$directories
if [[ $episodefolder == "ep"* ]]; then
cat "$folder_webcomics"/"$episodefolder"/lang/README.md >> "$folder_webcomics"/README-GENERAL-LICENSE.md
# episode footer
echo "" >> "$folder_webcomics"/README-GENERAL-LICENSE.md
echo "" >> "$folder_webcomics"/README-GENERAL-LICENSE.md
echo "________________________________________________________________________________" >> "$folder_webcomics"/README-GENERAL-LICENSE.md
echo "" >> "$folder_webcomics"/README-GENERAL-LICENSE.md
echo "" >> "$folder_webcomics"/README-GENERAL-LICENSE.md
fi
done
# reload homepage
bash "$folder_scripts"/peppercarrot-main-menu.sh
break
exit
elif [ "$menuchoicecleaned" = "Upload FTP (low)" ]; then
cd "$folder_webcomics"
gnome-terminal --command="$folder_scripts"/lowres_uploader.sh
elif [ "$menuchoicecleaned" = "Upload FTP (hi)" ]; then
cd "$folder_webcomics"
gnome-terminal --command="$folder_scripts"/hires_uploader.sh
elif [ "$menuchoicecleaned" = "Upload RSYNC-SSH (hi)" ]; then
cd $folder_webcomics
gnome-terminal --command="$folder_scripts"/hires_uploader-ssh.sh
elif [ "$menuchoicecleaned" = "Update Wiki" ]; then
cd "$folder_wiki"
gnome-terminal --command="$folder_scripts"/wiki_uploader.sh
elif [ "$menuchoicecleaned" = "Update everything" ]; then
cd "$projectroot"
gnome-terminal --command="$folder_scripts"/install.sh
elif [ "$menuchoicecleaned" = "+ Add a new episode" ]; then
cd "$folder_webcomics"
gnome-terminal --command="$folder_scripts"/episode-creator.sh
else
# we got an episode, not an action.
# execute submenu!
_sub_menu
fi