-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathsalt.func
2376 lines (2061 loc) · 108 KB
/
salt.func
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
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
##########################################################################
## @file salt.func
## @brief The heart of SALT - all global functions
## @author steadfasterX <steadfasterX -AT- gmail -DOT- com>
## @date 2017-2023
## @copyright LGPL v3
## @details SALT - [S]teadfasterX [A]ll-in-one [L]G [T]ool
##
## global functions for SALT
##
## include this with:
## source salt.func
#
##########################################################################
# doxygen copy templates:
#
# # @var
# # @brief
# # @showinitializer
# # @details
#
# # @fn F_NAME()
# # @brief ..
# # @param 1 ..
# # @return ..
# # @exception ..
# # @details ..
#
##########################################################################
VARS="${0%/*}/salt.vars"
export HASHES="${0%/*}/salt.hashes"
source "$VARS"
[ $? -ne 0 ]&& echo "ERROR: including $VARS" && exit 3
source "$HASHES"
[ $? -ne 0 ]&& echo "ERROR: including $HASHES" && exit 3
# set CR arg
case $CRMODE in
yes) export CROPT="--cr yes";;
no) export CROPT="--cr no";;
*) export CROPT="";;
esac
######################################################################################
# there is no need to change these as they get auto set by the VERSION var
if [ "${VERSION/*:}" == "STREAM" ];then
export VCHK="https://raw.githubusercontent.com/steadfasterX/SALT/develop/salt.vars"
else
export VCHK="https://raw.githubusercontent.com/steadfasterX/SALT/master/salt.vars"
fi
######################################################################################
# do not echo but write log entry
F_LOG(){
# takes 1 argument
# 1 => Message to log/echo (can handle \t and \n)
echo -e "$(date '+%F %T'): $1" >> $LOG
}; export -f F_LOG
# echo output and save it in a log as well
F_ELOG(){
# takes 1 argument
# 1 => Message to log/echo (can handle \t and \n)
echo -e "$(date '+%F %T'): $1" | tee -a $LOG
}; export -f F_ELOG
######################################################################################
F_LOG "CR setting: $CRMODE = $CROPT"
######################################################################################
# print a message
F_MSG(){ F_LOG "$FUNCNAME: started"
# takes 2 arguments
#
# 1 => box width
# 2 => message to show
# optional:
# 3 => free args
$FYAD --width=$1 --title="$YTITLE" --text "$2" $3
RET=$?
F_LOG "$2"
F_LOG "$FUNCNAME: ended"
echo $RET
}; export -f F_MSG
# print an error message
F_MSGE(){ F_LOG "$FUNCNAME: started"
# takes up to 3 arguments
#
# 1 => width
# 2 => message
#
# optional:
# 3 => yad stuff
$FYAD --width="$1" --title="$YTITLE - ERROR" --image="$SICONS/error.png" --text "ERROR:\n\n$2" $3 --button=Exit:0
RES=$?
F_LOG "ERROR: $2"
F_LOG $RES
echo $RES
}; export -f F_MSGE
# print an OK message
F_MSGOK(){ F_LOG "$FUNCNAME: started"
# takes up to 3 arguments
#
# 1 => width
# 2 => message
#
# optional:
# 3 => yad stuff
$FYAD --width="$1" --title="$YTITLE - SUCCESS" --image="$SICONS/ok_64x64.png" --text "\n$2" $3 --button=Close:0
RES=$?
F_LOG "$2"
F_LOG $RES
echo $RES
}; export -f F_MSGOK
# print a warning message
F_MSGW(){ F_LOG "$FUNCNAME: started"
# takes up to 3 arguments
#
# 1 => width
# 2 => message
#
# optional:
# 3 => yad stuff
$FYAD --width="$1" --title="$YTITLE - WARNING" --image="$SICONS/warning_64x64.png" --text "\n$2" $3 --button=Close:0
RES=$?
F_LOG "$2"
F_LOG $RES
echo $RES
}; export -f F_MSGW
# check errorcode + exit when not errorcode not as expected
F_ERR(){ F_LOG "$FUNCNAME: started"
# takes 2-4 arguments
#
# mandantory:
# 1 => the process initiating this function
# 2 => the errorcode (usually $? in your call)
# optional (4 requires at least an empty 3):
# 3 => the message to show
# 4 => the expected error code (if missing we expect 0)
# 5 => yad code for F_MSGE (requires at least emtpy 3 and 4)
CALLER=$1
ERRCODE=$2
MSG="$3"
EXPECTED=$4
YADSTUFF="$5"
[ -z "$EXPECTED" ] && EXPECTED=0
if [ -z "$CALLER" ]||[ -z "$ERRCODE" ];then
F_ELOG "Required argument missing in $FUNCNAME!"
F_EXIT $FUNCNAME 3
fi
if [ "$ERRCODE" != "$EXPECTED" ];then
F_ELOG "ERROR: $ERRCODE occurred in $CALLER (expected $EXPECTED, got $ERRCODE)"
[ ! -z "$MSG" ] && F_MSGE 800 "$MSG" "$YADSTUFF"
F_EXIT "${CALLER}->${FUNCNAME}" 4
else
echo "OK: $CALLER"
fi
}; export -f F_ERR
# exit properly
F_EXIT(){ F_LOG "$FUNCNAME: started"
# takes 3 arguments
# mandantory:
# 1 => the function or reason who calls the exit function
# 2 => the exitcode to be used
#
# optional:
# 3 => type: cleaning lock file (full) or just close (when not set)
EREASON=$1
ECODE=$2
ETYPE=$3
F_ELOG "EXIT: $EREASON with code $ECODE"
[ "$ETYPE" == "full" ] && rm -vf $LOCKFILE >> $LOG
exit $ECODE
F_LOG "$FUNCNAME: ended"
}; export -f F_EXIT
# detects the type of device storage
F_DETSTORAGE(){ F_LOG "$FUNCNAME: started"
echo coming soon
}; export -f F_DETSTORAGE
# get current phone data
F_GETINFO(){ F_LOG "$FUNCNAME: started"
# takes no arguments
$FYAD --title="$YTITLE - COLLECTING" --text "\n Collecting device information..." --width=400 --timeout=25 --timeout-indicator=right --no-buttons &
PBPP=$!
IARB=$(F_CDARB)
F_LOG "$FUNCNAME: ARB $IARB"
USU=$(F_CKUSU)
F_LOG "$FUNCNAME: USU $USU"
ROMCOMP=$(F_ROMCOMP)
F_LOG "$FUNCNAME: ROMCOMP $ROMCOMP"
LAFVER=$(F_CHKLAFV)
F_LOG "$FUNCNAME: LAFVER $LAFVER"
# reconnecting too fast will cause timeouts
sleep 1
echo "usu:${USU}" \
&& echo "romcomp:$ROMCOMP" \
&& echo "arb:${IARB}" \
&& echo "lafver:$LAFVER" \
&& $PYTHONBIN $LAFPATH/lglaf.py $LAFARGS ${CROPT} -c '!INFO GPRO \x08\x0b\0\0' --rawshell \
| $PYTHONBIN $LAFPATH/scripts/parse-props.py - \
| $EGREPBIN "(device_sw_version|model_name|secure_device|laf_sw_version|device_factory_version|target_country|battery_level|imei|target_operator|serial)" | tr "\n" " " | tr -d "'"
F_LOG "$FUNCNAME: $(kill $PBPP)"
F_LOG "$FUNCNAME: ended"
}; export -f F_GETINFO
# checks which ROM type is compatible with UsU on that device
F_ROMCOMP(){ F_LOG "$FUNCNAME: started"
# takes no arg
DEVTMO=$($PYTHONBIN $LAFPATH/partitions.py $LAFARGS ${CROPT} --list 2>&1 | grep -c carrier | $TEEBIN -a $LOG)
DEVEUR=$($PYTHONBIN $LAFPATH/partitions.py $LAFARGS ${CROPT} --list 2>&1 | grep -c cust | $TEEBIN -a $LOG)
F_LOG "UsU compatibility: $DEVTMO (0=h815, 1=h811)"
if [ "$DEVTMO" == "1" ];then
echo "H811"
elif [ "$DEVEUR" == "1" ];then
echo "H815"
else
echo "unknown"
F_LOG "UsU compatibility: cannot be detected! full GPT:"
$PYTHONBIN $LAFPATH/partitions.py $LAFARGS ${CROPT} --list 2>&1 | $TEEBIN -a $LOG
fi
}; export -f F_ROMCOMP
# check the ARB of a KDZ file
F_KDZARB(){ F_LOG "$FUNCNAME: started with $@"
# takes 2 args, returns ARB value found
#
# 1 => full path to kdz file
# 2 => full extract path
LGKDZ="$1"
LGTARGET="$2"
[ -z "$LGKDZ" -o ! -f "$LGKDZ" ] && F_ERR $FUNCNAME 3 "Internal error: empty LGKDZ or file not found"
[ -z "$LGTARGET" -o ! -d "$LGTARGET" ] && F_ERR $FUNCNAME 3 "Internal error: empty LGTARGET or directory not found"
F_LOG "$FUNCNAME: cleanup.."
find "$LGTARGET" -type f -maxdepth 1 -name 'sbl*' -or -name 'xbl*' -exec rm -vf {}\\; >> $LOG 2>&1
IRES=$($KDZMGR --batch --list -x "$LGKDZ" -d "$LGTARGET" 2>&1)
ARBSLICE=$(echo "$IRES" |$EGREPBIN "sbl|xbl"|head -n1|cut -d ":" -f 1)
if [ -z "$ARBSLICE" ];then
F_LOG "$FUNCNAME: no ARB or slice found >$ARBSLICE< .. skipping ARB detection .."
echo "arb-detect-error"
else
F_LOG "$FUNCNAME: found ARB in slice >$ARBSLICE< .. extracting.."
# extract ARB slice
$KDZMGR --batch -x "$LGKDZ" -d "$LGTARGET" --slice "$ARBSLICE" >> $LOG 2>&1
ARBFILE=$(find "${LGTARGET}/extracteddz" -type f -maxdepth 1 -name 'sbl*' -or -name 'xbl*')
F_LOG "$FUNCNAME: ARBFILE = $ARBFILE"
# get and print the ARB
F_CKARB "$ARBFILE"
fi
}; export -f F_KDZARB
# extract a KDZ
F_EXTRACTKDZ(){ F_LOG "$FUNCNAME: started with $@"
# takes 2-3 arguments
#
# required:
# 1 => KDZ file name (full path)
# 2 => Target directory
# optional:
# 3 => auto mode (e.g. for KDZ flashing)
LGKDZ="$1"
LGTARGET="$2"
AUTOM="$3"
[ -z "$LGKDZ" -o ! -f "$LGKDZ" ] && F_ERR $FUNCNAME 3 "Internal error: empty LGKDZ or file not found"
[ -z "$LGTARGET" -o ! -d "$LGTARGET" ] && F_ERR $FUNCNAME 3 "Internal error: empty LGTARGET or directory not found"
# ensure the target dir does not contain old image files
[ "${LGTARGET}/extracteddz" ] && rm -rf "${LGTARGET}/extracteddz"
[ "${LGTARGET}/extractekdz" ] && rm -rf "${LGTARGET}/extractedkdz"
# open yad listener
echo 0> /tmp/${FUNCNAME}_l
tail -f /tmp/${FUNCNAME}_l | $FYAD --title="$YTITLE - COLLECT" --text="\n" --progress-text="Collecting KDZ information ..." --width=400 --progress --pulsate --no-buttons &
echo 1 >> /tmp/${FUNCNAME}_l
tail_pid=$!
# grab the partition list
IRES=$($KDZMGR --batch --list -x "$LGKDZ" -d "$LGTARGET" 2>&1)
IRESDATA=$(echo -e "$IRES" |grep ":data" | sort -t : -k 2)
IRESEMPTY=$(echo -e "$IRES" |grep ":empty" | sort -t : -k 2)
# grab the ARB of the KDZ
KDZARB=$(F_KDZARB "$LGKDZ" "$LGTARGET")
# close yad listener
kill $tail_pid
rm /tmp/${FUNCNAME}_l
# build the extract list based on the UsU state
case "$LGUSU" in
yes) IRESAUTO=$(echo -e "$IRESDATA" | $EGREPBIN -iv "($AUTONOEXTRACTUSU)")
;;
no|no_device_found) IRESAUTO=$(echo -e "$IRESDATA" | $EGREPBIN -iv "($AUTONOEXTRACT)")
;;
*) kill $tail_pid
rm /tmp/${FUNCNAME}_l
F_MSGE 500 "Unexpected LGUSU result ($LGUSU).. "
F_EXIT "$FUNCNAME: Cannot determine UsU state" 3
;;
esac
F_LOG "collected data:\nUsU: $LGUSU\nIRESDATA:\n$IRESDATA\nIRESEMPTY:\n$IRESEMPTY\nIRESAUTO:\n$IRESAUTO"
F_LOG "$FUNCNAME: $(kill $PBPP)"
if [ x"$AUTOM" == "xauto" ];then
CHOOSENP=$(echo -e "$IRESAUTO"| cut -d ":" -f 1-2)
else
IRESSORTED=$(echo -e "$IRESDATA\n$IRESEMPTY")
BTNRET=66
while [ "$BTNRET" -eq 77 -o "$BTNRET" -eq 66 ];do
if [ "$BTNRET" == 66 ];then
FCHOOSENP=$(for slice in $IRESSORTED;do if [ "${slice/*:/}" == "data" ];then echo -e "true:$slice"; else echo -e "false:$slice";fi | tr ':' '\n' ;done \
| $FYAD --height=800 --width=1000 --title="$YTITLE - EXTRACT" \
--text "\n This KDZ has an <a href='https://forum.xda-developers.com/t/closed-unlock-poc-ls991-h81x-vs986-f500-unofficial-unlock-poc.3648288/#post-73206763'>ARB</a> of: <span color='#ff0000' size='large'><b>$KDZARB</b></span>\n\n Select partition(s) to EXTRACT:\n"\
--list --checklist \
--column="Selection":CHK \
--column="#" \
--column="Partition":TXT \
--column="Type" \
--listen --no-selection \
--button="Deselect All":77 \
--button=Extract:0 \
--button=Abort:3)
BTNRET="${PIPESTATUS[0]}"
CHOOSENP=$(echo "$FCHOOSENP" | cut -d "|" -f 2,3 | tr "|" ":"| tr "\n" " ")
F_LOG "$FUNCNAME BTNRET: $BTNRET"
else
if [ "$BTNRET" == 77 ];then
FCHOOSENP=$(for slice in $IRESSORTED;do if [ "${slice/*:/}" == "data" ];then echo -e "false:$slice"; else echo -e "false:$slice";fi | tr ':' '\n' ;done \
| $FYAD --height=800 --width=1000 --title="$YTITLE - EXTRACT" \
--text "\n This KDZ has an <a href='https://forum.xda-developers.com/t/closed-unlock-poc-ls991-h81x-vs986-f500-unofficial-unlock-poc.3648288/#post-73206763'>ARB</a> of: <span color='#ff0000' size='large'><b>$KDZARB</b></span>\n\n Select partition(s) to EXTRACT:\n"\
--list --checklist \
--column="Selection":CHK \
--column="#" \
--column="Partition":TXT \
--column="Type" \
--listen --no-selection \
--button="Select All (with data)":66 \
--button=Extract:0 \
--button=Abort:3)
BTNRET="${PIPESTATUS[0]}"
CHOOSENP=$(echo "$FCHOOSENP" | cut -d "|" -f 2,3 | tr "|" ":"| tr "\n" " ")
F_LOG "$FUNCNAME BTNRET: $BTNRET"
else
break
fi
fi
done
fi
F_LOG "CHOOSENP: $CHOOSENP"
CHCOUNT=$(echo "$CHOOSENP" |tr " " "\n" |grep -c :)
[ $CHCOUNT -lt 1 ] && F_MSGE 700 "No partition selected or aborted by user" && F_EXIT $FUNCNAME $CHCOUNT
F_ELOG "choosen partitions: $CHOOSENP -> $CHCOUNT"
# open yad listener
echo 0> /tmp/e
tail -f /tmp/e | $FYAD --title="$YTITLE - EXTRACT" --text="\n <b>SALT is now extracting ...</b>\n (just wait until this dialog closes)\n" --width=900 --progress --button='Close (WAIT until FINISHED)':0 --auto-close &
tail_pid=$!
MGRARGS=
for slice in $CHOOSENP;do
CNT=$((CNT+1))
slicename=${slice/*:/}
slicenum=${slice/:*/}
echo "#extracting ${slicename} ..." >>/tmp/e
[ $CNT -ne $CHCOUNT ] && MGRARGS="-D"
$KDZMGR --batch -x "$LGKDZ" -d "$LGTARGET" --slice $slicenum --with-cache --with-userdata $MGRARGS >> $LOG 2>&1
CNTPERC=$(($CNT * 100 / $CHCOUNT))
echo $CNTPERC >>/tmp/e
[ $CNT -eq $CHCOUNT ] && echo '# FINISHED!' >>/tmp/e && F_LOG "$FUNCNAME: Extract finished"
done
EXERR=$?
# cleanup dz (but leave the dlls)
rm -fv "$LGTARGET/extractedkdz/*.dz" >> $LOG
# ensure regular users can work with the extracted stuff
if [ "$LGTARGET" != "/tmp" ] && [ "$LGTARGET" != "/" ];then
chown -Rv ${REALUSER} "$LGTARGET" >> $LOG
else
chown -Rv ${REALUSER} "$LGTARGET/extractedkdz" "$LGTARGET/extracteddz" >> $LOG
fi
# close yad listener
kill $tail_pid
if [ $EXERR -ne 0 ];then
F_ERR $FUNCNAME $EXERR "ERROR occured or aborted by user!"
else
[ x"$AUTOM" != "xauto" ] && $FYAD --width="500" --title="$YTITLE - SUCCESS" --image="$SICONS/ok_64x64.png" --text "\nAll partitions extracted!\n" \
--button='Open target folder':"xdg-open '$LGTARGET/extracteddz'" \
--button='Mount an image':"bash -c 'F_MOUNTPARTS $LGTARGET/extracteddz'" \
--button=Close:0
fi
F_LOG "$FUNCNAME: ended"
}; export -f F_EXTRACTKDZ
# check device for for antirollback bullshit (I'm still pissed off that a vendor is doing this! I mean HARDBRICK a phone ?? wtf LG?)
F_CDARB(){ F_LOG "$FUNCNAME: started"
# takes no arguments
# returns: <ARB>:<detection-success>
DEVARBEMPTY=0
PDARB=$($PYTHONBIN $LAFPATH/partitions.py $LAFARGS ${CROPT} --batch --list | $EGREPBIN "($PARB)" | head -n 1 | cut -d ":" -f1)
F_LOG "$FUNCNAME: ARB partition seems to be: $PDARB"
DEVARB=$($PYTHONBIN $LAFPATH/partitions.py $LAFARGS ${CROPT} --batch --dump - $PDARB 2>> $LOG| strings | $EGREPBIN "[0-9] SW_ID" |cut -d " " -f 2 | head -n 1 | sed -E 's/([0-9]{7,7})([0-9]{2,2}).*/\2/g;s/^0//g')
# normalize ARB
case $DEVARB in
[1-9]0) DETARB=$DEVARB; DEVARB=${DEVARB/0/} ; F_LOG "$FUNCNAME: normalized ARB from $DETARB to $DEVARB" ;;
esac
[ -z "$DEVARB" ] && DEVARB="0" && DEVARBEMPTY=1 && F_LOG "EMPTY ARB DETECTED:\n$($PYTHONBIN $LAFPATH/partitions.py $LAFARGS ${CROPT} --batch --dump /tmp/${PDARB}.err $PDARB && strings /tmp/${PDARB}.err | grep -C 1 SW_ID 2>&1)" && F_LOG "Please send this log and the $PDARB dump in /tmp/${PDARB}.err" && F_LOG "$($PYTHONBIN $LAFPATH/partitions.py $LAFARGS ${CROPT} --list --debug 2>&1)" && F_LOG "$(lsusb -v)"
[ "$DEVARB" == "zero" ] && DEVARB=0 && F_LOG "ARB valid and 0"
F_LOG "$FUNCNAME: DEVARB=$DEVARB, DEVARBEMPTY=$DEVARBEMPTY"
echo "${DEVARB}:${DEVARBEMPTY}"
F_LOG "$FUNCNAME: ended"
}; export -f F_CDARB
# dumps a single partition
F_DUMPPART(){ F_LOG "$FUNCNAME: started with $@"
# takes 2 args
#
# 1 => partition name
# 2 => path to store
[ -z $1 -o -z $2 ] && F_EXIT "$FUNCNAME missing args!" 3
PNAME=$1
BPTH="$2"
BFL="${BPTH}/${PNAME}"
[ ! -d "$BPTH" ] && mkdir -p "$BPTH"
$PYTHONBIN $LAFPATH/partitions.py $LAFARGS ${CROPT} --batch --dump $BFL $PNAME | $TEEBIN -a $LOG
}; export -f F_DUMPPART
# check for the UsU Unlock (G4 only)
F_CKUSU(){ F_LOG "$FUNCNAME: started"
# takes no arguments
#
(F_DUMPPART aboot $USUTMPDIR/check 2>&1) >> $LOG
REMAB=$(sha256sum $USUTMPDIR/check/aboot | cut -d " " -f1)
USUDET=0
[ "$USUHASH" == "$REMAB" ] && USUDET=1
F_LOG "$FUNCNAME: USU=$USUDET (1=yes, 0=no)"
unset USUMNM
[ $USUDET == 1 ] && USUMNM="$(F_USUMODEL)"
echo "${USUDET}:${USUMNM}"
F_LOG "$FUNCNAME: ended"
}; export -f F_CKUSU
# check for the real modelname when UsU
F_USUMODEL(){ F_LOG "$FUNCNAME: started"
# takes no arguments
#
(F_DUMPPART raw_resources $USUTMPDIR 2>&1) >> $LOG
REMRR=$(dd if=$USUTMPDIR/raw_resources skip=3145722 count=6 bs=1 2>>/dev/null | strings)
F_LOG "$FUNCNAME: RR based USUMODEL=$REMRR"
echo "${REMRR}"
F_LOG "$FUNCNAME: ended"
}; export -f F_USUMODEL
# check local file for antirollback bullshit
# (I'm still pissed off that LG is REALLY doing this! I mean HARDBRICK a phone ?? wtf LG? Its MY decision if I wanna use an outdated/insecure ROM version!)
F_CKARB(){ F_LOG "$FUNCNAME: started"
# takes 1 argument
#
# 1 => full path to the file to check
ARBFILE="$1"
if [ ! -f "$ARBFILE" ];then
F_MSGE 700 "Missing required file to check for ARB\n (checked this filename: $ARBFILE)!"
echo "arb-detect-error"
else
KDZARB=$(strings "$ARBFILE" | $EGREPBIN "[0-9] SW_ID" |cut -d " " -f 2 | head -n 1 | sed -E 's/([0-9]{7,7})([0-9]{2,2}).*/\2/g;s/^0//g')
# normalize ARB
case $KDZARB in
[1-9]0) DETARB=$KDZARB; KDZARB=${KDZARB/0/} ; F_LOG "$FUNCNAME: normalized ARB from $DETARB to $KDZARB" ;;
esac
[ -z "$KDZARB" ] && KDZARB=0
F_LOG "KDZARB=$KDZARB"
echo $KDZARB
fi
F_LOG "$FUNCNAME: ended"
}; export -f F_CKARB
# check device model
F_CHKMODEL(){ F_LOG "$FUNCNAME: started"
# takes 1 argument
# returns <connected-model>:<file-model>
#
# 1 => image/kdz file to compare
KFILE="$1"
[ -z "$KFILE" -o ! -f "$KFILE" ] && F_ERR $FUNCNAME 3 "\n ERROR!\n\n KFILE missing for compare!"
DEVINF=$(F_GETINFO)
for i in $DEVINF;do
case ${i/:*/} in
model_name) LGMODEL=${i/*:/};;
esac
done
KDZMODEL=$(dd if=$KFILE bs=512 count=10000 2>&1| strings | $EGREPBIN -m1 -o '(LGLS[0-9]{3})|(LGVS[0-9]{3})|(LG-[H|F][0-9]{3})')
if [ -z "$KDZMODEL" ] ;then
RES="${LGMODEL}:unknown"
else
RES="${LGMODEL}:${KDZMODEL}"
fi
F_LOG "$FUNCNAME: $RES"
echo $RES
F_LOG "$FUNCNAME: ended"
} ; export -f F_CHKMODEL
# checks if UsU variable is readable and set correctly
F_USUVARVALID(){ F_LOG "$FUNCNAME: started"
if [ "$LGUSU" == "yes" -o "$LGUSU" == "no" ];then echo 1; else echo 0; fi
} ; export -f F_USUVARVALID
# verify device ARB and model results against folder / files ARB and model
# returns returncode of users choice or errors
F_VERIFYDARB(){
F_LOG "$FUNCNAME: started with $@"
IMGDIR="$1"
CHKMRES=unknown
# check device model of the given files
DFIL=$(find "$IMGDIR" -name 'misc.*' | head -n 1 | grep misc \
|| find "$IMGDIR" -name 'aboot*' | head -n 1 | grep aboot \
|| find "$IMGDIR" -name 'mpt*' | head -n 1 | grep mpt \
|| echo ERROR)
[ "$DFIL" != "ERROR" ] && F_LOG "$FUNCNAME: Will use $DFIL for model check" && CHKMRES=$(F_CHKMODEL "$DFIL")
# check ARB
ARBOK=0
AFIL=$(find "$IMGDIR" -name 'sbl1.*' | head -n 1 | grep sbl1 \
|| find "$IMGDIR" -name 'rpm*' | head -n 1 | grep rpm \
|| find "$IMGDIR" -name 'tz*' | head -n 1 | grep tz \
|| find "$IMGDIR" -name 'aboot*' | head -n 1 | grep aboot \
|| echo ERROR)
[ "$AFIL" != "ERROR" ] && F_LOG "$FUNCNAME: Will use $AFIL for ARB check" && KARB=$(F_CKARB "$AFIL")
ARBOK=0
DARB=$(F_CDARB)
F_LOG "$FUNCNAME: KARB: $KARB, DARB: $DARB, \nCHKMRES: ${CHKMRES/*:} VS. ${CHKMRES/:*}"
# verify the internal functions do not generate crap
[ -z "$KARB" -o -z "$DARB" ] && F_ERR $FUNCNAME 3 "\n ERROR!\n\n Device ARB or file-based ARB cannot be checked! ABORTED!!"
# verify ARB
[ "$KARB" -eq "${DARB/:*}" ] && ARBOK=1 && ARBINC=0 && F_LOG "$FUNCNAME: ARB is equal between files and device"
[ "$KARB" -gt "${DARB/:*}" ] && ARBOK=1 && ARBINC=1 && F_MSGW 800 "\n!!! WARNING !!!\n\nChosen files have a higher ARB level then your current device. Depending on the files you flash (e.g. bootloader) your ARB will be increased!\n\nThat means you can <b>never</b> rollback to a previous versions once flashed!\n\nRead more about ARB here:\n\n<a href='https://forum.xda-developers.com/t/closed-unlock-poc-ls991-h81x-vs986-f500-unofficial-unlock-poc.3648288/#post-73206763'>ARB explained</a>" >> /dev/null 2>&1
[ "$KARB" -lt "${DARB/:*}" ] && ARBOK=0 && ARBINC=0 && F_MSGE 800 "The ARB of the files you are trying to flash is LOWER then your device!!! ABORTED!\n\nRead more about ARB here:\n\n<a href='https://forum.xda-developers.com/t/closed-unlock-poc-ls991-h81x-vs986-f500-unofficial-unlock-poc.3648288/#post-73206763'>ARB explained</a>" && F_EXIT "$FUNCNAME too low ARB" 3
# a bulletproof method to avoid issues with any of the above (e.g. when KARB or DARB are not digits etc)
[ "$ARBOK" -ne 1 ] && F_MSGE 500 "Issues regarding determining ARB! ABORTED!" && F_EXIT "$FUNCNAME: ARB check failed" 4
# manual ARB verification by the user
if [ -z "${CHKMRES/*:}" ] || [ -z "${CHKMRES/:*}" ]|| [ "${CHKMRES/:*}" == "unknown" ] || [ "${CHKMRES/*:}" != "${CHKMRES/:*}" ];then
F_LOG "$FUNCNAME: file and device model does not match!!!"
F_MSGW 800 "<b><span color='#ff0000'>!!! WARNING !!! File and device model does not match!</span></b>\n\nDevice model:\t\t${CHKMRES/:*}\nFiles are for:\t\t${CHKMRES/*:}\n\nARB of your device compared with the files\nDevice:\t${DARB/:*}\nFiles:\t$KARB\n\nYou can doublecheck some known ARB <a href='https://forum.xda-developers.com/t/closed-unlock-poc-ls991-h81x-vs986-f500-unofficial-unlock-poc.3648288/#post-73206763'>here</a>\n\nDo you really want to continue and so FLASHing now?" "--button=Continue-may-HARDBRICK:99"
else
F_LOG "$FUNCNAME: file and device model does match"
F_MSGOK 800 "<b>file and device</b> information match\nDevice model:\t${CHKMRES/:*}\nFiles are for:\t\t${CHKMRES/*:}\n\nARB of your device compared with the files\nDevice:\t${DARB/:*}\nFiles:\t$KARB\nYou can doublecheck some known ARB <a href='https://forum.xda-developers.com/t/closed-unlock-poc-ls991-h81x-vs986-f500-unofficial-unlock-poc.3648288/#post-73206763'>here</a>\n\n Do you really want to continue and so FLASHing now?" "--button=Continue:99"
fi
}; export -f F_VERIFYDARB
# flash a KDZ
F_FLASHKDZ(){ F_LOG "$FUNCNAME: started"
# takes 5 arguments
#
# 1 => KDZ filename
# 2 => Factory reset
# 3 => Model check
# 4 => ARB check
# 5 => test mode
LGKDZ="$1"
LGFR="$2"
LGCHKMOD="$3"
LGARB="$4"
LGDRY="$5"
# autoextract kdz without userdata and cache
KDZTMP=/tmp
F_EXTRACTKDZ "$LGKDZ" "$KDZTMP" auto
# test mode?
if [ "$LGDRY" != "FALSE" ];then
($KDZMGR --batch --flash "$KDZTMP/extracteddz" --test 2>&1) | tee -a $LOG | $FYAD --title="$YTITLE - FLASH" --text-info --text "\n <b><span color='#009900'>FLASHING KDZ (TEST)...</span></b>\n" --listen --tail --height=600 --width=900 --wrap --fore=blue --button="Next":0
$FYAD --title="$YTITLE - FLASH" --text "\n TEST run finished\n\n Do you want to continue to FLASH in REAL now?" --button=FLASH:1 --button=Cancel:0
[ $? -ne 1 ] && echo canceling.. && F_EXIT $FUNCNAME $?
fi
# check device connection
F_CHKDEVCON
# that one is required for flashing (the device must be connected and UsU state must be detected!)
VARSET=$(F_USUVARVALID)
if [ "$VARSET" -eq 0 ];then F_MSGE 500 "ERROR: Cannot determine UsU state?! aborted.."; F_EXIT "$FUNCNAME" 3; fi
# recheck valid image files
# TODO
# verify ARB and model
RET=$(F_VERIFYDARB "$KDZTMP/extracteddz")
# abort when needed
[ "$RET" != "99" ] && F_ERR $FUNCNAME 3 "\n Aborted on user check verification"
# abort when needed
[ $? -ne 0 ] && F_ERR $FUNCNAME 3 "\n Aborted on user check verification"
# If all the above is fine: FLASH
F_FLASHPART "$KDZTMP/extracteddz" auto
# factory reset to avoid bootloop (cache gets deleted by FLASHPART already)
# TODO: accept the taken user choice
# DISABLED as WIPEPART will just clear the partition and do not FORMAT it (will produce bootloops etc)
#F_WIPEPART userdata ni
F_MSG 600 " KDZ flashing completed.\n Check the log for details (Advanced Menu)"
F_LOG "$FUNCNAME: ended"
}; export -f F_FLASHKDZ
# choose and flash partitions from a backup or extracted KDZ
F_FLASHPART(){ F_LOG "$FUNCNAME: started"
# takes 1 optional argument
#
# 1 => image files path
LGUSUOVERRIDE=false
if [ -z "$1" ];then
AIMGDIR=$($FYAD --width=600 --title="$YTITLE - FOLDER" --form \
--field=" Select the source folder":DIR \
--field=" UsU override\n (will allow flashing of all partitions on UsU devices - leave unchecked if unsure!)":CHK \
$REALHOME \
$LGUSUOVERRIDE)
IMGDIR=$(echo $AIMGDIR|cut -d '|' -f1)
LGUSUOVERRIDE=$(echo $AIMGDIR|cut -d '|' -f2)
else
IMGDIR="$1"
fi
F_LOG "$FUNCNAME: IMGDIR=$IMGDIR"
[ ! -d "$IMGDIR" ] && F_ERR $FUNCNAME 3 "\n ERROR!\n\n Folder \n\n $IMGDIR\n\n does not exists?!"
# check device connection
F_CHKDEVCON
VARSET=$(F_USUVARVALID)
if [ "$VARSET" -eq 0 ];then F_MSGE 500 "ERROR: Cannot determine UsU state?! aborted.."; F_EXIT "$FUNCNAME" 3; fi
# create a list of *.image files
if [ "$LGUSU" == "yes" ] && [ "$LGUSUOVERRIDE" == "false" -o "$LGUSUOVERRIDE" == "FALSE" ];then
F_LOG "$FUNCNAME: UsU detected so will not display UsU relevant files (USUOVERRIDE=$LGUSUOVERRIDE)"
IMGFILES=$(for ifile in $(find "$IMGDIR" -maxdepth 1 -type f -name '*.bin' -or -name '*.img' -or -name '*.image' -or -name '*.mbn' | tr " " "_" |$EGREPBIN -vi "($FLASHIGNOREUSU)");do echo "${ifile##*/}";done | tr "\n" " ")
else
F_LOG "$FUNCNAME: will display all files (USUOVERRIDE=$LGUSUOVERRIDE)"
IMGFILES=$(for ifile in $(find "$IMGDIR" -maxdepth 1 -type f -name '*.bin' -or -name '*.img' -or -name '*.image' -or -name '*.mbn' | tr " " "_" |$EGREPBIN -vi "($FLASHIGNORE)");do echo "${ifile##*/}";done | tr "\n" " ")
fi
F_LOG "$FUNCNAME: image files: $IMGFILES"
# give proper default choice for what to flash and what not
shopt -s extglob
unset IRES
for f in $IMGFILES;do
AVIMG="${f/:*}"
APART=$(echo "${f/*:}" | sed -e 's/\.image//g;s/\.img//g;s/\.bin//g;s/\.mbn//g;s/mmcblk0p\(.*\)/\1/g')
case $APART in
${PUNNEEDED})
if [ -z "$IRES" ];then IRES="false\n${AVIMG}\n${APART}\nunneeded\n99"; else IRES="$IRES false\n${AVIMG}\n${APART}\nunneeded\n99" ;fi
;;
${PBOOTL})
if [ -z "$IRES" ];then
IRES="true\n${AVIMG}\n${APART}</span>\n<span\tcolor='#ff0000'>bootloader</span>\n1"
else
IRES="$IRES true\n${AVIMG}\n${APART}\n<span\tcolor='#ff0000'>bootloader</span>\n1"
fi
;;
${PDEVICE})
# dangerous partitions contain device specific stuff, e.g. your IMEI and will not get written by a regular KDZ flash!
if [ -z "$IRES" ];then
IRES="false\n${AVIMG}\n${APART}</span>\n<span\tcolor='#ff0000'>dangerous</span>\n88"
else
IRES="$IRES false\n${AVIMG}\n${APART}\n<span\tcolor='#ff0000'>dangerous</span>\n88"
fi
;;
${PSYSTEM})
if [ -z "$IRES" ];then
IRES="true\n${AVIMG}\n${APART}\n<span\tcolor='#558000'>safe-to-flash</span>\n2"
else
IRES="$IRES true\n${AVIMG}\n${APART}\n<span\tcolor='#558000'>safe-to-flash</span>\n2"
fi
;;
*)
if [ -z "$IRES" ];then
IRES="true\n${AVIMG}\n${APART}\nunknown-type\n2"
else
IRES="$IRES true\n${AVIMG}\n${APART}\nunknown-type\n2"
fi
;;
esac
done
F_LOG "$FUNCNAME: created yad list: $IRES"
BTNRET=66
while [ "$BTNRET" -eq 77 -o "$BTNRET" -eq 66 ];do
if [ "$BTNRET" == 66 ];then
FCHOOSENP=$(for files in $IRES;do echo -e "$files" ;done \
| $FYAD --height=800 --width=700 --title="$YTITLE - FOLDER" --text "\n Select the partitions you want to flash\n (the RECOMMENDED partitions to flash are CHECKED already!)\n\n\t<i>bootloader:</i>\t\twhen flashing ensure you select <b>ALL</b> parts of it - otherwise hard brick\n\t<i>dangerous:</i>\t\tcan reset unlocked devices, loosing IMEI etc!\n\t<i>unknown-type:</i>\tmeaning of that partition is unknown, use with care!\n\n Hint: you can change the target partition by a double click - but do this only when you\n <b>REALLY</b> know what you're doing!\n" \
--list --checklist \
--column="Flash":CHK \
--column="Image File":TXT \
--column="Target partition" \
--column="Type" \
--editable \
--editable-cols="3" \
--column=sort_int \
--hide-column=5 \
--listen \
--button="Deselect All":77 \
--button=FLASH:0 \
--button=Abort:99 )
BTNRET="${PIPESTATUS[0]}"
CHOOSENP=$(echo "$FCHOOSENP" | cut -d "|" -f 2-5 | tr "|" ":" | tr "\n" " ")
F_LOG "$FUNCNAME BTNRET: $BTNRET"
else
if [ "$BTNRET" == 77 ];then
FCHOOSENP=$(for files in $IRES;do echo -e "${files/true/false}" ;done \
| $FYAD --height=800 --width=700 --title="$YTITLE - FOLDER" --text "\n Select the partitions you want to flash\n (the RECOMMENDED partitions to flash are CHECKED already!)\n\n\t<i>bootloader:</i>\t\twhen flashing ensure you select <b>ALL</b> parts of it - otherwise hard brick\n\t<i>dangerous:</i>\t\tcan reset unlocked devices, loosing IMEI etc!\n\t<i>unknown-type:</i>\tmeaning of that partition is unknown, use with care!\n\n Hint: you can change the target partition by a double click - but do this only when you\n <b>REALLY</b> know what you're doing!\n" \
--list --checklist \
--column="Flash":CHK \
--column="Image File":TXT \
--column="Target partition" \
--column="Type" \
--editable \
--editable-cols="3" \
--column=sort_int \
--hide-column=5 \
--listen \
--button="Select default":66 \
--button=FLASH:0 \
--button=Abort:99)
BTNRET="${PIPESTATUS[0]}"
CHOOSENP=$(echo "$FCHOOSENP" | cut -d "|" -f 2-5 | tr "|" ":" | tr "\n" " ")
F_LOG "$FUNCNAME BTNRET: $BTNRET"
else
break
fi
fi
done
[ $BTNRET -ne 0 ] && F_MSGE 500 "Aborted by user" && F_EXIT "$FUNCNAME aborted by user" 3
CHCOUNT=$(echo "$CHOOSENP" |tr " " "\n" |grep -c :)
[ $CHCOUNT -lt 1 ] && F_ERR $FUNCNAME 0 "No partition selected?"
F_LOG "choosen partitions: $CHOOSENP -> $CHCOUNT"
BLWARN=$(echo "$CHOOSENP"|tr " " "\n" | $EGREPBIN -c "(bootloader|dangerous)" )
if [ "$BLWARN" -gt 0 ];then
RET=$(F_MSGW 600 "You have choosen\n\n\t<b>$BLWARN</b>\n\nfiles marked as bootloader or/and dangerous.\nFlashing those should only be done when you know what you do!" "--button=I-think-I-know-what-I-do:88")
[ "$RET" != "88" ] && F_ERR $FUNCNAME 3 "Aborted by user"
fi
SORTEDP=$(echo "$CHOOSENP" |tr " " "\n" | sort -t : -k 3n | cut -d ":" -f 1-2 | tr "\n" " " )
CHCOUNT=$(echo "$SORTEDP" |tr " " "\n" |grep -c :)
F_LOG "sorted partitions: $SORTEDP -> $CHCOUNT"
# verify ARB and model
ARET=$(F_VERIFYDARB "$IMGDIR")
# abort when needed
[ "$ARET" != "99" ] && F_ERR $FUNCNAME 3 "Aborted on user check verification ($ARET)"
UANS=$(F_MSGW 700 "Keep in mind that SALT flashes the partitions in RAW format which will take usually longer then i.e. when using LGup.\n(RAW means every single bit gets copied - so even unused disk space)\n\nSALT is ready and will flash these partitions:\n\n$(echo $SORTEDP | sed 's/\ /, /g')" "--button=FLASH:99")
if [ $UANS -ne 99 ] || [ $CHCOUNT -eq 0 ] ;then
F_MSGE 500 "Aborted by user or no partitions selected"
else
# FLASH
CNT=0
for img in $SORTEDP; do
CNT=$((CNT+1))
FFILE="$IMGDIR/${img/:*}"
FPART=${img/*:}
F_LOG "flashing: $FFILE to $FPART"
# inform yad which partition we flash
echo "#flashing: $FPART"
F_LOG "$FUNCNAME: $FPART starting"
$PYTHONBIN -u $LAFPATH/partitions.py $LAFARGS ${CROPT} --batch --restore "$FFILE" $FPART 2>>$LOG | sed -u -e "s%:\([0-9]*\):\([0-9]*\)%,#$FPART: \1 KB / \2 KB%g;s/,/\n/g" 2>>$LOG
FLASHERR=${PIPESTATUS[0]}
if [ $FLASHERR -eq 0 ];then
echo "100"
F_LOG "$FUNCNAME: $FPART finished"
[ $CNT -eq $CHCOUNT ] && echo '# ALL PARTITIONS FLASHED SUCCESSFULLY' && F_LOG "$FUNCNAME: All partitions flashed successfully"
else
F_LOG "$FUNCNAME: $FPART FAILED with $FLASHERR"
echo "# $FPART: FAILED"
F_ERR $FUNCNAME 4 "DO NOT REBOOT YOUR DEVICE!\n FLASHING PROBLEM OCCURED!!!\n while flashing:\n\n <b>$FPART</b>\n\nClick this button, then Upload: " 0 "--form --field=Upload-SALT-log!$SICONS/log_16x16.png:FBTN $SALTPATH/getlog"
fi
done | $FYAD --image="$SICONS/salt_logo_64x64.png" --title="$YTITLE - FLASHING" --text="\n <b>Lean back, take a cup of coffee or sleep a bit. SALT is flashing now ...</b>\n (DO NOT REBOOT THE DEVICE while flashing or when an error occurs!)\n\n" --width 900 --progress --button='Close (WAIT until all is flashed)':1
FLERR=${PIPESTATUS[0]}
# check result
if [ "$FLERR" -eq 0 ];then
F_MSGOK 400 "Flashing was successful!"
else
F_MSGE 800 "FLASHING ENDED WITH ERROR: $FLERR\n\nCheck Debug Log in SALT main screen!\nDO NOT REBOOT THE DEVICE TO AVOID HARD BRICK!!!!\n\nIf you haven't already uploaded the debug log click this button, then Upload:\n" "--form --field=Upload-SALT-log!$SICONS/log_16x16.png:FBTN $SALTPATH/getlog"
fi
# TODO: md5 verify?
# wipe cache
# disabled as it will clear the partition but not format it - leading into a non booting device until formatted manually
#F_WIPEPART cache ni || F_MSGE 400 "Wiping cache ended with an error: $WIPERR\n\nCheck Debug Log in SALT main screen."
# sync filesystems
F_SYNC || F_MSGE 400 "Syncing filesystems ended with an error: $WIPERR\n\nCheck and upload the debug Log in SALT advanced menu.\nDO NOT REBOOT THE DEVICE!"
fi
F_LOG "$FUNCNAME: ended"
}; export -f F_FLASHPART
# check/ensure device is connected
F_CHKDEVCON(){ F_LOG "$FUNCNAME: started"
# takes no argument
$PYTHONBIN $LAFPATH/lglaf.py $LAFARGS ${CROPT} --debug -c '!EXEC uname -m\0' --rawshell 2>&1 | $TEEBIN -a $LOG
RET=${PIPESTATUS[0]}
if [ $RET -ne 0 ];then
RES=$(F_MSG 700 "NO DEVICE CONNECTED?\nIf you have connected your device ensure that it is in DOWNLOAD mode\n(<u>not</u> fastboot, <u>not</u> recovery, <u>not</u> booted Android)" "--image=$SICONS/warning_64x64.png --button=Example-Picture:99 --button=Skip:11 --button=Retry:22")
F_LOG "$FUNCNAME: msge result = $RES"
F_LOG "$FUNCNAME: lsusb output = $(lsusb |grep 1004)"
[ $RES -eq 99 ] && [ ! -z $SUDO_USER ] && sudo -u $SUDO_USER xdg-open "$SICONS/dlmode.png"
[ $RES -eq 99 ] && [ -z $SUDO_USER ] && xdg-open "$SICONS/dlmode.png"
RET=$RES
else
F_LOG "$FUNCNAME: Device seems to be connected!"
fi
F_LOG "RET: $RET"
return $RET
}; export -f F_CHKDEVCON
# open a shell
F_SHELL(){ F_LOG "$FUNCNAME: started"
# takes no arguments
F_CHKDEVCON
if [ $? -eq 0 ];then
F_ELOG "device connected... Opening shell now!"
xterm -e "cd $LAFPATH && echo -e '\n*****************\nTYPE the word exit TO CLOSE THIS WINDOW\n*********************\n\n'; $PYTHONBIN $LAFPATH/lglaf.py $LAFARGS ${CROPT} --rawshell"
fi
F_LOG "$FUNCNAME: ended"
}; export -f F_SHELL
# start dialog for kdz extract
F_STARTKDZ(){ F_LOG "$FUNCNAME: started"
# takes no arguments
EXCHOICES=$($FYAD --title="$YTITLE - EXTRACT" --width=800 --always-print-result --text \
"\n This will extract any KDZ file for you with just a click\n" \
--form \
--field=" KDZ file":FL --file-filter="KDZ files (*.kdz)| *.kdz *.KDZ"\
--field=" Target directory\nHINT: Ensure you have enough free disk space":DIR \
undef /tmp/salt_kdz \
)
F_ELOG "returned: $EXCHOICES"
KDZFILE=$(echo "$EXCHOICES" | cut -d '|' -f 1)
TARGDIR=$(echo "$EXCHOICES" | cut -d '|' -f 2)
UDATA=$(echo "$EXCHOICES" | cut -d '|' -f 4)
KCACHE=$(echo "$EXCHOICES" | cut -d '|' -f 5)
F_ELOG "KDZFILE = $KDZFILE, TARGDIR = $TARGDIR, UDATA = $UDATA, KCACHE = $KCACHE"
[ ! -f "$KDZFILE" ] && F_ERR "EXTRACTKDZ" 3 "$KDZFILE does not exists or is not readable!"
[ ! -z "$TARGDIR" ] && [ ! -d "$TARGDIR" ] && echo mkdir -p $TARGDIR
F_EXTRACTKDZ "$KDZFILE" "$TARGDIR" $UDATA $KCACHE
F_ELOG $FUNCNAME ended
};export -f F_STARTKDZ
# Update everything!
F_UPDATE(){ F_LOG "$FUNCNAME: started"
# takes no arguments
#
# let the user switch between stable and develop
AA=$($FYAD --title="$YTITLE - SETUP" --item-separator='|' --text "\n Here you can choose between stable and development branches of SALT and its backends" --form \
--field=" Target mode\t":CB "$SALTMODES" \
--button=Switch/Update:0 --button=Cancel:1 \
)
[ $? -ne 0 ] && F_LOG "Aborted on user request" && F_EXIT $FUNCNAME 4
AAP=$(echo "$AA" | cut -d "|" -f 1)
case $AAP in
STREAM)
BRSALT="$BR_T_SALT"
BRKDZ="$BR_T_KDZ"
BRLAF="$BR_T_LAF"
;;
*)
BRSALT="$BR_S_SALT"
BRKDZ="$BR_S_KDZ"
BRLAF="$BR_S_LAF"
;;
esac
CNT=0
for u in ${SALTPATH}:$BRSALT ${LAFPATH}:$BRLAF ${KDZTOOLS}:$BRKDZ; do
CNT=$((CNT+1))
F_LOG "$FUNCNAME: updating ${u/:*} on branch ${u/*:} ..."
echo "${CNT}:5"
cd ${u/:*}
echo "${CNT}:10"
F_LOG "$($GIT checkout ${u/*:} 2>&1 || $GIT config --global --add safe.directory ${u/:*} 2>&1)"
$GIT pull 2>&1 | tee -a $LOG | sed "s/^/${CNT}:#/g"
test ${PIPESTATUS[0]} -eq 0 && echo "${CNT}:100"
done | $FYAD --title="$YTITLE - UPDATING" --text="\n <b>Be patient while SALT freshen up...</b>\n (if a progress bar does NOT reach 100% a manual update is required)\n\n" --width 800 --progress --bar="SALT codebase":norm --bar="LGLAF codebase":norm --bar="kdztools codebase":norm --button=Close
F_MSGW 600 "You HAVE TO restart SALT now before the changes become active." "--fixed"
F_LOG "$FUNCNAME: ended"
}; export -f F_UPDATE
# identify a git branch
F_CHKBRNCH(){ F_LOG "$FUNCNAME: started"
# takes 1 arg
#
# 1 => path to check
#
# returns: current branch name
BRPATH="$1"
if [ -z "$BRPATH" ] || [ ! -d "$BRPATH" ];then F_MSGE 500 "INTERNAL ERROR: No valid path ($BRPATH) given! aborted.."; F_EXIT "$FUNCNAME" 9; fi
cd $BRPATH
git symbolic-ref --short -q HEAD
F_LOG "$FUNCNAME: ended with $?"
}; export -f F_CHKBRNCH
# wipe a partition
F_WIPEPART(){ F_LOG "$FUNCNAME: started with $@"
# takes 2 arguments
#
# 1 => partition name to wipe
# 2 => interactive (ia) or noninteractive (ni) mode. if not given we assume interactive!
WPART="$1"
ITP="$2"
if [ "$ITP" == "ni" ];then
F_LOG "$FUNCNAME: wiping $WPART in noninteractive mode"
$PYTHONBIN ${LAFPATH}/partitions.py $LAFARGS ${CROPT} --wipe $WPART 2>&1 | $TEEBIN -a $LOG
else
F_LOG "$FUNCNAME: wiping $WPART in interactive mode"
F_MSG 400 "Do you really want to wipe out <b>$WPART</b>?" "--button=Yes:0 --button='wtf NO never':1"
[ $? -eq 0 ] && $PYTHONBIN ${LAFPATH}/partitions.py $LAFARGS ${CROPT} --wipe $WPART 2>&1 | $TEEBIN -a $LOG | $FYAD --title="$YTITLE - WIPING" --width=800 --height=200 --text-info --listen --wrap --button=Close
fi
F_SYNC
}; export -f F_WIPEPART