forked from puppylinux-woof-CE/woof-CE
/
init
executable file
·1461 lines (1351 loc) · 52.3 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
# see also /sbin scripts: usablefs, set_plang, wait4usb, switch
#
# _FN = _FILENAME
# _MP = _MOUNTPOINT
#
#Aufs layers setup by this script...
#aufs layers: RW (top) RO1 RO2 PUPMODE
#First boot (or pfix=ram): tmpfs pup_xxx.sfs 5
#Normal running puppy: pup_save.3fs pup_xxx.sfs 12
#ditto, but flash drive: tmpfs pup_save.3fs pup_xxx.sfs 13
#Multisession cd/dvd: tmpfs folders pup_xxx.sfs 77
######################## localization ########################
#ex: /locale/<locale>/init.mo
L_WINDOWS_HIBERNATED="ERROR: Windows NTFS hibernated partition, cannot mount"
L_DONE="done"
L_FAILED="failed"
L_DUMPING_BOOTINIT_LOG="Dumping last lines of /tmp/bootinit.log..."
L_DUMPING_KERNEL_LOG="Dumping last lines of kernel log..."
L_ERROR_IS_TOO_CRITICAL="Error is too critical, dropping out to console..."
L_PAUSING_60_SECONDS="Pausing for 60 seconds..."
L_LOADING_FILE="Loading the '%s' %s file..." #printf
L_CANNOT_RESIZE_PUPSAVE="SORRY, cannot resize %s" #printf
L_INCREASING_PUPSAVE='Increasing %s by %s Kbytes, please wait...' #printf
L_LOADING_PUPSAVE='Loading savefolder %s [%s]...' #printf
L_LOADING_PUPSAVE_FILE='Loading savefile %s [%s] (%s)...' #printf
L_UPGRADE_NO="Backing off, not using personal storage, booting in RAM only, PUPMODE=5..."
L_LOADING_FROM_CD="Loading folder %s from CD/DVD..." #printf
L_RAM_DISK_FULL="RAM disk full, copy failed at %s" #printf
L_ADDING_SAVE_LAYER_FAILED="adding %s to aufs stack failed." #printf
L_WAITING_FOR_USB="Waiting for USB storage."
L_LOADING_KEYBOARD_LAYOUT="Loading '%s' keyboard layout..." #printf
L_COPY_MESSAGE="copying to ram"
L_LOAD_MESSAGE="main"
L_PRE_MESSAGE="Loading puppy main sfs file."
L_ERR_PDRV_INCOMPLETE="%s information is incomplete." #printf
L_ERR_ONEPART_NOT_MOUNTED="%s is not mounted." #printf
L_ERR_ONEPART_NOT_OK="%s %s is not Ok." #printf
L_ERR_ONEPART_MOUNT_SFS_FAILED="%s %s mount of sfs failed." #printf
L_ERR_AUFS_SFS_FAILED="aufs mount of %s failed." #printf
L_ERR_TYPE_PUPSAVE="Type a number to choose which personal file to use:"
L_DROPPED_TO_INITRD_SHELL="Dropped to initramfs shell. Type 'exec switch' to continue booting Puppy."
L_SWITCH_ROOT="Performing a 'switch_root' to the layered filesystem..."
L_CONTINUING_LOADING="...continuing with loading %s..." #printf
L_FOLDER_MARKED_BAD="Folder %s marked bad." #printf
L_0_NONE="0 none"
L_ERROR_FAILED_AUFS_STACK='Failed to create empty aufs stack'
L_ADDING_MODULE="Adding module %s" #printf
L_NO_DISTRO_SPECS="No DISTRO_SPECS file found, assuming that personal storage is empty."
L_DEBUG_SAVE="To save debug info to a partition, type 'debugsave'"
L_PASSWORD="Password:"
L_PASSWORD_MSG_1="NOTICE: As you type your password nothing will be displayed on the screen."
L_PASSWORD_MSG_2="This is a security measure. Just type it in then press ENTER key..."
L_SFFS_ERROR="ERROR: savefile filesystem is not ext2/3/4"
##############################################################
#mkdir -p /pup_new/initrd
#cp -rf /dev2 /pup_new/initrd/dev
#cp /dev2.tar.gz /pup_new/initrd/dev2.tar.gz
exec 1>/dev2/console 2>&1 #s243a
/sbin/usablefs # mount: /proc /sys /dev / (proc sysfs devtmpfs rootfs)
# a full-install OS has 'fullinstall' param in the cmdline
# it's added by puppyinstaller (or you can add it manually)
for i in $(cat /proc/cmdline) ; do
[ "$i" = "fullinstall" ] && exec /init_full_install
done
export TERM="xterm"
export TERMINFO="/usr/share/terminfo"
export LANG=C
PATH="/bin:/sbin"
export KERNELVER="$(uname -r)"
VFAT_OUT_PARAM='noatime,shortname=mixed,quiet,utf8' #see also /sbin/set_plang
. /DISTRO_SPECS #v412 has DISTRO_VERSION, DISTRO_FILE_PREFIX
. /etc/rc.d/functions_x
export DISTRODESC="${DISTRO_NAME} ${DISTRO_VERSION} - Linux ${KERNELVER} - `uname -m`"
#precaution - if DISTRO_SPECS was not processed by 3builddistro...
[ ! "$DISTRO_ZDRVSFS" ] && DISTRO_ZDRVSFS="zdrv_${DISTRO_FILE_PREFIX}_${DISTRO_VERSION}.sfs"
[ ! "$DISTRO_FDRVSFS" ] && DISTRO_FDRVSFS="fdrv_${DISTRO_FILE_PREFIX}_${DISTRO_VERSION}.sfs"
[ ! "$DISTRO_ADRVSFS" ] && DISTRO_ADRVSFS="adrv_${DISTRO_FILE_PREFIX}_${DISTRO_VERSION}.sfs"
[ ! "$DISTRO_YDRVSFS" ] && DISTRO_YDRVSFS="adrv_${DISTRO_FILE_PREFIX}_${DISTRO_VERSION}.sfs"
[ ! "$DISTRO_PUPPYSFS" ] && DISTRO_PUPPYSFS="puppy_${DISTRO_FILE_PREFIX}_${DISTRO_VERSION}.sfs"
# filenames specified in DISTRO_SPECS: DISTRO_ZDRVSFS, DISTRO_PUPPYSFS...
Z_DEF_FN="$DISTRO_ZDRVSFS"
F_DEF_FN="$DISTRO_FDRVSFS"
A_DEF_FN="$DISTRO_ADRVSFS"
Y_DEF_FN="$DISTRO_YDRVSFS"
P_DEF_FN="$DISTRO_PUPPYSFS"
if [ $loglevel ] ; then
LOGLEVEL=$loglevel
else
# If no loglevel is specified, the kernel uses its default loglevel..
# but it may be too verbose and flood the screen.
# '3' is the standard loglevel.
echo '3' > /proc/sys/kernel/printk
fi
#=============================================================
# FUNCTIONS
#=============================================================
fsck_func() {
# "$1" - partition device - ex: /dev/sdb2
# "$2" - fstype - ex: ext2
case $2 in
ext2|ext3|ext4) fsck_app='e2fsck' ; fsck_OPT='-y' ;;
#vfat|msdos) fsck_app='fsck.fat' ; fsck_OPT='-y' ;;
#exfat) fsck_app='exfatfsck' ; fsck_OPT='' ;;
*) return ;;
esac
which "${fsck_app}" || {
echo "WARNING: '${fsck_app}' not found"
FSCKDPARTS="${FSCKDPARTS}${1}|"
return
}
if [ "$(echo "$FSCKDPARTS" | grep "${1}|")" = "" ];then
${fsck_app} ${fsck_OPT} ${1} > /dev/console 2>&1 || sleep 3 #so the user has time to read the error msg..
FSCKDPARTS="${FSCKDPARTS}${1}|"
fi
}
mntfunc() {
MNT_T="$1" #ex: vfat
MNT_DEV="$2" #ex: /dev/sda1
MNT_DIR="$3" #ex: /mnt/sda1
MNT_O='noatime'
MNT_DSK="${MNT_DEV:5:3}"
if [ "$PTRIM" = "yes" -a "$MNT_DSK" != "" -a "$(cat /sys/block/$MNT_DSK/queue/rotational)" = "0" ];then
if [ "$MNT_T" = "ext4" -o "$MNT_T" = "f2fs" ];then
MNT_O="${MNT_O},discard"
fi
fi
[ "$PFSCKP" = "yes" ] && fsck_func "$MNT_DEV" "$MNT_T"
case $MNT_T in
ntfs)
ntfs-3g $MNT_DEV $MNT_DIR -o umask=0,no_def_opts,noatime,rw,silent 2>/dev/null #default is rw. 130211 add silent.
ntfsRETVAL=$?
[ $ntfsRETVAL -eq 0 ] && return 0
if [ $ntfsRETVAL -eq 14 ];then
echo -e "\\033[1;31m${L_WINDOWS_HIBERNATED}\\033[0;39m" >/dev/console #31=red
return 14
else
ntfs-3g $MNT_DEV $MNT_DIR -o umask=0,no_def_opts,noatime,rw,force,silent 2>/dev/null #130211 add silent.
fi
;;
vfat) mount -t $MNT_T -o $VFAT_OUT_PARAM $MNT_DEV $MNT_DIR ;;
exfat) mount.exfat-fuse -o $MNT_O $MNT_DEV $MNT_DIR ;;
*) mount -t $MNT_T -o $MNT_O $MNT_DEV $MNT_DIR ;;
esac
return $?
}
check_status() #args: [-critical] $RET_VAL "$ERROR_MSG"
{
ERROR_CRITICAL=""
[ "$1" = "-critical" ] && { ERROR_CRITICAL="yes" ; shift; }
RET_VAL=$1
shift
ERROR_MSG="$@"
if [ $RET_VAL -eq 0 ] ; then
echo -en "\\033[74G" >/dev/console #move to column 72. 110426: 74
echo -e "\\033[1;32m${L_DONE}\\033[0;39m" >/dev/console #32=green
else
echo -en "\\033[72G" >/dev/console #move to column 72.
echo -e "\\033[1;31m${L_FAILED}\\033[0;39m" >/dev/console #31=red
if [ "$FLAG_NO_TIMEOUT" ] ; then
FLAG_NO_TIMEOUT=
return
fi
echo -e "\\033[1;35m${L_DUMPING_BOOTINIT_LOG}\\033[0;39m" >/dev/console #35=purple
echo -en "\\033[1;31m" >/dev/console #31=red
cat /tmp/bootinit.log | tail -n 4 >/dev/console
echo -en "\\033[0;39m" >/dev/console
echo -e "\\033[1;35m${L_DUMPING_KERNEL_LOG}\\033[0;39m" >/dev/console #35=purple
echo -en "\\033[1;31m" >/dev/console #31=red
dmesg | tail -n 4 >/dev/console
echo -en "\\033[0;39m" >/dev/console
#exit to initial ramdisk shell...
[ "$RDSH" != "" ] && exec /bin/sh >/dev/console 2>&1
if [ "$ERROR_CRITICAL" = "yes" ] ; then
echo -en "\\033[1;35m" >/dev/console #35=purple
[ "$ERROR_MSG" != "" ] && echo "*** $ERROR_MSG" >/dev/console
echo "*** ${L_ERROR_IS_TOO_CRITICAL}" >/dev/console
echo -en "\\033[0;39m" >/dev/console
echo -e "\\033[1;32m*** $L_DEBUG_SAVE\\033[0;39m" >/dev/console
exec /bin/sh >/dev/console 2>&1
else
echo "${L_PAUSING_60_SECONDS}" >/dev/console
sleep 60
fi
fi
}
decode_spec() {
#${1} = an sfs spec e.g. sdb2:/pup/test_it.sfs
ONE_BP_ID=""; ONE_BP_FN=""
[ "${1}" ] || return
case "${1}" in
*:*) ONE_BP_ID="${1%%:*}"; ONE_BP_FN="${1#*:}" ;;
*) ONE_BP_ID="${1}" ;;
esac
if [ "$ONE_BP_FN" ];then
case "$ONE_BP_FN" in
*/*) [ "${ONE_BP_FN:0:1}" != "/" ] && ONE_BP_FN="/$ONE_BP_FN" ;;
*) ONE_BP_FN="$PSUBDIR/$ONE_BP_FN" ;;
esac
fi
}
decode_id() {
ONE_PART=""
[ "${1}" ] || return
if [ "$(echo -n ${1} | grep -E '^[a-z]+[0-9]')" -a "$(grep -m1 "${1}$" /proc/partitions)" ];then
ONE_PART="$1" #is a real partition
else
[ "$BLKIDOUT" ] || BLKIDOUT="$(blkid)"
ONE_PART="$(echo "$BLKIDOUT" | grep -m1 -E " LABEL=.${1}| UUID=.${1}" | cut -f1 -d: | cut -f3 -d/)" #is LABEL or UUID
fi
}
decode_other_ids() {
#get ONE_PART from DEV or ID specified in sfs boot params
decode_id "$Z_BP_ID"
[ "$ONE_PART" ] && { Z_PART="$ONE_PART"; Z_BP_ID=""; }
decode_id "$F_BP_ID"
[ "$ONE_PART" ] && { F_PART="$ONE_PART"; F_BP_ID=""; }
decode_id "$A_BP_ID"
[ "$ONE_PART" ] && { A_PART="$ONE_PART"; A_BP_ID=""; }
decode_id "$Y_BP_ID"
[ "$ONE_PART" ] && { Y_PART="$ONE_PART"; Y_BP_ID=""; }
decode_id "$SAVE_BP_ID"
[ "$ONE_PART" ] && { SAVEPART="$ONE_PART"; PSAVEPART="$ONE_PART"; SAVE_BP_ID=""; }
}
log_part_id() {
# "$1" - partition id - ex: Work or sdc4
echo "Partition ${1} not found."
}
ensure_mounted() {
# "$1" - partition - ex: sda3
# "$2" - mountpoint - ex: /mnt/pdrv
ONE_MP="$(mount | grep -m1 "/dev/${1} " | cut -f 3 -d ' ')"
[ "$ONE_MP" ] && return
ONE_FS="$(echo "$HAVE_PARTS" | grep -m1 "${1}|" | cut -f 2 -d '|')"
ONE_MP="${2}"
[ -d "$ONE_MP" ] || mkdir -p $ONE_MP
mntfunc $ONE_FS /dev/${1} $ONE_MP #-t $ONE_FS /dev/$ONE_PART $ONE_MP
if [ $? -ne 0 ] ; then
sleep 3 # usb optical drive showing as /sys/block/sr0, but won't mount, needs more delay...
mntfunc $ONE_FS /dev/${1} $ONE_MP
[ $? -ne 0 ] && { echo "${1} on $ONE_MP as $ONE_FS mount failed."; ONE_MP=""; return 1; }
fi
# fsckme.flg is created by rc.sysinit and deleted by rc.shutdown
# this flag will be set for any prior improper shutdown. if have lots of installations
# of puppy on the pc, the flag may not even be for this install of puppy, however, this is
# the simplest implementation...
if [ -f ${ONE_MP}/fsckme.flg ] ; then
#sda1,ext3,/PUPPYBOOT/precise/precisesave.4fs
FSCKME="`cat ${ONE_MP}/fsckme.flg`"
echo -e "${ONE_MP}/fsckme.flg\n $FSCKME"
FSCK_PART="$(echo "$FSCKME" | cut -f 1 -d ",")"
FSCK_EXT="$(echo "$FSCKME" | cut -f 2 -d ",")"
FSCK_SAVEFILE="$(echo "$FSCKME" | cut -f 3 -d ",")"
rm -f ${ONE_MP}/fsckme.flg
[ "$FSCK_SAVEFILE" ] && PFSCK="yes"
[ "$PFSCKP" = "yes" ] && return # boot param, partition already fsck'ed
case ${FSCK_EXT} in ext2|ext3|ext4|vfat|msdos|exfat)
umount ${ONE_MP}
[ "$FSCKME" ] && fsck_func /dev/${FSCK_PART} ${FSCK_EXT}
ensure_mounted "$1" "$2" ;;
esac
fi
}
ensure_save_mounted() {
SAVE_MP="/mnt/dev_save"
ensure_mounted "$SAVEPART" "$SAVE_MP"
if [ "$ONE_MP" ];then
if [ "$ONE_MP" != "$SAVE_MP" ];then
#ensure SAVEPART is mounted on /mnt/dev_save
[ -d "$SAVE_MP" ] || mkdir -p $SAVE_MP
echo "mount -o move $ONE_MP $SAVE_MP" #debug
mount -o move $ONE_MP $SAVE_MP
fi
SAVE_FS="$ONE_FS"
else
SAVE_MP=""
fi
}
find_drv_file() {
# "$1" - specified filename - ex: /pup/mydrv-1.2.3.sfs
# "$2" - default filename - ex: adrv_tahr_6.0.5.sfs
ONE_FN=""
[ "${1}" ] || [ "${2}" ] || return
if [ "${1}" ];then
ONE_TRY_FN="${1}"
[ "${ONE_TRY_FN:$((${#ONE_TRY_FN} - 1))}" = "/" ] && ONE_TRY_FN="${ONE_TRY_FN}${2}" #last char
else
ONE_TRY_FN="${PSUBDIR}/${2}"
fi
[ -f "${ONE_MP}${ONE_TRY_FN}" ] && ONE_FN="$ONE_TRY_FN"
}
find_onepupdrv() {
# "$1" - partition - ex: sda3
# "$2" - specified filename - ex: /pup/mydrv-1.2.3.sfs
# "$3" - default filename - ex: adrv_tahr_6.0.5.sfs
# "$4" - prefix for "drv" mountpoint - ex: a
ONE_FN=""
[ "${2}" ] || [ "${3}" ] || return
[ "${4}" ] || return
if [ "${1}" ];then
ONE_PART="${1}"
else
ONE_PART="$P_PART"
fi
[ "$ONE_PART" ] || return
ensure_mounted "$ONE_PART" "/mnt/${4}drv"
[ "$ONE_MP" ] || return
find_drv_file "${2}" "${3}"
[ "$ONE_FN" = "" -a "${2}" ] && echo "$ONE_PART, $ONE_TRY_FN file not found."
}
setup_loop_sfs() {
# "$1" - sfs filename - ex: /mnt/dev_save/puppy/tahr/puppy_tahr_6.0.5.sfs
ONE_LOOP="$(losetup -f)"
losetup $LO_OPT $ONE_LOOP ${1}
[ $? -eq 0 ] || { LO_OPT=""; losetup $LO_OPT $ONE_LOOP ${1}; }
}
load_sfs_file() {
[ "$LOADMSG" ] && echo -n "$(printf "${L_LOADING_FILE}" "$ONE_BASENAME" "$LOADMSG")" > /dev/console
if [ "$COPY2RAM" = "" ];then
COPY2RAM="no"
#if there's heaps of ram, copy puppy.sfs to a tmpfs...
#v405 fast media plus more than 256MB ram then definitely worth copying to ram...
SIZESFSK=$(du -k $ONE_FN | cut -f 1)
SIZESFSK=$(($SIZESFSK + 1000)) #some slack.
MINRAM2CPY=$(($SIZESFSK * 2)) #100222 technosaurus: in case of very big puppies.
#decide whether to copy .sfs's to ram
[ "$PNOCOPY" = "yes" ] || COPYCONTENDER='yes'
[ "$PCOPY" = "yes" ] && COPYCONTENDER='yes'
[ "$PRAMONLY" = "yes" ] && COPYCONTENDER='yes'
[ "$COPYCONTENDER" = "yes" ] && [ $RAMSIZE -gt 400000 ] && [ $RAMSIZE -gt $MINRAM2CPY ] && COPY2RAM="yes"
fi
if [ "$COPY2RAM" = "yes" ];then
SIZEZK=$(du -k $ONE_FN | cut -f 1)
TFREEK=$(df | grep -m1 ' /mnt/tmpfs' | tr -s ' ' | cut -f 4 -d ' ')
if [ $TFREEK -gt $SIZEZK ];then
if [ "$ONE_MP" = "" ];then #101101 humongous initrd.
mv -f $ONE_FN /mnt/tmpfs/
else
[ "$LOADMSG" ] && [ "$COPYMSG" ] && echo -en " \\033[1;35m${COPYMSG}\\033[0;39m" > /dev/console #purple.
TOTAL_SIZEK_SFS_RAM=$(($TOTAL_SIZEK_SFS_RAM + $SIZEZK))
cp -af $ONE_FN /mnt/tmpfs/
fi
sync
setup_loop_sfs /mnt/tmpfs/$ONE_BASENAME
else
setup_loop_sfs $ONE_FN
[ "$ONE_PART" != "rootfs" ] && KEEPMOUNTED="${KEEPMOUNTED}${ONE_PART} "
fi
else
setup_loop_sfs $ONE_FN
[ "$ONE_PART" != "rootfs" ] && KEEPMOUNTED="${KEEPMOUNTED}${ONE_PART} "
fi
SFS_MP="/pup_${ONE_SFX}"
[ "$ONE_SFX" = "p" ] && SFS_MP="/pup_ro2"
[ -d "$SFS_MP" ] || mkdir $SFS_MP
mount -r -t squashfs -o noatime $ONE_LOOP $SFS_MP > /dev/console 2>&1
STATUS=$?
[ $STATUS -eq 0 ] && ONE_LAYER="$SFS_MP=rr"
[ "$LOADMSG" ] && check_status $STATUS
}
setup_onepupdrv() {
# "$1" - sfs spec - ex: sdb2,ext4,/pup/mydrv-1.2.3.sfs
# "$2" - suffix for "pup_" branch directory - ex: a
# "$3" - prepend after rw layer indicator - ex: p
ONE_LAYER=""
[ "$1" ] || return 1
[ "$2" ] || return 1
ONE_PART="$(echo "${1}" | cut -f 1 -d ',')"
[ "$ONE_PART" ] || return 1
ONE_REL_FN="$(echo "${1}" | cut -f 3 -d ',')"
[ "$ONE_REL_FN" ] || return 1
ONE_SFX="${2}"
ONE_PREP="${3}"
if [ "$ONE_PART" = "rootfs" ];then #humongous initrd.
ONE_MP="" #actually it's '/'.
COPY2RAM='yes' #actually it is already in ram, but load_sfs_file code puts it in a tmpfs.
else
if [ "$ONE_PART" = "$P_PART" ];then
ONE_MP="$P_MP"
else
ONE_MP="$(mount | grep -m1 "/dev/$ONE_PART " | cut -f 3 -d ' ')"
[ "$ONE_MP" ] || return 2
fi
fi
ONE_FN="${ONE_MP}${ONE_REL_FN}"
ONE_BASENAME="$(basename $ONE_REL_FN)"
#validate sfs here
[ -s "$ONE_FN" ] || return 3 #sfs not Ok
load_sfs_file
[ "$ONE_LAYER" ] || return 4 #sfs mount failed
if [ "$ONE_PREP" ];then
echo "mount -o remount,add:1:$ONE_LAYER /pup_new" #debug
mount -o remount,add:1:$ONE_LAYER /pup_new
[ $? -eq 0 ] || return 5
else
echo "mount -o remount,append:$ONE_LAYER /pup_new" #debug
mount -o remount,append:$ONE_LAYER /pup_new
[ $? -eq 0 ] || return 5
fi
NEWUNIONRECORD="${NEWUNIONRECORD}${ONE_BASENAME} "
return 0
}
load_ext_file() { #ex: stretchsave.4fs
SAVE_SZ_FN=""
RESIZE_FN="$(dirname $SAVE_FN)/pupsaveresizenew.txt"
#delete following line when resize file location is fixed
[ -f "$RESIZE_FN" ] || RESIZE_FN="${SAVE_MP}/pupsaveresizenew.txt"
#-- resize savefile?.. see /usr/sbin/resizepfile.sh
if [ -f "$RESIZE_FN" ] ; then
#(1) resize extX file. see below (2)
. $RESIZE_FN #$PUPSAVEFILEX $KILOBIG
if [ "$PUPSAVEFILEX" = "$SAVE_REL_FN" ] ; then
if [ ! -e /bin/resize2fs ];then
echo -en "\\033[1;31m" > /dev/console
echo -n "$(printf "${L_CANNOT_RESIZE_PUPSAVE}" "$PUPSAVEFILEX")" > /dev/console #31=red
echo -en "\\033[0;39m" > /dev/console
rm -f $RESIZE_FN
else
SAVE_SZ_FN="$SAVE_FN"
rm -f $RESIZE_FN
echo > /dev/console
echo -n "$(printf "${L_INCREASING_PUPSAVE}" "$PUPSAVEFILEX" "$KILOBIG")" >/dev/console
dd if=/dev/zero bs=1024 count=$KILOBIG >> $SAVE_SZ_FN
sync
fi
fi
fi
#--
# is the ${DISTRO_FILE_PREFIX}save encrypted?...
SFFS=$(blkid "$SAVE_FN" | grep -o ' TYPE=".*' | cut -f 2 -d '"')
#--
if [ "$SFFS" = "crypto_LUKS" ] ; then
ln -sv /pup_new/lib/modules/${KERNELVER} /lib/modules/${KERNELVER}
modprobe dm-crypt || ERROR_M_DESC="Or maybe the kernel doesn't properly support dm-crypt"
modprobe xts || ERROR_M_DESC="Or maybe the kernel doesn't properly support dm-crypt"
while [ 1 ]
do
ONE_LOOP="$(losetup -f)"
#mount encrypted savefile
echo >/dev/console
MYPASS=$(dialog --backtitle "$DISTRODESC" --stdout --title "Password required" --passwordbox "$L_PASSWORD_MSG_1 $L_PASSWORD_MSG_2" 0 0 2>/dev/console) ; clear
losetup $ONE_LOOP $SAVE_FN
echo -n "$MYPASS" | cryptsetup luksOpen -v $ONE_LOOP savefile -
if [ $? -ne 0 ] ; then
cryptsetup luksClose savefile
losetup -d $ONE_LOOP
dialog --backtitle "$DISTRODESC" --title "Wrong password" --ok-label "Retry" --yes-label "Retry" \
--cancel-label "Drop to console" --no-label "Drop to console" \
--extra-button --extra-label "Reboot" --yesno "You entered a wrong password (most likely). $ERROR_M_DESC" 0 0 &>/dev/console
case $? in
0) continue ;;
3) reboot ;;
*) exec /bin/sh >/dev/console 2>&1 ;;
esac
fi
ONE_LOOP_PREV=$ONE_LOOP
ONE_LOOP=/dev/mapper/savefile #hack
SFFS=ext4
break
done
else # unencrypted savefile
if echo "$SAVE_FN" | grep -q '_crypt' ; then
dialog --backtitle "$DISTRODESC" --msgbox "Your savefile name contains: *_crypt*. It's probably an old cryptoloop savefile. No longer supported. Will not use it. However you can open ${PUPSAVE##*/} to see its contents by clicking on it (filemnt)" 0 0 &>/dev/console
echo 'Warning: old cryptoloop savefile... setting PUPSAVE=""' #debug
FLAG_NO_TIMEOUT=1
PUPSAVE=""
return
fi
ONE_LOOP="$(losetup -f)"
losetup $ONE_LOOP $SAVE_FN
fi
#--
if [ "$PFSCK" = "yes" ] ; then
echo "" > /dev/console
fsck_func "$ONE_LOOP" "$SFFS"
fi
#--
if [ "$SAVE_SZ_FN" ] ; then
#(2) resize extX filesystem - fill extX file. see above (1)
[ "$PFSCK" != "yes" ] && e2fsck -y "$ONE_LOOP" #debug
resize2fs -pf "$ONE_LOOP" #no size, will fill all of file.
echo -n "$(printf "${L_CONTINUING_LOADING}" "$PUPSAVEFILE")" > /dev/console
sync
fi
#--
[ -d "$SAVE_LAYER" ] || mkdir $SAVE_LAYER
echo "mount -t $SFFS -o noatime $ONE_LOOP $SAVE_LAYER" #debug
mount -t $SFFS -o noatime $ONE_LOOP $SAVE_LAYER
if [ $? -ne 0 ] ; then
echo 'Warning: setting PUPSAVE=""' #debug
PUPSAVE=""
fi
}
setup_save_file(){
SAVE_REL_FN="$(echo "$PUPSAVE" | cut -f 3 -d ',')"
if [ -f "${SAVE_MP}${SAVE_REL_FN}" ];then #savefile
PUPSAVE_SIZE="$(fx_format_bytes $(stat -c %s "${SAVE_MP}${SAVE_REL_FN}"))"
echo -n "$(printf "${L_LOADING_PUPSAVE_FILE}" "$SAVE_REL_FN" "$SAVEPART" "$PUPSAVE_SIZE")" > /dev/console
else
echo -n "$(printf "${L_LOADING_PUPSAVE}" "$SAVE_REL_FN" "$SAVEPART")" > /dev/console
fi
rm -r -f "$SAVE_LAYER"
SAVE_FN="${SAVE_MP}${SAVE_REL_FN}"
if [ -f "$SAVE_FN" ];then #savefile. ex: stretchsave.4fs
echo "--SAVEFILE-- $SAVE_FN" #debug
load_ext_file
elif [ -d "$SAVE_FN" ];then #savefolder
echo "--SAVEFOLDER-- $SAVE_FN" #debug
ln -sv "$SAVE_FN" "$SAVE_LAYER"
else
PUPSAVE=""
fi
#[ "$PUPSAVE" ] && decrypt directory at SAVE_LAYER
if [ "$PUPSAVE" ];then
SAVE_NAME="$(basename $SAVE_REL_FN)"
#- fix for empty pupsaves (missing /initrd/DISTRO_SPECS)
if [ ! -f "$SAVE_LAYER/initrd/DISTRO_SPECS" ] ; then
touch /tmp/rc_update_force_pm5 # see /etc/rc.d/rc.update
PCLEAN=""
fi
#-
if [ "$PCLEAN" != "yes" -a -f "$SAVE_LAYER/initrd/DISTRO_SPECS" ];then
validate_pupsave_upgrade /DISTRO_SPECS $SAVE_LAYER/initrd/DISTRO_SPECS
case $? in
0) PCLEAN="yes" ;; #(dialog) perform upgrade
1) PUPSAVE="" ;; #(dialog) do not perform upgrade
esac
fi
if [ "$PCLEAN" = "yes" ];then
#do upgrade processing
touch /tmp/version_update_flag
CURDIR="$(pwd)"
cd "$SAVE_LAYER"
#delete critical system files
#keep rc.local - user customisations and/or fixes.
echo "Removing $(ls ./lib/modules/$KERNELVER/modules.*)"
rm -f ./lib/modules/$KERNELVER/modules.*
RC_STUFF="$(ls ./etc/rc.d/rc.* | grep -v "/rc.local$" | tr '\n' ' ')"
rm -fv $RC_STUFF
rm -fv ./etc/rc.d/funct*
#iterate over all files in save
for ONE_FILE in $(find . \( -type f -or -type l \) -print); do
ONE_BASE="${ONE_FILE##*/}" #basename
if [ "${ONE_BASE:0:4}" = ".wh." ]; then #remove most whiteout files
[ "${ONE_BASE:4:4}" = ".wh." ] && continue #internal aufs files
[ "${ONE_FILE%/*}" = "./root/.config/autostart" ] && continue #keep autostart changes
echo "Removing ${ONE_FILE}"
rm -f "$ONE_FILE" #remove whiteout file
fi
done
cd "$CURDIR"
sync
fi
check_status 0
else
check_status 1
fi
if [ ! "$PUPSAVE" ] ; then
echo "No pupsave. Setting PUPMODE 5" #debug
if ! [ -L $SAVE_LAYER ] ; then # $SAVE_LAYER is a true mp
echo -e "Unmounting savefile\numount -d $SAVE_LAYER" #debug
umount -d $SAVE_LAYER
fi
PUPMODE=5
SAVE_MP=""
SAVE_LAYER=""
fi
}
copy_folders() { #SAVE_LAYER=/pup_ro1
echo -e "\n-------------------- copy_folders" #debug
echo "SAVE_MP=$SAVE_MP"
DESTDIR="/mnt/tmpfs/pup_ro1"
[ -d "$DESTDIR" ] || mkdir -p $DESTDIR
rm -r -f "$SAVE_LAYER"
SAVE_FN="$DESTDIR"
ln -s $DESTDIR $SAVE_LAYER
#BKFOLDERS now set in check for pupmode=77
BKLASTFOLDER="$(echo "${BKFOLDERS}" | head -n 1)"
#a boot option allows ignore last n sessions, also need to create a badlist...
if [ "$PIGNORELAST" ];then
BKBADLIST="$(echo "${BKFOLDERS}" | head -n ${PIGNORELAST})"
if [ -f ${SAVE_MP}/${BKLASTFOLDER}/.badfolders ];then
cp ${SAVE_MP}/${BKLASTFOLDER}/.badfolders ${DESTDIR}/
if [ $? -ne 0 ];then
#fallback, in case last folder badly corrupted...
BKPREVFOLDER="$(echo "${BKFOLDERS}" | head -n 2 | tail -n 1)"
[ -f ${SAVE_MP}/${BKPREVFOLDER}/.badfolders ] && cp ${SAVE_MP}/${BKPREVFOLDER}/.badfolders ${DESTDIR}/
fi
fi
echo "$BKBADLIST" >> ${DESTDIR}/.badfolders
#note, rc.shutdown and savesession-dvd 'touch' this file so it will get saved.
sync
else
[ -f ${SAVE_MP}/${BKLASTFOLDER}/.badfolders ] && cp ${SAVE_MP}/${BKLASTFOLDER}/.badfolders ${DESTDIR}/
fi
[ -f ${DESTDIR}/.badfolders ] && BKBADLIST="$(cat ${DESTDIR}/.badfolders | tr "\n" " ")"
echo "BKBADLIST=${BKBADLIST}" #debug
BKFOLDERS="$(echo -n "${BKFOLDERS}" | tr "\n" " ")"
for ONEFOLDER in ${BKFOLDERS}
do
if [ "$(echo -n "$BKBADLIST" | grep "${ONEFOLDER}")" != "" -o -L "${SAVE_MP}/${ONEFOLDER}" ];then
echo "$(printf "${L_FOLDER_MARKED_BAD}" "${ONEFOLDER}")" >/dev/console
continue #ignore bad folder.
fi
echo "$ONEFOLDER" #debug
echo -n "$(printf "${L_LOADING_FROM_CD}" "${ONEFOLDER}")" >/dev/console
#need to be careful not to overfill the ramdisk...
FREERAMDISK=$(df 2>/dev/null | grep /mnt/tmpfs | head -n 1 | tr -s " " | cut -f 4 -d " ")
SIZEFOLDER=$(du -k -s ${SAVE_MP}/${ONEFOLDER} | cut -f 1)
SIZEARCHIVE=0
if [ -d ${SAVE_MP}/${ONEFOLDER}/archive ];then
SIZEARCHIVE=$(du -k -s ${SAVE_MP}/${ONEFOLDER}/archive | cut -f 1)
fi
SIZESOURCE=$(expr $SIZEFOLDER - $SIZEARCHIVE)
if [ $FREERAMDISK -gt $SIZESOURCE ];then
#well, -u will only copy if files newer, so less stuff may get copied than calc'd above.
#need to copy everything except archive folder...
[ -d ${SAVE_MP}/${ONEFOLDER}/bin ] && cp -a -u ${SAVE_MP}/${ONEFOLDER}/bin ${DESTDIR}/
[ -d ${SAVE_MP}/${ONEFOLDER}/sbin ] && cp -a -u ${SAVE_MP}/${ONEFOLDER}/sbin ${DESTDIR}/
[ -d ${SAVE_MP}/${ONEFOLDER}/etc ] && cp -a -u ${SAVE_MP}/${ONEFOLDER}/etc ${DESTDIR}/
[ -d ${SAVE_MP}/${ONEFOLDER}/lib ] && cp -a -u ${SAVE_MP}/${ONEFOLDER}/lib ${DESTDIR}/
[ -d ${SAVE_MP}/${ONEFOLDER}/opt ] && cp -a -u ${SAVE_MP}/${ONEFOLDER}/opt ${DESTDIR}/
[ -d ${SAVE_MP}/${ONEFOLDER}/var ] && cp -a -u ${SAVE_MP}/${ONEFOLDER}/var ${DESTDIR}/
[ -d ${SAVE_MP}/${ONEFOLDER}/root ] && cp -a -u ${SAVE_MP}/${ONEFOLDER}/root ${DESTDIR}/
[ -d ${SAVE_MP}/${ONEFOLDER}/home ] && cp -a -u ${SAVE_MP}/${ONEFOLDER}/home ${DESTDIR}/
[ -d ${SAVE_MP}/${ONEFOLDER}/usr ] && cp -a -u ${SAVE_MP}/${ONEFOLDER}/usr ${DESTDIR}/
[ -f ${DESTDIR}/root/.XLOADED ] && rm -fv ${DESTDIR}/root/.XLOADED #toxic
[ -f ${DESTDIR}/var/local/shared/.XLOADED ] && rm -fv ${DESTDIR}/var/local/shared/.XLOADED #toxic
cp -a -u ${SAVE_MP}/${ONEFOLDER}/*.sfs ${DESTDIR}/ 2>/dev/null
#delete deleted files (.wh.filename)... 110212 screen out .wh..wh..opq
WHITEOUTS="$(find ${DESTDIR} -xdev -type f -name .wh.* | grep -v '__dir_opaque' | grep -v '.wh..wh.')" #110212
echo "$WHITEOUTS" | while read DELWHITE ; do
DELFILE="$(echo -n "$DELWHITE" | sed -e 's/\.wh\.//g')"
if [ -e "$DELFILE" ];then
[ "$PDEBUG" ] && echo "Deleting $DELFILE" #debug
rm -rf "$DELFILE"
rm -rf "$DELWHITE"
fi
done
check_status 0 #display 'done' for each folder loaded.
else
printf "${L_RAM_DISK_FULL}\n" "${ONEFOLDER}"
check_status 1
break
fi
done
sync
echo -e "--------------------\n" # debug
}
prepend_dir() { #SAVE_LAYER=/pup_ro1
rm -rf ${SAVE_LAYER}/tmp #in case last boot was pupmode=12
#adjust stack
echo "mount -o remount,add:1:${SAVE_LAYER}=ro+wh /pup_new" #debug
mount -o remount,add:1:${SAVE_LAYER}=ro+wh /pup_new #ro+wh = Readonly branch and it has/might have whiteouts on it
if [ $? -eq 0 ];then
[ $PUPMODE -ne 77 ] && KEEPMOUNTED="${KEEPMOUNTED}${SAVEPART} "
[ "$SAVE_NAME" ] && NEWUNIONRECORD="$SAVE_NAME $NEWUNIONRECORD"
else
printf "${L_ADDING_SAVE_LAYER_FAILED}\n" "$SAVE_LAYER"
fi
}
replace_dir() { #SAVE_LAYER=/pup_rw
#setup empty /tmp on tmpfs for in stack
rm -rf ${SAVE_LAYER}/tmp
#adjust stack
echo "mount -o remount,prepend:${SAVE_LAYER}=rw,mod:/mnt/tmpfs/pup_rw=ro,del:/mnt/tmpfs/pup_rw /pup_new" #debug
mount -o remount,prepend:${SAVE_LAYER}=rw,mod:/mnt/tmpfs/pup_rw=ro,del:/mnt/tmpfs/pup_rw /pup_new
if [ $? -eq 0 ];then
rm -rf /mnt/tmpfs/pup_rw
KEEPMOUNTED="${KEEPMOUNTED}${SAVEPART} "
[ "$SAVE_NAME" ] && NEWUNIONRECORD="$SAVE_NAME $NEWUNIONRECORD"
else
printf "${L_ADDING_SAVE_LAYER_FAILED}\n" "$SAVE_LAYER"
fi
}
set_fs_linux() {
# "$1" - file system type - ex: ext4
ONE_FS_IS_LINUX=""
case ${1} in
ext2|ext3|ext4|reiserfs|minix|f2fs) ONE_FS_IS_LINUX="yes" ;;
esac
}
find_save_file() {
# "$1" - mount point - ex: /mnt/pdrv
# "$2" - partition name - ex: sdb2
# "$3" - file system type - ex: ext4
if [ "$SAVE_BP_DIR" ];then
SAVE_DIR="$SAVE_BP_DIR"
else
SAVE_DIR="${PSUBDIR}/"
fi
SAVE_FILES="$(ls -d ${1}${SAVE_DIR}${DISTRO_FILE_PREFIX}save* 2>/dev/null)"
for ONE_SAVE in $SAVE_FILES;do
#validate savefiles here
IS_OK=""
case $ONE_SAVE in
*.2fs|*.3fs|*.4fs)
[ -s "$ONE_SAVE" ] && IS_OK="yes"
;;
*.BKP-*) #written by /usr/sbin/pupsave-backup
case $ONE_SAVE in
*.2fs*|*.3fs*|*.4fs*) IS_OK="$PSAVEBKP" ;;
*) [ "$ONE_FS_IS_LINUX" = "yes" ] && IS_OK="$PSAVEBKP" ;;
esac
;;
*)
[ "$ONE_FS_IS_LINUX" = "yes" ] && [ -d "$ONE_SAVE" ] && IS_OK="yes"
;;
esac
[ "$IS_OK" = "yes" ] && PUP_SAVES="${PUP_SAVES}${2},${3},${SAVE_DIR}$(basename $ONE_SAVE)
"
done
PUP_SAVES="$(echo "$PUP_SAVES")" #remove trailing newline char
echo "MENU_MAX_PUPSAVES=${MENU_MAX_PUPSAVES}" #debug
if [ "$MENU_MAX_PUPSAVES" ] ; then
PUP_SAVES="$(echo "$PUP_SAVES" | head -n $MENU_MAX_PUPSAVES)"
fi
}
search_func() {
[ "$PDEBUG" -a "$LOOK_SAVE" ] && echo "3: filename=${PSUBDIR}/${DISTRO_FILE_PREFIX}save"
[ "$PDEBUG" -a "$LOOK_PUP" ] && echo "3: PSUBDIR=$PSUBDIR P_BP_FN=$P_BP_FN P_DEF_FN=$P_DEF_FN"
echo "HAVE_PARTS='${HAVE_PARTS}'" #debug
if [ "${1}" ];then
echo "param='${1}'" #debug
TRY_PARTS_FIRST="$(echo "$HAVE_PARTS" | grep -E "${1}")"
TRY_PARTS_LAST="$(echo "$HAVE_PARTS" | grep -Ev "${1}")"
TRY_PARTS="$TRY_PARTS_FIRST
$TRY_PARTS_LAST"
else
TRY_PARTS="$HAVE_PARTS"
fi
echo "TRY_PARTS='${TRY_PARTS}'" #debug
[ "$TRY_PARTS" ] || return
for ONETRY in $TRY_PARTS;do
ONE_PART="$(echo -n "$ONETRY" | cut -f 1 -d '|')"
[ "$PDEBUG" ] && echo "4: ONE_PART=$ONE_PART"
ensure_mounted "$ONE_PART" "/mnt/pdrv"
if [ "$ONE_MP" ];then
if [ "$LOOK_SAVE" -a "$SAVEPART" = "" ];then
set_fs_linux "$ONE_FS"
find_save_file "$ONE_MP" "$ONE_PART" "$ONE_FS"
if [ "$PUP_SAVES" ];then
SAVEPART="$ONE_PART"
[ "$PDEBUG" ] && echo "5: ONE_PART=$ONE_PART filename=${PSUBDIR}/${DISTRO_FILE_PREFIX}save"
fi
fi
if [ "$LOOK_PUP" ];then
find_drv_file "$P_BP_FN" "$P_DEF_FN"
if [ "$ONE_FN" ];then
PDRV="$ONE_PART,$ONE_FS,$ONE_FN"
P_MP="$ONE_MP"
P_PART="$ONE_PART"
[ "$PDEBUG" ] && echo "5: ONE_PART=$ONE_PART PSUBDIR=$PSUBDIR P_BP_FN=$P_BP_FN P_DEF_FN=$P_DEF_FN"
break;
fi
fi
umount $ONE_MP
fi
done
}
get_part_info() {
probedisk -hr > /tmp/probedisk.log
probepart -hr > /tmp/probepart.log
sed 's%|.*%% ; s%.*/%%' /tmp/probedisk.log > /tmp/ALLDRVS0
HAVE_PARTS="$(cat /tmp/probepart.log | cut -f 1-2 -d '|' | sed -e 's%/dev/%%')"
[ "$PDEBUG" ] && echo "$HAVE_PARTS" > /tmp/HAVE_PARTS
}
wait_for_usb() {
[ -e /tmp/flag-usb-ready ] && return
echo -n "${L_WAITING_FOR_USB}" > /dev/console
/sbin/wait4usb
get_part_info
BLKIDOUT=""
check_status 0
}
umount_unneeded() {
MTD_PARTS="$(mount | cut -f1 -d' ' | grep '^/dev' | grep -v loop | cut -f3 -d'/')"
for ONE_PART in $MTD_PARTS;do
[ "$(echo -n "$KEEPMOUNTED" | grep "$ONE_PART")" ] || umount /dev/$ONE_PART
done
}
fatal_error() {
# "$1" - message - ex: puppy_tahr_6.0.5.sfs not found
# "$2" - pre-status-message - ex: Finding puppy
KEEPMOUNTED=""
umount_unneeded
[ "${2}" ] && echo -n "${2}" > /dev/console
check_status -critical 1 "$1"
}
#=============================================================
# MAIN
#=============================================================
clear #clear the screen.
echo -en "\\033[0;34m***\\033[0;37m ${DISTRO_NAME} ${DISTRO_VERSION}"
echo -en "\\033[0;34m -\\033[0;37m Linux ${KERNELVER} "
echo -en "\\033[0;31m[\\033[0;37m`uname -m`\\033[0;31m]"
echo -e "\\033[0;34m ***\\033[0;39m"
#[ ! "$LOGLEVEL" ] && exec 1>/tmp/bootinit.log 2>&1 #remove o/p from console. v2.22 loglevel added.
#exec 1>/dev/console 2>&1 #s243a
[ ! -f /bin/resize2fs ] && touch /tmp/no_resize2fs
# sets PLANG, PKEYS, VFAT_OUT_PARAM, FONTMAP, KMAP, CODEPAGE
[ -f /sbin/set_plang ] && . /sbin/set_plang
#pmedia= usbflash|usbhd|usbcd|ataflash|atahd|atacd|atazip|scsihd|scsicd|cd
[ $pmedia ] && PMEDIA=$pmedia #boot parameter, broad category of boot media. ex: cd.
[ $psubdir ] && PSUBDIR=$psubdir #boot parameter, directory for puppy files. ex: puppy220
[ $psavemark ] && PSAVEMARK=$psavemark #100913 partition number that has/will-have save-file.
[ $PSUBDIR ] && [ "${PSUBDIR:0:1}" != "/" ] && PSUBDIR="/${PSUBDIR}" #add leading /.
[ $pdev1 ] && PDRV=$pdev1 #boot parameter, partition have booted off. ex: hda3
#100915 requested by technosaurus (formats get changed further down)...
[ $pdrv ] && PDRV=$pdrv #format partition:<path><filename> ex: sda2:/slacko/puppy_slacko_6.3.0.sfs
[ $pupsfs ] && PDRV=$pupsfs
[ $zdrv ] && ZDRV=$zdrv #ex: sda2:/slacko/zdrv_slacko_6.3.0.sfs
[ $fdrv ] && FDRV=$fdrv
[ $adrv ] && ADRV=$adrv
[ $ydrv ] && YDRV=$ydrv
#<partition>:<filename>, for savefile/savefolder. <partition> can be a name or Label or UUID
[ $psave ] && PSAVE=$psave #ex: sdb4:/puppy/tahr/tahrsave or smark or 49baa82d-8c69:tahrsave
#list of kernel modules to load, ex: pimod=hid-logitech-dj.ko,kernel/drivers/hid/hid-multitouch.ko
[ $pimod ] && PIMOD=$pimod
#specify partition for Underdog Linux (refer also underdog.lnx).
[ $underdog ] && UNDERDOG=$underdog
#[ $pdebug ] && PDEBUG=$pdebug
PDEBUG=1
TOTAL_SIZEK_SFS_RAM=0
# show menu with pupsaves
[ $psavemenu ] && PSAVEMENU=$psavemenu
# Booting from external USB disks may not find files on time. Wait early.
[ "${PMEDIA:0:3}" = "usb" ] && wait_for_usb
RDSH=""
if [ "$pfix" ];then
for ONEFIX in $(echo -n "$pfix" | tr ',' ' ')
do
case $ONEFIX in
ram) PRAMONLY="yes";; #run in ram only (do not load ${DISTRO_FILE_PREFIX}save).
rdsh) RDSH="yes";; #exit to shell in initial ramdisk.
xorgwizard) PXORGWIZARD="yes";;#force xorgwizard for this session
nox) PNOX="yes";; #do not start X.
clean) PCLEAN="yes";; #force version upgrade and cleanup.
trim) PTRIM="yes";; #add "discard" to mount options if SSD
copy) PCOPY="yes";; #copy .sfs files into ram.
nocopy) PNOCOPY="yes";; #do not copy .sfs files into ram (default is copy if enough ram).
fsck) PFSCK="yes";; #do a fsck of ${DISTRO_FILE_PREFIX}save file.
fsckp) PFSCKP="yes";; #do fsck before first mount of ext partitions
[0-9]*) PIGNORELAST=$ONEFIX;; #blacklist last $ONEFIX folders (multisession).
*) echo "pfix=$ONEFIX is not a known boot parameter";;
esac
done
fi
[ "$PRAMONLY" != "yes" ] && [ -f /BOOT_SPECS ] && . /BOOT_SPECS
if [ "$PSAVEMENU" ] ; then
#MENU_MAX_PUPSAVES=number
MENU_MAX_PUPSAVES=$(echo "$PSAVEMENU" | grep -o '[0-9]' | tr '\n' ' ' | sed 's| ||g')
fi
[ "$TZ" ] && export TZ
hwclock -l -s
[ "$PDEBUG" ] && echo "0: PMEDIA=$PMEDIA PDRV=$PDRV PSUBDIR=$PSUBDIR pfix=$pfix"
#100915 technosaurus recommendation (see above)...
[ "$PDRV" ] && { decode_spec "$PDRV"; P_BP_ID="$ONE_BP_ID"; P_BP_FN="$ONE_BP_FN"; PDRV=""; }
[ "$ZDRV" ] && { decode_spec "$ZDRV"; Z_BP_ID="$ONE_BP_ID"; Z_BP_FN="$ONE_BP_FN"; ZDRV=""; }
[ "$FDRV" ] && { decode_spec "$FDRV"; F_BP_ID="$ONE_BP_ID"; F_BP_FN="$ONE_BP_FN"; FDRV=""; }
[ "$ADRV" ] && { decode_spec "$ADRV"; A_BP_ID="$ONE_BP_ID"; A_BP_FN="$ONE_BP_FN"; ADRV=""; }
[ "$YDRV" ] && { decode_spec "$YDRV"; Y_BP_ID="$ONE_BP_ID"; Y_BP_FN="$ONE_BP_FN"; YDRV=""; }
[ "$PSAVE" ] && { decode_spec "$PSAVE"; SAVE_BP_ID="$ONE_BP_ID"; SAVE_BP_FN="$ONE_BP_FN"; }
SAVE_BP_DIR=""
[ "$SAVE_BP_FN" ] && [ "${SAVE_BP_FN:$((${#SAVE_BP_FN} - 1))}" = "/" ] && SAVE_BP_DIR="$SAVE_BP_FN" #last char
#first look inside initrd...
#unset x_DEF_FN so that find_onepupdrv() won't look for it
[ -f /${P_DEF_FN} ] && { PDRV="rootfs,rootfs,/$P_DEF_FN"; P_DEF_FN=""; }
[ -f /${Z_DEF_FN} ] && { ZDRV="rootfs,rootfs,/$Z_DEF_FN"; Z_DEF_FN=""; }
[ -f /${F_DEF_FN} ] && { FDRV="rootfs,rootfs,/$F_DEF_FN"; F_DEF_FN=""; }
[ -f /${A_DEF_FN} ] && { ADRV="rootfs,rootfs,/$A_DEF_FN"; A_DEF_FN=""; }
[ -f /${Y_DEF_FN} ] && { YDRV="rootfs,rootfs,/$Y_DEF_FN"; Y_DEF_FN=""; }
#-----------------------------
# see if actually a non-huge kernel is being used..
not_a_huge_kernel_stuff && check_status 0
#-----------------------------
get_part_info
grep -v '^sr' /tmp/ALLDRVS0 > /tmp/ATADRIVES0
ATAOPTICALDRIVES="$(grep '^sr' /tmp/ALLDRVS0 | tr '\n' ' ')"
PUP_SAVES=""
KEEPMOUNTED=""
FSCKDPARTS=""
BLKIDOUT=""
LO_OPT="-r"
[ "$PDEBUG" ] && echo "1: PDRV=$PDRV P_BP_ID=$P_BP_ID P_BP_FN=$P_BP_FN"
#establish PDRV
P_PART=""; LOOK_PUP=""; LOOK_SAVE=""
if [ "$P_BP_ID" ];then #specified as parameter
decode_id "$P_BP_ID"
[ "$ONE_PART" ] && { P_PART="$ONE_PART"; P_BP_ID=""; }
if [ "$P_PART" = "" ];then
wait_for_usb
decode_id "$P_BP_ID"
[ "$ONE_PART" ] && { P_PART="$ONE_PART"; P_BP_ID=""; }
fi
find_onepupdrv "$P_PART" "$P_BP_FN" "$P_DEF_FN" "p"
[ "$ONE_FN" ] && { PDRV="$ONE_PART,$ONE_FS,$ONE_FN"; P_MP="$ONE_MP"; }
[ "$PDEBUG" ] && echo "2: ONE_PART=$ONE_PART ONE_FN=$ONE_FN ONE_MP=$ONE_MP"
elif [ "$PDRV" = "" ];then #not specified anywhere
#determine what to search for
[ "$PMEDIA" = "cd" ] && LOOK_SAVE="yes"
[ "$SAVE_BP_ID" -o "$PSAVEMARK" ] && LOOK_SAVE=""
LOOK_PUP=yes
[ "$PDEBUG" ] && echo "2: LOOK_PUP=$LOOK_PUP LOOK_SAVE=$LOOK_SAVE PMEDIA=$PMEDIA"
fi
if [ "$LOOK_PUP" -o "$LOOK_SAVE" ];then #something to search for
[ "${PMEDIA:0:3}" != "usb" ] && search_func
if [ "$P_PART" = "" ];then
wait_for_usb
USBDRVS="$(find /sys/block -maxdepth 1 -name 'sd*' -o -name 'sr*' | xargs -n 1 readlink 2>/dev/null | grep '/usb[0-9]' | rev | cut -f 1 -d '/' | rev | tr '\n' '|')"
[ "$PDEBUG" ] && echo "2: USBDRVS=$USBDRVS -> ${USBDRVS%|}"
if [ "$USBDRVS" ] ; then
search_func "${USBDRVS%|}"
else
search_func
fi
fi
fi
[ "$P_BP_ID" ] && { log_part_id "$P_BP_ID"; ONE_PART="$P_BP_ID"; }
[ "$PDEBUG" ] && echo "6: ONE_PART=$ONE_PART ONE_TRY_FN=$ONE_TRY_FN PDRV=$PDRV"
if [ "$PDRV" = "" ];then
[ "$ONE_TRY_FN" ] || ONE_TRY_FN="$PSUBDIR/$P_DEF_FN"
fatal_error "$ONE_PART $ONE_TRY_FN not found." "Finding puppy main sfs file."
fi
#establish SAVEPART
decode_other_ids
if [ "$Z_BP_ID" -o "$F_BP_ID" -o "$A_BP_ID" -o "$Y_BP_ID" -o "$SAVE_BP_ID" ];then
wait_for_usb
decode_other_ids
fi
if [ "$P_PART" ];then
BOOTDRV="$(echo -n "$P_PART" | grep -o -f /tmp/ALLDRVS0)" #110205 ex: sda1 becomes sda.
if [ "$SAVEPART" = "" ];then #setup SAVEPART
[ "$P_MP" ] || P_MP="$(mount | grep -m1 "/dev/$P_PART " | cut -f 3 -d ' ')"
[ -f ${P_MP}${PSUBDIR}/SAVEMARK ] && PSAVEMARK="$(cat ${P_MP}${PSUBDIR}/SAVEMARK)" #partition no. that has or will-have ${DISTRO_FILE_PREFIX}save.2fs. 101020
if [ "$PSAVEMARK" ];then
SAVEPART="${BOOTDRV}${PSAVEMARK}" #note, PSAVEMARK could also be a kernel boot param. ex: 2
if [ "$(echo $HAVE_PARTS | grep "$SAVEPART")" = "" ];then #partition not exist