-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathArchAppImageGen
executable file
·689 lines (566 loc) · 14.3 KB
/
ArchAppImageGen
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
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
#!/bin/bash
#
# Configuration Script for ArchAppImage
#
# By Mauricio Ferrari
#
###############################################################################
set -e
printf "\e]2;ArchAppImage - Empacotador de AppImage\007"
: "$(readlink -f "$0")"
CWD=${_%/*}
cols=${COLUMNS:-$(tput cols)}
rows=${LINES:-$(tput lines)}
test $cols -lt 90 -o $rows -lt 30 && {
printf '\033[8;32;94t'
sleep 0.1
exec $0 # Sério. Se ajustar a resolução, tem que abrir de novo.
exit 0
}
config_file=~/.config/ArchAppImage.conf
rst="\e[0m"
blue="\e[1;38;5;7;48;5;24m"
alt_blue="\e[1;38;5;7;48;5;18m"
red="\e[1;38;5;7;48;5;160m"
violet="\e[1;38;5;7;48;5;57m"
box="\e[1;38;5;7;48;5;237m"
green="\e[1;38;5;7;48;5;28m"
TL="┌" # Top Left
TR="┐" # Top Right
BL="└" # Bottom Left
BR="┘" # Bottom Right
H="─" # Horizontal
V="│" # Vertical
# declare -i text_size=0
function _project_dir
{
test -f $config_file || printf "PROJECT_DIR=$HOME/ArchAppImage\n" > $config_file
: "$( grep "PROJECT_DIR" $config_file )"
project_dir="${_#*=}"
test -d $project_dir || {
mkdir -p "$HOME/ArchAppImage/tools"
for f in APP-ArchAppImage AppRun_bwrap AppRun_Conteiner AppRun_proot AppRun_Universal
{
test -f "$project_dir/tools/$f" || {
test -f "$CWD/tools/$f" && cp "$CWD/tools/$f" "$project_dir/tools"
}
}
}
printf $project_dir
}
function _top_border
{
declare -i cl=${1:-$cols}
color="$blue"
test -z "$2" || {
tput cup $(($2 + 1)) $3
color="$alt_blue"
}
printf "${color}$TL"
for ((x = 2; x < cl; x++))
{
printf "$H"
}
printf "$TR\n"
}
function _vertical_border_background
{
declare -i cl=${1:-$cols}
declare -i rs=${2:-$rows}
for ((y = 2; y < rs; y++))
{
test -z "$3" || tput cup $(($3 + y)) $4
printf "${V}%$(($cl - 2))s${V}\n" " "
}
}
function _bottom_border
{
declare -i cl=${1:-$cols}
test -z "$3" || tput cup $(($3 + $2)) $4
printf "$BL"
for ((x = 2; x < cl; x++))
{
printf "$H"
}
printf "$BR"
}
function _title
{
msg=${1:-"sample title"}
text_length=${#msg}
color="$blue"
declare -i text_x=(cols-text_length)/2
declare -i y=${2:-1}
test $y -eq 0 && {
y=(rows-$3)/2+2
color="$alt_blue"
}
tput cup $y $text_x
printf "$color${msg^^}"
}
function _center_text
{
centertext=( $1 )
declare -i i=${2:-0}
declare -i y=${3:-0}
for text in "${centertext[@]//_/ }"
{
declare -i cp=${#text}
declare -i pos_x=(cols-cp)/2
declare -i pos_y=(rows/2)-y+i
cap="${text#*\'}"
cap="${cap%\'*}"
text="${text//\[/$red\[}"
text="${text//\]/\]$alt_blue}"
text="${text//\'*\'/$violet\'$cap\'$alt_blue}"
tput cup $pos_y $pos_x
printf "$text\n"
i+=1
}
}
function _custom_read
{
declare -r CHAR_LF=$'\n'
declare -r CHAR_ESC=$'\e'
declare -r CHAR_BS=$'\x7F'
DISRES=
RES=
test -z "$1" || RES="$1"
printf "$RES"
tput sc
while read -rN 1 -d "" CHAR; do
case "$CHAR" in
"$CHAR_ESC")
IFS= read -t 0.0001 -r -n 2 -s rest || true
test -z "$rest" || {
tput rc
printf ' '
tput rc
continue
}
RES=
DISRES=1
clear
break
;;
"$CHAR_LF")
test -z "$RES" -a -z "$dis_enter" || break
tput rc
continue
;;
"$CHAR_BS")
tput rc
printf ' '
tput rc
test -z $RES || {
RES="${RES::-1}"
echo -ne "\b \b"
}
;;
*)
RES+="${CHAR}"
;;
esac
tput sc
done
}
function _text_box
{
# text_size=${#1}
color=${textcolor:-$violet}
declare -i start_x=(cols-cl)/2+2
declare -i start_y=(rows-rs)/2+2+${3:-0}
declare -i start_z=start_x+${#1}+2
text=$1
text="${text//\[/$color\[}"
text="${text//\]/\]$alt_blue}"
tput cup $start_y $start_x
printf "${alt_blue}$text:"
tput cup $start_y $start_z
test -z $dis_box || return 0
printf "$box%$(( $2 - ${#1} - 6 ))s" ""
tput cup $start_y $(( start_z + 1 ))
}
function _screen_bg
{
cl=${1:-$cols}
rs=${2:-$rows}
test -z "$1" || {
declare -i start_x=(cols-cl)/2
declare -i start_y=(rows-rs)/2
}
_top_border $cl $start_y $start_x
_vertical_border_background $cl $rs $start_y $start_x
_bottom_border $cl $rs $start_y $start_x
tput cuu1
printf "\r$blue$V"
}
function __config
{
cl=
rs=
_screen_bg
_title "ArchAppImage - Empacotador de AppImage - Configurações"
_screen_bg 60 9
_title "Configurações do ArchAppImage" 0 9
_text_box "Diretório do Projeto" 60 3
_custom_read "$( _project_dir )"
printf "$rst"
clear
test -z "$RES" || {
test -d "$RES" || mkdir -p "$RES"
test -d "$RES/tools" || mkdir -p "$RES/tools"
for f in APP-ArchAppImage AppRun_bwrap AppRun_Conteiner AppRun_proot AppRun_Universal
{
test -f "$RES/tools/$f" || {
test -f "$CWD/tools/$f" && cp "$CWD/tools/$f" "$RES/tools"
}
}
sed -i "s|PROJECT_DIR=.*|PROJECT_DIR=$RES|" $config_file
}
}
function __apply_settings
{
pdir="$( _project_dir )"
prg="$pdir/$package_name-ArchAppImage"
test -f "$prg" || cp -a "$pdir/tools/APP-ArchAppImage" "$prg"
sed -i "s/package_name=.*/package_name=\"$package_name\"/" $prg
sed -i "s/binary_name=.*/binary_name=\"$binary_name\"/" $prg
sed -i "s/level_search_deps=.*/level_search_deps=$dep_level/" $prg
test -z "$add_deps" || {
sed -i "s/dependences=.*/dependences=\"$add_deps\"/" $prg
sed -i "s/level_search_add_deps=.*/level_search_add_deps=$add_dep_level/" $prg
}
test $appimage_mode -eq 0 && sed -i "s/mode=.*/mode=\"default\"/" $prg || sed -i "s/mode=.*/mode=\"conteiner\"/" $prg
test $appimage_mode -eq 1 && sed -i "s/use_apprun_type=.*/use_apprun_type=0/" $prg
test $appimage_mode -eq 2 && sed -i "s/use_apprun_type=.*/use_apprun_type=1/" $prg
test $appimage_mode -eq 3 && sed -i "s/use_apprun_type=.*/use_apprun_type=2/" $prg
test $appimage_mode -eq 3 && sed -i "s/use_apprun_type=.*/use_apprun_type=3/" $prg
test $conteiner_custom -eq 0 || {
sed -i "s/custom_conteiner_name=.*/custom_conteiner_name=\"$custom_name\"/" $prg
sed -i "s/enable_multilib=.*/enable_multilib=$enable_multilib/" $prg
sed -i "s/enable_chaoticaur=.*/enable_chaoticaur=$enable_chaotic/" $prg
sed -i "s/enable_archlinuxcn=.*/enable_archlinuxcn=$enable_archlinuxcn/" $prg
sed -i "s/enable_build_aur=.*/enable_build_aur=$enable_aur/" $prg
}
sed -i "s/config_all_locales=.*/config_all_locales=$enable_lang/" $prg
sed -i "s/create_appimage=.*/create_appimage=$create_appimage/" $prg
}
function __new_appimage
{
cl=
rs=
_screen_bg
_title "ArchAppImage - Empacotador de AppImage - Novo Projeto"
_screen_bg 90 28
_title "Novo Projeto de AppImage" 0 28
_text_box "Nome do Pacote" 90 2
_custom_read
test -z "$RES" && return 0
package_name="$RES"
_text_box "Nome do Executável Binário" 90 4
_custom_read "$package_name"
test -z "$RES" && return 0
binary_name="$RES"
dis_box=1
_text_box "Nível de Busca de Dependencias (1-9) def.1 -->" 90 6
echo -ne "\b\b "
read -N 1 -s res
dis_box=
case "$res" in
[1-9])
dep_level=$res
printf "$green[ $res ]$alt_blue"
;;
$'\x1b')
clear
return 0
;;
*)
dep_level=1
printf "$green[ 1 ]$alt_blue"
;;
esac
declare -i num=8
_text_box "Dependencias Adicionais" 90 $num
dis_enter=1
_custom_read
dis_enter=
test -z "$DISRES" || return 0
add_deps="$RES"
test -z "$add_deps" || {
num+=2
dis_box=1
_text_box "Nível de Busca de Dependencias Adicionais (1-9) def.1 --> " 90 $num
echo -ne "\b\b "
read -N 1 -s res
dis_box=
case "$res" in
[1-9])
add_dep_level=$res
printf "$green[ $res ]$alt_blue"
;;
$'\x1b')
clear
return 0
;;
*)
add_dep_level=1
printf "$green[ 1 ]$alt_blue"
;;
esac
}
num+=2
dis_box=1
_text_box "AppRun(def.0): [ 0 ] Default [ 1 ] junest [ 2 ] bwrap" 90 $num
echo -ne "\b\b "
num+=1
_text_box " [ 3 ] proot [ 4 ] bwrap_proot" 90 $num
echo -ne "\b\b "
read -N 1 -s res
dis_box=
old=0
r=69
case "$res" in
0)
appimage_mode=$res
old=1
;;
1)
appimage_mode=$res
r=50
old=1
;;
2)
appimage_mode=$res
r=31
old=1
;;
3)
appimage_mode=$res
r=37
;;
4)
appimage_mode=$res
r=18
;;
$'\x1b')
clear
return 0
;;
*)
appimage_mode=0
res=0
;;
esac
test $old -eq 1 && tput cuu1
tput cub $r
printf "$green[ $res ]$alt_blue"
dis_box=1
num+=2
_text_box "Configurar um Contêiner Customizado? (def.N) --> [ Y ] Sim [ N ] Não" 90 $num
echo -ne "\b\b "
read -N 1 -s res
dis_box=
case "$res" in
[yY])
conteiner_custom=1
tput cub 22
printf "$green[ Y ]$alt_blue"
;;
$'\x1b')
clear
return 0
;;
*)
conteiner_custom=0
tput cub 10
printf "$red[ N ]$alt_blue"
;;
esac
test $conteiner_custom -eq 0 || {
num+=2
_text_box "Nome Customizado" 90 $num
_custom_read "$package_name"
test -z "$RES" && return 0
custom_name="$RES"
textcolor="$red"
dis_box=1
num+=2
_text_box "Opções --> [ 0 ] Multilib [ 1 ] ChaoticAUR [ 2 ] ArchLinuxCN [ 3 ] AUR" 90 $num
echo -ne "\b\b "
dis_box=
textcolor=
enable_multilib=0
enable_chaotic=0
enable_archlinuxcn=0
enable_aur=0
r=68
while read -rN 1 -d "" -s res; do
case "$res" in
0)
test $enable_multilib -eq 0 && {
enable_multilib=1
color="$green"
} || {
enable_multilib=0
color="$red"
}
r=68
;;
1)
test $enable_chaotic -eq 0 && {
enable_chaotic=1
color="$green"
} || {
enable_chaotic=0
color="$red"
}
r=48
;;
2)
test $enable_archlinuxcn -eq 0 && {
enable_archlinuxcn=1
color="$green"
} || {
enable_archlinuxcn=0
color="$red"
}
r=29
;;
3)
test $enable_aur -eq 0 && {
enable_aur=1
color="$green"
} || {
enable_aur=0
color="$red"
}
r=10
;;
$'\x1b')
clear
return 0
;;
$'\n')
break
;;
*)
continue
;;
esac
tput sc
tput cub $r
printf "$color[ $res ]$alt_blue "
tput rc
done
}
dis_box=1
num+=2
_text_box "Ativar Todos os Idiomas? (def.N) --> [ Y ] Sim [ N ] Não [ A ] Auto" 90 $num
echo -ne "\b\b "
read -N 1 -s res
dis_box=
case "$res" in
[yY])
enable_lang=1
tput cub 35
printf "$green[ Y ]$alt_blue"
;;
[aA])
enable_lang=2
tput cub 11
printf "$green[ A ]$alt_blue"
;;
$'\x1b')
clear
return 0
;;
*)
enable_lang=0
tput cub 23
printf "$red[ N ]$alt_blue"
;;
esac
dis_box=1
num+=2
_text_box "Criar AppImage de Imediato? (def.N) --> [ Y ] Sim [ N ] Não" 90 $num
echo -ne "\b\b "
read -N 1 -s res
dis_box=
case "$res" in
[yY])
create_appimage=1
tput cub 22
printf "$green[ Y ]$alt_blue"
;;
$'\x1b')
clear
return 0
;;
*)
create_appimage=0
tput cub 10
printf "$red[ N ]$alt_blue"
;;
esac
textcolor="$green"
dis_box=1
num+=2
_text_box "[ Concluído - ENTER para Continuar ]" 90 $num
dis_box=
textcolor=
echo -ne "\b\b "
read -N1
printf "$rst"
clear
__apply_settings
}
function __main
{
cl=
rs=
_screen_bg
tput sc
_title "ArchAppImage - Empacotador de AppImage - Mauricio Ferrari [LinuxDicasPro]"
_screen_bg 60 15
_title "Bem-Vindo ao ArchAppImage" 0 15
text=(
"O 'ArchAppImage' é um Empacotador de AppImage"
"Baseado no Conteiner Junest Criado para Empacotar"
"AppImage com a Inclusão do 'GLibC'."
" "
"O objetivo é a Criação de AppImage Compatível"
"com a Maioria das Distros Linux e Facilidade na"
"Portabilidade de Programas para AppImage."
)
t2=( "[ENTER] Continuar [ C ] Configurações [ESC] Sair" )
sub=4
add=5
test $(( rows % 2 )) -eq 1 && {
sub=3
add=6
}
_center_text "${text[*]// /_}" 0 $sub
_center_text "${t2[*]// /_}" $add
tput rc
read -n 1 -s -r key
printf "$rst"
clear
case "$key" in
"C"|"c")
__config
;;
$'\x1b')
exit 0
;;
*)
__new_appimage
;;
esac
}
clear
while :; do
__main
done
exit 0