-
Notifications
You must be signed in to change notification settings - Fork 3
/
init
executable file
·2491 lines (2349 loc) · 110 KB
/
init
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
#!/bin/sh
#(c) Copyright Barry Kauler, 30 January 2017. Licence: GPL v3 (/usr/share/doc/legal).
#simple script in initramfs to boot Easy Linux.
#text colors: 34=blue, 33=yellow, 32=green, 31=red, 35=purple, 36=aquablue, 38=black
#background colors: 40=black 41=red 42=green 43=yellow 44=blue 45=magenta 46=cyan 47=white
#ansi escape codes ref: https://misc.flogisoft.com/bash/tip_colors_and_formatting
#190304 complete rewrite.
#190706 reintroduce support live-cd, and run in zram.
#190713 first bootup, password gui has a back-button to lang/kbd gui.
#190714 run in zram if working-partition not found.
#190716 search for persistent storage.
#190811 redesign to be able to drop capabilities when switch_root. 190812
#190817 copy session to ram, and disable partition mounting. 190818
#190820 fix determine BASELANG for non-english.
#190821 debian xorg fbdev does not work, have alternative from pyro.
#190828 verify cp of vmlinuz, initrd, easy.sfs to wkg partition.
#190901 cannot choose "Copy session to RAM & disable drives" at first bootup.
#190913 the inbuilt easy container has label pyro or buster, fix upgrading older versions easyos.
#190914 remove more desktop icons and menu entries. copying session to ram, also load extra sfs files.
#190915 fix 190913
#190923 rc.sysinit needs login pw to run and unlock gnome-keyring. 191005 removed (archived input536).
#191101 modify error msg if BOOT_DEV not found.
#191219 add "lockdown=confidentiality" to boot menu.
#191224 if easy.sfs mounted on /tro (via loop0), rollback fails (easy.sfs seems to delete, but isn't), hence moved rollback below unmount /tnew
#200218 use hwclock to set system time.
#200301 optional chroot instead of switch_root ***NOT USING***
#200302 run fstrim on ssd that supports TRIM.
#200303 $DATE variable, read in fscheck.
#200319 busybox fdisk faulty with my 8TB hdd, using full fdisk.
#200621 ref 200302, now have full 'hdparm' utility, can check usb drives.
#200621 ext4 journal default commit interval is 5 seconds, change to 30.
#200623 change from static /dev to devtmpfs, due to awful nvme node assignments when 2+ drives.
#200623 log stuff to /root/.initrd-debug in main f.s.
#200624 fix 200621 if ext4 does not have a journal. 200715 fix again.
#200719 xWKG_DEV override for "Copy session to RAM & unmount working-partition".
#200720 pickup "qfix=NEW"
#200726 boot- and wkg-partition the same, fsck does not work, as fscheck script cannot unmount.
#200727 revert 200719. new "qfix=lock1" for "Copy session to RAM & unmount working-partition"
#200801 new exit_to_initrd(), qfix=dropout<n> to drop out to console.
#200802 new 'nnn' file manager. /.debug.flg written by /usr/sbin/debug-initrd
#200803 user-requested lockdown, file /.lockdown.flg
#200804 revert 191219. 200805 fixes for running in ram.
#200806 .lockdown.flg cannot be in .session folder, requires pw to unencrypt.
# nor can it be in wkg-partition as it is zram0 after bootup. put it in boot-part. ref: /usr/sbin/lockdown-ram
#200807 improve exit funcs, add shfm.
#200809 fix for "job control turned off". qfix=normal to remove permanent lockdown.
#200809 lockdown: new "save" icon on desktop, replace "update" icon.
#200820 mount securityfs. enable lockdown, no longer done as kernel boot param.
#200820 also want BOOT_UUID in /etc/rc.d/PUPSTATE. do not hard-code "save" coords.
#200822 save origWKG_DIR in PUPSTATE. 200823 save BOOT_LOCK in PUPSTATE. 200824 fixes.
#200826 running in ram, mimic sfs files to same path in zram. copy all sfs's. 200827 copy more.
#200828 nearly all cp need -a param.
#200830 remove globicons file when version update. xdg fix. cp fix.
#200830 run mknod here, in case lock#2.
#20201109 "uk" keyboard layout renamed to "gb".
#20201130 make sure ext2 f.s. in zram0 block size is 4096!
#20201201 set TZ timezone variable. note, it will be corrected later after .session mounted.
#20201204 do not delete globicons file when version update (revert 200830).
#20201206 test /sys/kernel/security exists.
#20201211 copy session to ram & disable drives: power-down disabled drives using hdparm.
#20201211 /usr/share/sss/initrd_strings/initd_strings* has translation for "save", but don't assume anything for "update"...
#20201213 lockdown: if kernel patched cap_sys_mount separated from cap_sys_admin, drop latter.
#20201223 do not do 20201223 if kernel less than 5.10 (Xorg does not work).
#20210113 rpi does not have a hardware clock, set it to something sane at 1st bootup.
#20210407 hidepid=1 when mount /proc. maybe only useful in a multiuser situation. ref: kernel docs filesystems/proc.txt. see also: start-container
#20210423 modified cp for xorg alternative that runs in initrd.
#20210423 dunfell oe, xorg not working in initrd, don't use.
#20210424 display word-wrapped text blocks, in coloured rectangle. fix.
#20210524 change from "save-folder" to "save-file". 20210525 fix. 20210526 modify. revert.
#20210530 sparse-file save-file has performance penalty, restrict to WKG_FS=ntfs only.
#20210608 do not like gtk gui for ask pw.
#20210611 paragon ntfs driver needs "-t ntfs3" mount option.
#20210912 group id 118 is "fscryptgrp", using this for enabling fscrypt when login to clients (such as spot).
#20210919 /clients is now /home, home is now files. 20211006 fix.
#20211014 qfix=vid to fix broken video, need to run xorgwizard.
#20211015 hardware-profiling for /etc/modprobe.d
#20211023 cat /proc/fb to /root/.initrd-debug/proc-fb
#20211111 delete container if no longer valid. 20211122 fix.
#20211111 check that symlink to extra sfs still valid (loading on main desktop). 20211122 fix.
#20211205 /files is now in easy.sfs (rootfs-skeleton), as well as boot/initrd-tree/skeleton
#20211206 group id 122 is "filesgrp", set all in /files
#20211207 relocate 20211205 and 20211206 to version-upgrade code section.
#20211208 /mnt/zram0/containers does not exist, append 2>/dev/null
#20211210 /mnt/wkg/files must be 770 permissions.
#20211212 new /mnt/${WKG_DEV}/${WKG_DIR}data
#20220123 2nd partition may be 640 or 768MB. 20220125 resize2fs fix?
#20220206 if no /dev/fb0 then clear screen.
#20220211 if icon-free desktop, icons are in jwm tray. 20220212 fix.
#20220304 increase ext4 commit=30 to 1800 (30min). ref: https://bkhome.org/news/202203/ext4-with-or-without-journal-on-flash-stick.html
#20220511 1st partition may be 767MB, 2nd 4MB
#20220511 ext4 4M too small for a journal. instead of doing it in 3buildeasydistro, do here after resize.
#20220515 recompress easy.sfs from xz to lz4 (LZ4_HC). in fact, do it for all mksquashfs operations.
#20220517 reduce usage of easy.sfs mounted on tnew. warning easy.sfs copy time.
#20220521 tnew, BASELANG, removed completely.
#20220521 aufs top-level now zram. 20220522 no internal journal.
#20220522 the kernel gets rotational right for internal nvme ssd, wrong for usb flash.
#20220522 revert 20220304
#20220523 if EOS_TOP_LEVEL_ZRAM==1 do not mount tmpfs on /tmp
#20220524 rename mnt/easy_ro to mnt/.easy_ro, ditto easy_rw ref: easy-remaster, easy-containers, rc.shutdown
#20220525 EOS_SUPPORT_CONTAINERS==0 do not support containers.
#20220526 hdparm only works on sata drives.
#20220526 lockdown bootup, do not use top-level zram1.
#20220527 when top-level zram, mount wkg-part with noatime
#20220527 /mnt/${WKG_DEV}/${WKG_DIR}.session-transit exists, then merge to .session see: ask-save-zram1 20220530
#20220528 message recommend password.
#20220529 top-level-zram1 mount a subfolder in aufs, so will be able to share zram with containers.
#20220601 lockdown, remove zram1 "save" icon.
#20220601 desktop icons have changed layout, so erase previous PuppyPin
#20220603 override EOS_TOP_LEVEL_ZRAM, kernel param zramtl=1|0 or a file .zramtl.flg
#20220603 replace DB_* with SFS_DB_* in sfs .specs files.
#20220609 tweak whether copy easy.sfs to ram.
#20220611 pass working-drive speed test to PUPSTATE, as variable WKGDRV_SPEED
#20220613 easy.sfs now in ${WKG_DEV}/${WKG_DIR}, not in boot-partition.
# initrd now has /etc/DISTRO_SPECS
#20220614 >=4.0 force always easy.sfs in working-partition. 20220615 fixes. 20220618 fix.
#20220621 .lockdown.flg, .debug.flg, .zramtl.flg, .BOOT_SPECS, .easyos-bootcnt move from boot- to wkg-partition.
#20220622 totally remove BOOT_DEV and BOOT_DIR. remove BOOT_SPECS file.
#20220622 ask enable ext4 encrypt. boot menu.
#20220623 some choices in menu_func cannot be implemented until after pw entered.
#20220624 /easy_rw only mounted if EOS_TOP_LEVEL_ZRAM==1
#20220624 more entries in boot menu.
#20220626 offer boot menu when no pw. 20220627 fix. 20220629
#20220730 EOS_* fallback fix.
#20220801 fix wait for resize2fs to finish. support dd in coreutils.
#20220801 move /.fsckme.flg to /mnt/${WKG_DEV}/${WKG_DIR}
#20220802 top-level-zram doesn't work properly if not enough ram
#20220907 do not have /var symlink. do not have /root/.var or /root/.var0 see also: rc.sysinit, erase-exceptions, fixlayers
#20220911 skeleton img may now have 832MiB wkg-partition.
#20220922 fix set pw for zeus.
#20220928 move /.brokenvideo to /mnt/${WKG_DEV}/${WKG_DIR}
#20220929 remove meaningless widescreen detect.
#20221015 version update, exclude some files&folders from rw-*sfs
#20221016 check valid library path.
#20221030 support EOS_LOGIN_ZEUS, /mnt/wkg/.loginzeus.flg can override.
#20221102 remove support EOS_LOGIN_ZEUS
#20221118 playing with new logo.
#20221226 support skeleton wkg partition 672MiB.
#20230104 /mnt/${WKG_DEV}/${WKG_DIR}.session/.rollback.flg moved to /mnt/${WKG_DEV}/${WKG_DIR}.rollback.flg
#20230112 option pass "qlang=nn" where nn is two-letter language, ex: fr
#20230112 separate strings to file /nls/init.str.en
#20230113 load font for country code.
#20230123 removed SESSIONSFSflag. it is an old idea from 2017, not used.
#20230123 bring back tnew; gtk apps run in initrd
#20230124 choose from two splash images in tnew. apply default gtk2 theme.
#20230131 for sfs exceeding releases max-depth, do not delete if used in container.
#20230210 always load .str.en, in case non-english is incomplete.
#20230211 .str files folder hierarchy reorganized.
#20230220 3buildeasydistro copies build-choices into initrd, so don't do it here.
#20230221 oh, busybox ash does not support ${QLANG^^} capitalization
#20230302 new wallpaper logo.
#20230304 support distro name other than "EasyOS" and "Easy".
#20230405 always change root pw. create signed-key-pair.
#20230406 WKG_DIR must be root:filesgrp and 770 (flatpak save). 20230407 revert.
#20230409 /files reverts to a symlink to /mnt/wkg/files
#20230409 /mnt/${WKG_DEV}/${WKG_DIR}data is no longer encrypted.
#20230414 not sure if busybox hwclock accepts "--localtime" use "-l"
#20230423 revert 20220601 do not delete PuppyPin.
#20230425 maybe compressed 'gpg' 'mksquashfs'
#20230429 fix workingdir when mount overlay fs. /build-choices has EOS_ variables.
#20230429 /build-choices has EOS_FSCRYPT_VER value 1 or 2
#20230430 64 byte hash generated from password.
#20230503 fscrypt v1 to v2 update.
#20230507 hash generated from password used for gpg.
#20230522 new zap psfu font, do not run load_font, load_font_country.
#20230616 modify check perms under /files
#20230622 new tr console keyboard layout.
#20230718 fix for /etc/xdg/rox.sourceforge.net erased when update.
#20230910 now have usr-merge, may have to fix old .session folder. 20230911 20230912
#20230913 pre-usrmerge .session may now have circular symlink.
#20231108 version update, conditionally load sfs's from previous version.
#20231109 hack for nvidia sfs. NO, reverted. check nvidia major version.
#20231111 fix history depth detection.
#20231124 for nvidia.sfs check that nvidia gpu exists.
#20231125 moved up reading sfs/settings/initrd/CONFIG; want to read KEYMAP further down even if no fscrypt.
#20231125 keyboard hardware profile, as need to detect if kb changed. 20231126 fix.
#20231128 fix 20231124
#20231203 usr-merge: may also have to fix kirkstone container.
#20240113 support skeleton with 920MiB wkg-partition. 20240116 880MiB wkg-part.
#20240128 keyboard layout: try fix background color.
#20240308 make sure .session/root has 700 perms.
#20230429
. /build-choices #3buildeasydistro copies it here.
[ ! "$EOS_TOP_LEVEL_ZRAM" ] && EOS_TOP_LEVEL_ZRAM='1'
[ ! "$EOS_SUPPORT_CONTAINERS" ] && EOS_SUPPORT_CONTAINERS='1'
EOS_LOGIN_ZEUS='0' #no longer supporting this.
[ ! "$EOS_FSCRYPT_VER" ] && EOS_FSCRYPT_VER='1'
export EOS_SUPPORT_CONTAINERS #20220529 read in /sbin/rw-merge
mount -o hidepid=1,gid=118 -t proc none /proc #20210407 20210912
mount -t sysfs none /sys
mount -t rootfs -o remount,rw rootfs /
ln -s /proc/mounts /etc/mtab 2> /dev/null
export PATH="/bin:/sbin"
mount -t devtmpfs devtmpfs /dev #200623
export TZ='XXX-23' #20201201 imaginary place right around the world east of Greenwich.
#...i think that this will give the most delayed time, so any file operations
#will not result in a future date after the correct time is set in the main f.s.
#ref: http://www.gnu.org/s/libc/manual/html_node/TZ-Variable.html
KERNVER="$(uname -r)" #20210524
CR='
'
cat /sys/class/zram-control/hot_add >/dev/null #20220517 creates /dev/zram1
cat /sys/class/zram-control/hot_add >/dev/null #20220517 creates /dev/zram2
create_top_level_zram1() { #20220521
FREEK=`grep '^MemFree:' /proc/meminfo | tr -s ' ' | cut -f 2 -d ' '`
#allocate 3/4 of free ram times 2 (as compression is approx 2:1)...
HALFK=$(($FREEK/2))
QTRK=$(($HALFK/2))
USEK=$(($HALFK+$QTRK)) #3/4
ALLOCK=$(($USEK*2))
echo "${ALLOCK}K" > /sys/block/zram1/disksize
#echo "${USEK}K" > /sys/block/zram1/mem_limit
busybox mke2fs -L "TOPLEVELZRAM" -m 0 -b 4096 /dev/zram1 > /dev/null
}
create_savefile_func() { #20210524
#ref: https://bkhome.org/news/202105/automatic-resizing-of-save-file-for-puppy.html
echo -e "\\033[1;35m${S001}\\033[0;39m" #purple
#create a sparse file, size of free space in WKG_DEV...
#20210526 no, make it real big. this will reduce fragmentation. mem tray applet can warn running out
# of space on WKG_DEV. cut 2 (size of partition) instead of 4...
#W0=$(df -k /dev/${WKG_DEV} | grep "^/dev/" | tr -s ' ' | cut -f 2 -d ' ')
#SPARSEK=$(($W0 * 2)) #allow 2MB slack. 20210526 no, double it!
#...not sure about this, reverting...
W0=$(df -k /dev/${WKG_DEV} | grep "^/dev/" | tr -s ' ' | cut -f 2 -d ' ')
SPARSEK=$(($W0 - 2048)) #allow 2MB slack.
dd if=/dev/null bs=1 seek=${SPARSEK}K of=/mnt/${WKG_DEV}/${WKG_DIR}easysave.ext4 > /dev/null 2>&1
#create a ext4 f.s....
LOOPavail="$(losetup -f)"
losetup ${LOOPavail} /mnt/${WKG_DEV}/${WKG_DIR}easysave.ext4
echo -n ' '
echo "#!/bin/ash
mke2fs -q -t ext4 -L \"EASYSAVE\" -m 0 -b 4096 -O encrypt,^64bit ${LOOPavail} > /dev/null 2>&1 #have the full mke2fs.
echo -n \"\$?\" > /tmp/retvalflg
sync" > /mke2fs.sh
chmod 755 /mke2fs.sh
/mke2fs.sh &
while pidof mke2fs.sh >/dev/null;do
sleep 1
echo -n '.'
done
RETVAL="$(cat /tmp/retvalflg)"
echo ''
losetup -d ${LOOPavail}
return $RETVAL
}
exit_to_initrd() {
[ ! "${1}" ] && set -- " Have exited from init script at this line number"
echo -e '\033[1;31m' #bright red
echo -n "${S002} "
grep -n -o "${1}" ${0}
#echo -en '\033[0;39m' #reset foreground color to default.
echo -en '\033[1;35m' #1;35 foreground bright magenta
echo "${S003}"
echo "${S004}"
echo "${S005}"
echo "${S006}"
echo "${S007}"
echo "${S008}"
if [ -f /bin/nnn ];then
echo "${S009}"
if [ ! -f /bin/nnn.bin ];then
mv -f /bin/nnn /bin/nnn.bin
echo -e '#!/bin/sh\nexec nnn.bin -c -d' > /bin/nnn
chmod 755 /bin/nnn
fi
export XDG_CONFIG_HOME=/etc/nnn
#note, i think if append /etc/nnn/plugins to $PATH, then can just have "simple" here...
export NNN_OPEN=/etc/nnn/plugins/simple
fi
echo -en '\033[0;39m' #reset foreground color to default.
export EDITOR=mp
export SHFM_OPENER=/sbin/xdg-open #200807 for shfm file manager.
#/bin/sh
setsid cttyhack sh #200809 fixes "job control turned off"
}
err_exit() { #200807 call exit_to_initrd()
echo -en '\033[1;31m' #bright red
echo -e "${S010} ${1}" #red
echo "${S011}"
echo "${S012}"
echo "${S013}"
echo
echo -en '\033[1;35m' #1;35 foreground bright magenta
echo "${S014}"
echo -en '\033[0;39m' #reset foreground color to default.
exit_to_initrd "$1"
}
ask_kb() { #181010
KEYMAP=us
#now ask for KEYMAP... 20230622 new tr (turkey)... 20240128 try fix background color...
echo -e '\e[1;;45m 1 azerty 2 be-latin1 3 br-abnt2 4 br-abnt 5 br-latin1-abnt2 6 br-latin1-us
7 by 8 cf 9 croat 10 cz 11 de 12 de-latin1
13 dk 14 dvorak 15 dvorak-l 16 dvorak-r 17 es 18 et
19 fi 20 fr 21 gb 22 gr 23 hu101 24 hu
25 il 26 it 27 jp106 28 la-latin1 29 lt 30 mk
31 nl 32 no 33 pl 34 pt-latin1 35 ro 36 ru
37 se 38 sg 39 sk-qwerty 40 sk-qwertz 41 slovene 42 srp
43 sv-latin1 44 tr 45 us 46 wangbe \e[0;;m'
#20210424 want word-wrapped text block in background colour rectangle...
#S015='Please enter the number corresponding to your keyboard layout.'
echo -n -e '\033[1;;44m'
while read aLINE
do
echo -n ' '
echo -n -e '\033[1G' #move cursor back to col 1.
echo " ${aLINE}"
done << EOT
$(echo " ${S015}")
$(echo "${S016}" | fold -s -w 70)
EOT
echo -n -e '\033[0;;m'
echo -n -e '\033[1;30;43m'
while read aLINE
do
echo -n ' '
echo -n -e '\033[1G' #move cursor back to col 1.
echo " ${aLINE}"
done << EOT
$(echo "${S017}" | fold -s -w 70)
EOT
echo -n -e '\033[0;;m'
echo -n " ${S018} " #S018='Keyboard layout:'
read -r -t 300 KBnum
[ $? -ne 0 ] && return 1 #timed out
KBnum=$(echo -n "$KBnum" | sed -e 's%[^0-9]%%g')
[ ! $KBnum ] && KBnum=45 #20230622
[ $KBnum -gt 46 ] && KBnum=45 #20230622
[ $KBnum -eq 0 ] && KBnum=45 #20230622
KEYMAP="$(ls -1 /lib/keymaps | head -n ${KBnum} | tail -n 1 | sed -e 's%\.gz%%')"
echo " ${S019} ${KEYMAP}" #S019='...ok, keymap chosen:'
return 0
}
#20220622 no longer offering boot options in boot-manager, offer here... 20220624 more entries
menu_func() {
CNTm=1
if [ "$1" != "nopw" ];then #20220626
echo "QUIT ${CNTm} ${S020}" > /menulist
CNTm=$(($CNTm+1))
fi
if [ "$LOCKkeep" == "1" ];then
echo "LOCKREM ${CNTm} ${S021}" >> /menulist
CNTm=$(($CNTm+1))
fi
echo "NOX ${CNTm} ${S022}" >> /menulist
CNTm=$(($CNTm+1))
echo "RBSAVED ${CNTm} ${S023}" >> /menulist
CNTm=$(($CNTm+1))
echo "RBPRISTINE ${CNTm} ${S024}" >> /menulist
CNTm=$(($CNTm+1))
echo "FSCHECK ${CNTm} ${S025}" >> /menulist
CNTm=$(($CNTm+1))
#20221102 remove...
# echo "LOGZEUS ${CNTm} Flip login as user root or zeus WARNING EXPERIMENTAL" >> /menulist
# CNTm=$(($CNTm+1))
echo
echo -e -n "\\e[1;38;43m" #38=black text, 43=yellow background. ...um, getting bright-white text, black bg.
if [ "$1" == "nopw" ];then #20220626 20220627
echo "${S026}"
fi
#this pads the lines with spaces to column 41...
cut -f 2- -d ' ' /menulist | xargs -I STR printf "%-41s\n" STR
echo -e -n "\\e[0;;m"
if [ "$1" == "nopw" ];then #20220627 20220629
echo -n "${S027} "
read -t 15 menuchoice
else
echo -n "${S027} "
read menuchoice
fi
if [ "$menuchoice" ];then #20220626
MENUVAR="$(grep " ${menuchoice} " /menulist | cut -f 1 -d ' ')"
else
MENUVAR=''
fi
case "$MENUVAR" in
LOCKREM)
#LOCKkeep='0'
rm -f /mnt/${WKG_DEV}/${WKG_DIR}.lockdown.flg
echo "${S028}"
echo "\\033[1;31m ${S029}\\033[0;39m" #red
;;
NOX)
#delayed, see menu_delay_func...
#mkdir -p /mnt/${WKG_DEV}/${WKG_DIR}.session/root
#touch /mnt/${WKG_DEV}/${WKG_DIR}.session/root/bootcnt.txt #see /root/.profile
echo "${S030}"
;;
RBSAVED)
echo "${S031}"
;;
RBPRISTINE)
echo "${S032}"
;;
FSCHECK)
echo "${S033}"
;;
# LOGZEUS) #20221030 20221102 remove
# echo "...will flip login as user root or zeus"
# ;;
esac
echo
}
#20220623 some choices in menu_func cannot be implemented until after pw entered.
menu_delay_func() {
case "$MENUVAR" in
NOX)
mkdir -p /mnt/${WKG_DEV}/${WKG_DIR}.session/root
touch /mnt/${WKG_DEV}/${WKG_DIR}.session/root/bootcnt.txt #see /root/.profile
;;
RBSAVED)
echo -n ",last" > /mnt/${WKG_DEV}/${WKG_DIR}.rollback.flg #20230104
;;
RBPRISTINE)
echo -n ",erase" > /mnt/${WKG_DEV}/${WKG_DIR}.rollback.flg #20230104
;;
FSCHECK)
echo -n "${WKG_DEV},${WKG_FS},REQUEST" > /mnt/${WKG_DEV}/${WKG_DIR}.fsckme.flg #20220801
;;
# LOGZEUS) #20221030 20221102 remove
# xEOS_LOGIN_ZEUS="$(cat /mnt/${WKG_DEV}/${WKG_DIR}.loginzeus.flg 2>/dev/null)"
# if [ "$xEOS_LOGIN_ZEUS" == "1" ];then
# echo -n '0' > /mnt/${WKG_DEV}/${WKG_DIR}.loginzeus.flg
# EOS_LOGIN_ZEUS=0
# echo " ...will login as root. This is remembered for future boots."
# else
# echo -n '1' > /mnt/${WKG_DEV}/${WKG_DIR}.loginzeus.flg
# EOS_LOGIN_ZEUS=1
# echo " ...will login as zeus. This is remembered for future boots."
# fi
# ;;
esac
}
ask_root_pw() { #20230405
#'You chose not to enter a password to encrypt folders in the working-partition; however, you should, at least, enter a password for the root user.'
#'Note1: at future bootups, the password will not be required to login.'
#'Note2: if the keyboard does not work this early in bootup, there will be a timeout in 300 seconds.'
#'Please type a password, with characters a-z, A-Z, 0-9, minimum 6 characters, that you will remember:'
echo -en "\\033[1;31m" #red foreground.
echo -n "${S300}${CR}${S301}${CR}${S302}${CR}${S303}" | fold -s -w 69
echo -e "\\033[0;39m"
rootPW=''
while [ 1 ];do
echo -n " ${S037} " #'Password:'
read -r -t 300 rootPW
[ $? -ne 0 ] && echo #timed out
if [ "$rootPW" != "" ];then
xPW="$(echo -n "$rootPW" | sed -e 's%[^a-zA-Z0-9]%%g')"
if [ "$rootPW" != "$xPW" ];then
echo "\\033[1;31m ${S038} \\033[0;39m" #'Sorry, only a-z, A-Z, 0-9 characters allowed, try again' red text.
continue
fi
fi
break
done
}
ask_pw() { #180604
if [ "$1" == "0" ];then
#20210424 want word-wrapped text block in background colour rectangle...
echo -n -e '\033[1;;44m'
while read aLINE
do
echo -n ' '
echo -n -e '\033[1G' #move cursor back to col 1.
echo " ${aLINE}"
done << EOT
$(echo "${S034}" | fold -s -w 69)
$(echo " ${S035}")
EOT
echo -n -e '\033[0;;m'
echo -e " \\033[1;31m${S036}\\033[0;39m" #'For your security, a password is strongly recommended' 35=purple, 31=red 20220528
while [ 1 ];do #181109
echo -n " ${S037} " #'Password:'
read -r -t 300 PW
[ $? -ne 0 ] && echo #timed out
if [ "$PW" != "" ];then
xPW="$(echo -n "$PW" | sed -e 's%[^a-zA-Z0-9]%%g')"
if [ "$PW" != "$xPW" ];then
echo "\\033[1;31m ${S038} \\033[0;39m" #'Sorry, only a-z, A-Z, 0-9 characters allowed, try again' red text.
continue
fi
fi
break
done
# if [ ! "$PW" ];then
# PW="$(< /dev/urandom tr -dc 'a-zA-Z0-9' | head -c10)"
# echo " The auto-generated password is: ${PW}"
# echo " Pausing for 60 seconds, please write it down now!!!!"
# sleep 60
# fi
else
#20220622 no longer have menu choices in the boot-manager, so offer some choices here...
while [ 1 ];do
echo -e "\\e[1;;44m ${S039} \\e[0;;m" #'Please enter password to decrypt the working-partition'
echo -e "\\e[1;;43m ${S040} \\e[0;;m" #'OR just press ENTER to bring up a menu of boot options' 43=yellow background.
echo -n " ${S041} " #'Password:'
#read PW
PW=''
while [ 1 ];do #echo * for each char entered...
read -r -s -n1 pw1
if [[ -z $pw1 ]];then
echo; break
else
echo -n '*'; PW="${PW}${pw1}"
fi
done
if [ "$PW" == "" ];then
menu_func
continue
fi
break
done
fi
return 0 #190713
}
#load_font() { #20230522 no longer used.
# #2-char keymap is passed in
# case "$1" in
# az|be|br|by|cr|de|dk|es|fi|fr|gr|hu|it|nl|no|pt|ro|ru|se|sk|sl) #all european languages
# loadfont < /lib/consolefonts/LatGrkCyr-8x16.psfu
# ;;
# il) #arabic, hebrew. il=israel
# loadfont < /lib/consolefonts/LatArCyrHeb-16.psfu
# ;;
# esac
#}
##20230113 load font based on the 2-letter country code...
#load_font_country() { #20230522 no longer used.
# case "$1" in
# az|be|br|by|cr|de|dk|es|fi|fr|gr|hu|it|nl|no|pt|ro|ru|se|sk|sl)
# #all european languages
# loadfont < /lib/consolefonts/LatGrkCyr-8x16.psfu
# ;;
# il|dz|bh|td|km|dj|eg|iq|jo|kw|lb|ly|mr|ma|om|qa|sa|so|sd|sy|tn|ae|ye)
# #arabic, hebrew. il=israel arab countries: dz bh td km dj eg iq jo kw lb ly mr ma om qa sa so sd sy tn ae ye
# loadfont < /lib/consolefonts/LatArCyrHeb-16.psfu
# ;;
# esac
#}
###temporary mount easy.sfs###20230123
mount_tnew() {
mkdir tro trw tnew
mount -t squashfs -o loop,noatime /mnt/${WKG_DEV}/${WKG_DIR}easy.sfs tro
[ $? -ne 0 ] && err_exit "FAILED: mount -t squashfs -o loop,noatime /mnt/${WKG_DEV}/${WKG_DIR}easy.sfs tro"
if [ "$LAYERFS" == "aufs" ];then
mount -t aufs -o br=trw=rw:tro=ro aufs tnew
[ $? -ne 0 ] && err_exit "FAILED: mount -t aufs -o br=trw=rw:sro=ro aufs tnew"
else
mkdir twork
mount -t overlay -o lowerdir=tro,upperdir=trw,workdir=twork overlay tnew
[ $? -ne 0 ] && err_exit "FAILED: mount -t overlay -o lowerdir=tro,upperdir=trw,workdir=twork overlay tnew"
fi
mount -o bind /dev tnew/dev
mount -o bind /proc tnew/proc
cp -a /etc/mtab tnew/etc/
mkdir -p tnew/dev/pts
mount -t devpts devpts tnew/dev/pts #need this to run xterm.
#configure so can run X...
cp -a -f tnew/etc/X11/xorg.conf.d/10-evdev-puppy.conf / #coz need it later.
rm -f tnew/etc/X11/xorg.conf.d/*
rm -f tnew/usr/share/X11/xorg.conf.d/* 2>/dev/null
rm -f tnew/etc/X11/Xsession.d/*
cp -f /xorg.conf tnew/etc/X11/
cp -f ask-country-x tnew/
cp -f ask-pw-x tnew/
cp -f startx tnew/
cp -f xinitrc tnew/
cp -f logo800x600.png tnew/ #20230124
cp -f logo1920x1440.png tnew/ # "
cp -f tnew/root/.gtkrc-2.0 tnew/ # "
if [ -d tnew/usr/lib/xorg-fb ];then #alternative xorg runs on framebuffer.
rm -rf tnew/usr/lib/xorg/modules
cp -a -f tnew/usr/lib/xorg-fb/modules tnew/usr/lib/xorg/
cp -a -f tnew/usr/lib/xorg-fb/Xorg tnew/usr/lib/xorg/
cp -a -f tnew/usr/lib/xorg-fb/Xorg tnew/usr/bin/
fi
sed -e 's%^DISTRO_%INIT_DISTRO_%' tnew/etc/DISTRO_SPECS > /INIT_DISTRO_SPECS
. /INIT_DISTRO_SPECS
}
#190828 try to recover if cp fails...
cp_verify_func() {
#passed params: source destination
fsync ${2}
cmp -s ${1} ${2}
if [ $? -ne 0 ];then
echo -e "\\033[1;31m${S042}\\033[0;39m" #red
echo " cp ${1} ${2}"
echo " ${S043}"
echo " ${S044}"
rm -f ${2} 2>/dev/null
cp -a -f ${1} ${2}
fsync ${2}
cmp -s ${1} ${2}
if [ $? -ne 0 ];then
if [ "$prevVER" ];then
echo " ${S045}"
echo " ${S046}"
fi
err_exit "${S047}"
else
echo " ${S048}"
fi
fi
}
#20220622 taken out as a func, as call from two places...
mnt_wkg_ext4_func() {
#rw,relatime,data=ordered are the defaults anyway... 20220304 commit=30 to 1800... 20220522 revert
if [ $EOS_TOP_LEVEL_ZRAM -eq 1 ];then #20220527
mount -t ${WKG_FS} -o commit=30,rw,noatime,data=ordered /dev/${WKG_DEV} /mnt/${WKG_DEV} 2>/dev/null
else
mount -t ${WKG_FS} -o commit=30,rw,relatime,data=ordered /dev/${WKG_DEV} /mnt/${WKG_DEV} 2>/dev/null
fi
RET=$? #200715 it was going to err_exit, need this $RET...
if [ $RET -ne 0 ];then
if [ $EOS_TOP_LEVEL_ZRAM -eq 1 ];then #20220527
mount -t ${WKG_FS} -o noatime /dev/${WKG_DEV} /mnt/${WKG_DEV} #200624 fallback if no journal
else
mount -t ${WKG_FS} /dev/${WKG_DEV} /mnt/${WKG_DEV} #200624 fallback if no journal
fi
RET=$?
fi
return $RET
}
#20230112
if [ "$qlang" ];then
QLANG="$qlang"
fi
. /nls/en/init.str #20230210 20230211
if [ "$QLANG" ];then
if [ -e /nls/${QLANG}/init.str -a "$QLANG" != "en" ];then
. /nls/${QLANG}/init.str
export QLANG
#load_font_country ${QLANG} #20230113 20230522
fi
fi
#190307 display logo, -f = reduces to fit screen. 20220929
#20221118 playing with new logo... 20230119... 20230124...
fbX='800'
if [ -e /dev/fb0 ];then
if [ -s /sys/class/graphics/fb0/virtual_size ];then
fbRES="$(cat /sys/class/graphics/fb0/virtual_size)"
fbX="${fbRES/,*/}"
fi
idump -f logo1920x1440.png 2>/dev/null
#idump -f logo1920x1080.png 2>/dev/null #20230302
[ $? -ne 0 ] && rm -f /dev/fb0 #190313
else
clear #20220206 no logo, just clear the screen.
fi
export fbX #want in tnew
#optional WKG_DEV passed in as kernel boot param...
[ "$wkg_dev" ] && WKG_DEV="$wkg_dev" #ex: zram0
#also allow override WKG_DIR...
[ "$wkg_dir" ] && zWKG_DIR="$wkg_dir"
[ "$WKG_DIR" ] && zWKG_DIR="$WKG_DIR"
#190710 also WKG_UUID, WKG_LABEL...
[ "$wkg_uuid" ] && zWKG_UUID="$wkg_uuid"
[ "$WKG_UUID" ] && zWKG_UUID="$WKG_UUID"
[ "$wkg_label" ] && zWKG_LABEL="$wkg_label"
[ "$WKG_LABEL" ] && zWKG_LABEL="$WKG_LABEL"
[ "$zWKG_DIR" ] && [ "${zWKG_DIR##*/}" ] && zWKG_DIR="${zWKG_DIR}/" #must have trailing slash.
# ...optional/alternative WKG_LABEL
#190706 set to something if not defined...
[ ! "$WKG_UUID" ] && WKG_UUID='wkguuidunknown'
[ ! "$WKG_LABEL" ] && WKG_LABEL='wkglabelunknown'
#kernel boot parameter overrides...
[ "$zWKG_DIR" ] && WKG_DIR="$zWKG_DIR"
[ "$zWKG_UUID" ] && WKG_UUID="$zWKG_UUID" && WKG_DEV="" && WKG_LABEL=""
[ "$zWKG_LABEL" ] && WKG_LABEL="$zWKG_LABEL" && WKG_DEV="" && WKG_UUID=""
export LANG=C
#170206 reintroducing aufs in the kernel:
if grep -qw aufs /proc/filesystems; then
LAYERFS='aufs'
RO='=ro'
else
LAYERFS='overlay'
RO=''
fi
SALT="aprilandvincent" #190308 previously used $WKG_DISKID
#now have DISTRO_SPECS in initrd... 20220615 20220629 moved up.
[ ! -f /etc/DISTRO_SPECS ] && err_exit "/etc/DISTRO_SPECS is missing from initrd"
sed -e 's%^DISTRO_%INIT_DISTRO_%' /etc/DISTRO_SPECS > /INIT_DISTRO_SPECS
. /INIT_DISTRO_SPECS
#20230304 support names other than "EasyOS" and "Easy", see DISTRO_SPECS
if [ ! "$INIT_DISTRO_NAME_LONG" ];then
INIT_DISTRO_NAME_LONG="$INIT_DISTRO_NAME"
else
INIT_DISTRO_NAME="$INIT_DISTRO_NAME_LONG" #coz deprecated in DISTRO_SPECS
fi
if [ ! "$INIT_DISTRO_NAME_NORMAL" ];then
INIT_DISTRO_NAME_NORMAL='EasyOS'
fi
if [ ! "$INIT_DISTRO_NAME_SHORT" ];then
INIT_DISTRO_NAME_SHORT='Easy'
fi
###display info### #20220629 20230304
loadfont < /lib/consolefonts/zap-ext-vga16.psfu #20230522
echo -n -e "\\033[1;32m${INIT_DISTRO_NAME_LONG}, version ${INIT_DISTRO_VERSION}\\033[0;39m\n" #bright green
echo
###find drives###
#find the drive we are booting on (has vmlinuz, initrd, easy.sfs), and working drv...
#180601 users may forget to put a trailing slash... a leading slash is not allowed...
[ "$WKG_DIR" ] && [ "${WKG_DIR##*/}" ] && WKG_DIR="${WKG_DIR}/"
[ "$WKG_DIR" ] && [ "${WKG_DIR:0:1}" == "/" ] && WKG_DIR="${WKG_DIR:1:99}"
echo -n -e "\\033[1;35m${S100}\\033[0;39m\n " #purple
CNT=0; Pb=0; Pw=0
[ "$WKG_LABEL" == "EASYOSZRAM" ] && WKG_DEV="zram0" #190706 200822
[ -e /dev/scd0 ] && rm -f /dev/scd* #190706 static dev nodes, these duplicate sr* nodes.
while [ $CNT -lt 20 ];do #drives may take couple seconds to become available. 180415 increase 8 to 20.
sleep 1
echo -n '.'
CNT=$(($CNT+1))
#190718 iso written to usb-stick has (ex:) /dev/sdd and dev/sdd1 both LABEL="EASYOSOPTICAL", filter-out former...
BLKIDS="$(blkid | grep -v '[a-z]: ')"
#ex line: /dev/sda2: LABEL="intern1p2" UUID="cd5ef69b-883d-4744-bc1d-551154131db2" TYPE="ext4"
[ ! "$WKG_DEV" ] && WKG_DEV="$(echo "${BLKIDS}" | grep -E "\"${WKG_UUID}\"|\"${WKG_LABEL}\"" | cut -f 1 -d ':' | cut -f 3 -d '/')"
[ "$WKG_DEV" ] && break
done
[ ! "$WKG_DEV" ] && WKG_DEV="zram0" #190714
Wdevs=$(echo -n "$WKG_DEV" | tr '\n' ' ' | wc -w) #precaution.
[ $Wdevs -gt 1 ] && err_exit "${Wdevs} ${S101} ${WKG_UUID} ${WKG_LABEL}"
#20201223 only allow drop CAP_SYS_ADMIN if have CAP_SYS_MOUNT patch and kernel >=5.10
CSAdrop=0
capsh --supports=cap_sys_mount 2>/dev/null #20201213
if [ $? -eq 0 ];then #kernel has cap_sys_mount separated from cap_sys_admin
if vercmp $KERNVER ge 5.10 ;then #20210524
CSAdrop=1
fi
fi
#190817 parsing QFIX moved up, also repeated further down...
#ref: http://man7.org/linux/man-pages/man7/capabilities.7.html
CAPS_DROP='' #190812
xWKG_DEV='' #190817 200719 comment-out. 200727 restore.
DROPOUT='' #200801
LOCKDOWN='' #200803
NORMAL=0 #200809
BROKENVID=0 #20211014
ZRAMTL='' #20220603 override EOS_TOP_LEVEL_ZRAM
[ "$qfix" ] && QFIX=$qfix #kernel boot param
if [ "$QFIX" ];then
for ONEFIX in `echo -n "$QFIX" | tr ',' ' '`
do
case $ONEFIX in
#cap1|CAP1) CAPS_DROP='cap_sys_mount,cap_dac_override,cap_chown,cap_fowner,cap_mknod,cap_setfcap,cap_setpcap' ;; #190812
#cap2|CAP2) CAPS_DROP='cap_sys_mount,cap_dac_override,cap_chown,cap_fowner,cap_mknod,cap_setfcap,cap_setpcap'; xWKG_DEV='zram0' ;; #190817 copy to ram
#cap1|CAP1) CAPS_DROP='cap_sys_mount,cap_mknod' ;; #190812 190818
#cap2|CAP2) CAPS_DROP='cap_sys_mount,cap_mknod'; xWKG_DEV='zram0' ;; #190817 copy to ram. 190818
cap2|CAP2) CAPS_DROP='cap_mknod'; xWKG_DEV='zram0'; LOCKDOWN='2' ;; #190818 200803 deprecated.
lock*|LOCK*) LOCKDOWN="${ONEFIX:4:1}" ;; #200803 extract the number. note, "cap2" is deprecated.
dropout*|DROPOUT*) DROPOUT="${ONEFIX:7:1}" ;; #200801 extract the number
normal|NORMAL) NORMAL=1 ;; #200809 to remove permanent lockdown.
vid|VID) BROKENVID=1 ;; #20211014
zramtl*|ZRAMTL*) ZRAMTL=${ONEFIX:6:1} #20220603 zramtl0 disable, zramtl1 enable.
esac
done
fi
case "$LOCKDOWN" in #200803 note, see also .lockdown.flg further down script.
1) xWKG_DEV='zram0' ;; #"Copy session to RAM, unmount partitions"
2) #"Copy session to RAM, disable drives"
if [ $CSAdrop -eq 1 ];then
CAPS_DROP='cap_mknod,cap_sys_admin'
else
CAPS_DROP='cap_mknod'
fi
xWKG_DEV='zram0'
;;
esac
if [ "$LOCKDOWN" ];then #190901 200803
LOCKkeep='0' #200805 once-only
#cannot do this at first bootup, as not yet a session to copy to ram.
#20220123 may have a bigger 2nd partition... 20220511 2nd partition may be smaller, 4MB...
WKGSIZEflg="$(fdisk -l /dev/${WKG_DEV} | grep -oE ' 640 MB| 640 MiB| 4 MB| 4 MiB')" #200319 full fdisk "640 MiB"
if [ "$WKGSIZEflg" ];then
echo -e "\\033[1;31m${S102}\\033[0;39m" #red
CAPS_DROP=''
xWKG_DEV=''
LOCKDOWN='' #200803
fi
fi
if [ "$ZRAMTL" ];then #20220603
EOS_TOP_LEVEL_ZRAM=${ZRAMTL} #override.
fi
[ "$DROPOUT" == "0" ] && exit_to_initrd " ${S103}" #200801
###check if user has requested lockdown###
#200803 ref: /usr/sbin/lockdown-ram
#200806 .lockdown.flg cannot be in .session folder, put into boot-part... 20220621 wkg-part...
mkdir -p /mnt/${WKG_DEV}
WKG_FS="$(echo "$BLKIDS" | grep "^/dev/${WKG_DEV}:" | grep -o 'TYPE="[a-z0-9]*"' | cut -f 2 -d '"')" #200803 moved up.
if [ "$LOCKDOWN" == "" -o "$DROPOUT" == "" ];then
#temporarily mount WKG_DEV...
if grep -q 'ntfs3' /proc/filesystems;then #20210611 has paragon ntfs3 driver.
mount -t ${WKG_FS/ntfs/ntfs3} /dev/${WKG_DEV} /mnt/${WKG_DEV}
else
mount -t ${WKG_FS} /dev/${WKG_DEV} /mnt/${WKG_DEV}
fi
if [ $? -eq 0 ];then
[ $NORMAL -eq 1 ] && rm -f /mnt/${WKG_DEV}/${WKG_DIR}.lockdown.flg 2>/dev/null #200809
if [ "$LOCKDOWN" == "" ];then #that is, not done at kernel boot param.
if [ -s /mnt/${WKG_DEV}/${WKG_DIR}.lockdown.flg ];then
grep -q '^lock[0-9]:[0-9]' /mnt/${WKG_DEV}/${WKG_DIR}.lockdown.flg
if [ $? -eq 0 ];then
#.lockdown.flg has "lock[1|2]:[0|1]" -- :0 once-only, :1 permanent
LOCKspecs="$(cat /mnt/${WKG_DEV}/${WKG_DIR}.lockdown.flg)"
LOCKkeep="${LOCKspecs:6:1}"
LOCKDOWN="${LOCKspecs:4:1}"
case "$LOCKDOWN" in #200803 note, see above, kernel param "qfix=lock[1|2]"
1) xWKG_DEV='zram0' ;; #"Copy session to RAM, unmount partitions"
2) #"Copy session to RAM, disable drives"
if [ $CSAdrop -eq 1 ];then
CAPS_DROP='cap_mknod,cap_sys_admin'
else
CAPS_DROP='cap_mknod'
fi
xWKG_DEV='zram0'
;;
esac
if [ "$LOCKkeep" != "1" ];then
rm -f /mnt/${WKG_DEV}/${WKG_DIR}.lockdown.flg
sync
fi
fi
fi
fi
if [ "$DROPOUT" == "" ];then #that is, not a kernel boot param
#200802 ref: /usr/sbin/debug-initrd 200806 .debug.flg also in boot-part... 20220621 wkg-part...
if [ -s /mnt/${WKG_DEV}/${WKG_DIR}.debug.flg ];then
grep -q '^dropout' /mnt/${WKG_DEV}/${WKG_DIR}.debug.flg
if [ $? -eq 0 ];then
DROPOUT="$(cat /mnt/${WKG_DEV}/${WKG_DIR}.debug.flg)"
DROPOUT="${DROPOUT:7:1}"
rm -f /mnt/${WKG_DEV}/${WKG_DIR}.debug.flg
sync
fi
fi
fi
if [ "$ZRAMTL" == "" ];then #20220603 that is, not a kernel param. 20220621 now in wkg-part...
if [ -s /mnt/${WKG_DEV}/${WKG_DIR}.zramtl.flg ];then
EOS_TOP_LEVEL_ZRAM=$(cat /mnt/${WKG_DEV}/${WKG_DIR}.zramtl.flg) #1 or 0
fi
fi
#20230113 choose language 2-letter code... 20230123
if [ ! "$QLANG" ];then #set if kernel param.
if [ ! -f /mnt/${WKG_DEV}/${WKG_DIR}.qlang ];then
#ask language code...
EXIT='bad'
#20230221 abandon gtk ask-country-x ...
#if [ -e /dev/fb0 ];then
# mount_tnew #aufs temporary mount easy.sfs
# #cp -f tnew/root/.packages/build-choices build-choices #20230210 used in /sbin/ask-language 20230220
# chroot tnew /bin/busybox ash -c "/startx ask-country-x"
# touch tnew/RETASKCOUNTRY
# if grep -q '^EXIT="OK"' tnew/RETASKCOUNTRY; then
# KEYMAP="$(grep '^COMBO_KEYBOARD.*' tnew/RETASKCOUNTRY | cut -f 2 -d '"' | cut -f 1 -d ' ')" #ex: de
# BASELANG="$(grep '^COMBO_LOCALE.*' tnew/RETASKCOUNTRY | cut -f 2 -d '"' | cut -f 1 -d ' ')" #ex: de_DE
# BASELANG="${BASELANG/@*/}" #@euro chopped.
# QLANG="${BASELANG/_*/}"
# EXIT='OK'
# fi
# #umount temporary easy.sfs
# sync
# umount tnew/dev/pts
# umount tnew/proc
# umount tnew/dev
# umount tnew
# umount tro
#fi
#if [ "$EXIT" != "OK" ];then #fallback...
/sbin/ask-language #currently using dialog so don't need /dev/fb0
QLANG="$(cat /qlang)" #ex: fr
BASELANG="$(cat /DEFLANG12)" #ex: fr_FR
#fi
echo -n "$QLANG" > /mnt/${WKG_DEV}/${WKG_DIR}.qlang
else
QLANG="$(cat /mnt/${WKG_DEV}/${WKG_DIR}.qlang)"
fi
if [ -e /nls/${QLANG}/init.str -a "$QLANG" != "en" ];then #20230110
. /nls/${QLANG}/init.str
#load_font_country ${QLANG} #20230522
fi
export QLANG
fi
sync
umount /mnt/${WKG_DEV}
fi
fi
###very low ram###
#20220802 top-level-zram doesn't work properly if not enough ram
FREEK=`grep '^MemFree:' /proc/meminfo | tr -s ' ' | cut -f 2 -d ' '`
if [ $FREEK -lt 1200000 ];then #1.2GB
EOS_TOP_LEVEL_ZRAM=0
fi
#also disable lockdown...
if [ "$LOCKDOWN" ];then
if [ $FREEK -lt 3700000 ];then #3.7GB
echo -e "\\033[1;31m${S110}\\033[0;39m" #red
LOCKDOWN=''
xWKG_DEV=''
CAPS_DROP=''
#keep this, in case usb-stick boots on another pc...
#rm -f /mnt/${WKG_DEV}/${WKG_DIR}.lockdown.flg 2>/dev/null
fi
fi
#20220526 hope no conflict
if [ "$LOCKDOWN" ];then
#disable the extra zram1 top layer...
EOS_TOP_LEVEL_ZRAM=0
fi
if [ "$WKG_DEV" == "zram0" -o "$xWKG_DEV" == "zram0" ];then #190706 190817
echo ''
if [ "$WKG_DEV" == "zram0" ];then
echo -e "\\033[1;31m${S111}\\033[0;39m" #red
WKG_DRV='zram0'
WKG_FS='ext2'
else
echo -e "\\033[1;31m${S112}\\033[0;39m" #red
fi
xWKG_FS='ext2'
#allocate 3/4 of free ram times 2 (as compression is approx 2:1)...
HALFK=$(($FREEK/2))
QTRK=$(($HALFK/2))
USEK=$(($HALFK+$QTRK)) #3/4
ALLOCK=$(($USEK*2))
echo " ${S113} ${USEK}K"
echo "${ALLOCK}K" > /sys/block/zram0/disksize
echo "${USEK}K" > /sys/block/zram0/mem_limit
busybox mke2fs -L "EASYOSZRAM" -m 0 -b 4096 /dev/zram0 > /dev/null #20201130 make sure block size is 4096!
#...has to be ext2, so won't ask for password etc.
fi
if [ "$WKG_DEV" != "zram0" ];then #190817
WKG_PARTNUM="${WKG_DEV/*[a-z]/}"
#WKG_DRV="${WKG_DEV%%[^a-z][0-9]*}"
WKG_DRV="${WKG_DEV%[0-9]}"
WKG_DRV="${WKG_DRV%[0-9]}"
[ "${WKG_DRV:0:3}" == "mmc" ] && Pw=1
[ "${WKG_DRV:0:3}" == "nvm" ] && Pw=1
[ $Pw -eq 1 ] && WKG_DRV="${WKG_DRV%p}"
WKG_FS="$(echo "$BLKIDS" | grep "^/dev/${WKG_DEV}:" | grep -o 'TYPE="[a-z0-9]*"' | cut -f 2 -d '"')" #200803 moved up.
fi
#coz later on, $WKG_DEV may get changed to zram0...
origWKG_DEV="$WKG_DEV"
origWKG_FS="$WKG_FS"
origWKG_UUID="$WKG_UUID" #200809
origWKG_DIR="$WKG_DIR" #200822
export WKG_FS
#20210526 think what needed to allow save-file instead of save-folder...
# WKG_FS=ntfs: kernel >= 5.10.39 has paragon ntfs3 driver,
# WKG_FS must support sparse files. yes: ntfs ext2/3/4 f2fs reaiserfs xfs zfs btrfs squashfs no: exfat fat16/32 iso9660
SFchk=0
case "$WKG_FS" in
ntfs) #20210530 restrict to ntfs only, due to performance hit.
#ext*|reiser*|f2fs|ntfs*|xfs|zfs|btrfs)
SFchk=1