Michele13

myinit

May 9th, 2015
370
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 19.69 KB | None | 0 0
  1. #!/bin/sh
  2. ### linuxc script by fanthom <http://www.porteus.org>
  3. ### edited by Michele13
  4.  
  5. export PATH=/bin:/usr/bin:./
  6.  
  7. # Enable pivot_root in initramfs to let it behave like initrd:
  8. if [ -d /m ]; then
  9.     mount -nt tmpfs tmpfs -o mode=0755 /m
  10.     cp -a ??* /m 2>/dev/null
  11.     exec switch_root /m linuxrc "$@"
  12. fi
  13.  
  14. mount -nt proc proc /proc
  15. mount -nt sysfs sysfs /sys
  16. echo 0 >/proc/sys/kernel/printk
  17.  
  18. clear
  19. echo """Starting init script"""
  20.  
  21. # Functions:
  22. param() { egrep -qo " $1( |\$)" /proc/cmdline; }
  23. value() { egrep -o " $1=[^ ]+" /proc/cmdline | cut -d= -f2; }
  24. debug() { param debug && { echo -e "\n=====\n: Debugging started. Here is the shell for you.\n: Type your desired commands, hit Ctrl+D to continue booting\n: or press Ctrl+Alt+Del to reboot."; sh; echo -e "\n\n"; }; }
  25.  
  26. # Variables:
  27. i=`echo """^ """`
  28. m=`echo """->"""`
  29. arch=`uname -m`; [ $arch = x86_64 ] || arch=i486
  30. DELAY=`value delay`; [ $DELAY ] && { echo $i"delaying $DELAY sec (waiting for slow devices to settle up)"; sleep $DELAY; }
  31. SGN=`value sgnfile`; [ $SGN ] || SGN=jessie-$arch.sgn
  32. FROM=`value from`; ISO=`echo $FROM | egrep ".*\.iso( |\$)"`
  33. IP=`value ip | cut -d: -f2`
  34. MOPT=`value mopt`; [ $MOPT ] || MOPT="noatime,nodiratime,suid,dev,exec,async"
  35. CHANGES=`value changes`
  36. RAMSIZE=`value ramsize`; [ $RAMSIZE ] || RAMSIZE=60%
  37. LOAD=`value load | sed 's/;/|/g'`; [ $LOAD ] || LOAD=._null
  38. NOLOAD=`value noload | sed 's/;/|/g'`; [ $NOLOAD ] || NOLOAD=._null
  39. EXTRAMOD=`value extramod | sed 's/;/ /g'`
  40. RAMMOD=`value rammod | sed 's/;/|/g'`
  41. ROOTCOPY=`value rootcopy`
  42. FOLDER=debian
  43. livedbg=/var/log/livedbg
  44.  
  45. # Device Functions:
  46. fstab() { rm -f /tmp/devices
  47. param nocd || for x in /dev/sr*; do blkid $x >>/tmp/devices; done
  48. param nohd || blkid | egrep -v '/dev/sr|/dev/loop|/dev/mapper' >>/tmp/devices
  49. dev=`egrep -v 'TYPE="sw|TYPE="LVM|TYPE=".*_raid_member"' /tmp/devices 2>/dev/null | cut -d: -f1 | cut -d/ -f3 | sort | uniq`
  50. cat > /etc/fstab << EOF
  51. # Do not edit this file as fstab is recreated automatically during every boot.
  52. # Please use /etc/rc.d/rc.local or sysvinit scripts if you want to mount/unmount
  53. # drive, filesystem or network share.
  54.  
  55. # System mounts:
  56. aufs / aufs defaults 0 0
  57. proc /proc proc defaults 0 0
  58. sysfs /sys sysfs defaults 0 0
  59. devtmpfs /dev devtmpfs defaults 0 0
  60. devpts /dev/pts devpts rw,mode=0620,gid=5 0 0
  61.  
  62. # Device partitions:
  63. EOF
  64. for x in $dev; do
  65.     fs=`grep -w /dev/$x /tmp/devices | egrep -o ' TYPE=[^ ]+' | cut -d'"' -f2`
  66.     [ $fs = vfat ] && echo "/dev/$x /mnt/$x vfat $MOPT,umask=0,check=s,utf8 0 0" >>/etc/fstab || echo "/dev/$x /mnt/$x $fs $MOPT 0 0" >>/etc/fstab
  67.     if [ ! -d /mnt/$x ]; then
  68.     mkdir /mnt/$x
  69.     if [ $fs = ntfs ]; then
  70.         ntfs-3g /dev/$x /mnt/$x -o $MOPT 2>/dev/null || { sed -i "/$x /d" /etc/fstab; rmdir /mnt/$x; }
  71.     else
  72.         mount -n /mnt/$x 2>/dev/null || { modprobe $fs 2>/dev/null && mount -n /mnt/$x 2>/dev/null || { sed -i "/$x /d" /etc/fstab; rmdir /mnt/$x; }; }
  73.     fi
  74.     fi
  75. done
  76.  
  77. if [ -z "`egrep -o " noswap( |\$)" /proc/cmdline`" -a -e /tmp/devices ]; then
  78.     echo -e "\n# Swap partitions:" >>/etc/fstab
  79.     for x in `grep 'TYPE="swap"' /tmp/devices | cut -d: -f1`; do echo "$x none swap sw,pri=1 0 0" >>/etc/fstab; done
  80. fi }
  81. mount_device() {
  82. fs=`blkid /dev/$1 | egrep -o ' TYPE=[^ ]+' | cut -d'"' -f2`
  83. if [ "$fs" ]; then
  84.     mkdir /mnt/$1
  85.     if [ $fs = vfat ]; then
  86.     mount -n /dev/$1 /mnt/$1 -o $MOPT,umask=0,check=s,utf8 2>/dev/null || rmdir /mnt/$1
  87.     elif [ $fs = ntfs ]; then
  88.     ntfs-3g /dev/$1 /mnt/$1 -o $MOPT 2>/dev/null || rmdir /mnt/$1
  89.     else
  90.     mount -n /dev/$1 /mnt/$1 -o $MOPT 2>/dev/null || { modprobe $fs 2>/dev/null && mount -n /dev/$1 /mnt/$1 -o $MOPT || rmdir /mnt/$1; }
  91.     fi
  92. fi }
  93.  
  94. # Search functions:
  95. search() { FND=none; for x in `ls /mnt | tac`; do
  96. [ $1 /mnt/$x/$2 ] && { DEV=$x; FND=y; break; }; done
  97. [ $FND = y ]; }
  98. lazy() { SLEEP=6; while [ $SLEEP -gt 0 -a $FND = none ]; do nap; let SLEEP=SLEEP-1; fstab; search $*; done }
  99. locate() { LPATH=`echo $2 | cut -b-5 | sed s@/dev@/mnt@`
  100. if [ $LPATH = /mnt/ ]; then
  101.     DEV=`echo $2 | cut -d/ -f3`; LPTH=`echo $2 | cut -d/ -f4-`; SLEEP=6
  102.     while [ $SLEEP -gt 0 -a ! -b /dev/$DEV ]; do nap; let SLEEP=SLEEP-1; fstab; done
  103.     [ -d /mnt/$DEV ] || mount_device $DEV
  104.     [ $1 /mnt/$DEV/$LPTH ]
  105. elif [ $LPATH = UUID: -o $LPATH = LABEL ]; then
  106.     ID=`echo $2 | cut -d: -f2 | cut -d/ -f1`; LPTH=`echo $2 | cut -d/ -f2-`; DEV=`blkid | grep $ID | cut -d: -f1 | cut -d/ -f3`; SLEEP=6
  107.     while [ $SLEEP -gt 0 -a "$DEV" = "" ]; do nap; let SLEEP=SLEEP-1; fstab; DEV=`blkid | grep $ID | cut -d: -f1 | cut -d/ -f3`; done
  108.     [ -d /mnt/$DEV ] || mount_device $DEV
  109.     [ $1 /mnt/$DEV/$LPTH ]
  110. else
  111.     LPTH=$2; search $* || lazy $*
  112. fi }
  113.  
  114. # Other functions:
  115. nap() { echo -en $i"device not ready yet? delaying $SLEEP seconds \r"; sleep 1; }
  116. fail() { echo -e $i"couldn't find $1. Correct your cheatcodes if needed.\n  Press 'enter' to continue booting."; read -s; }
  117. fail_chn() { mount -nt tmpfs -o size=$RAMSIZE tmpfs /memory/changes; CHANGES=memory; CHNDEV=memory; }
  118. draw() { echo """---------------------------------------------------------"""; }
  119. fsck_dat() { echo $i"checking $1 for errors"
  120. fs=`blkid $1 | egrep -o ' TYPE=[^ ]+' | cut -b8-10`
  121. if [ $fs = xfs ]; then
  122.     echo $i"detected xfs - performing fsck at mount time"
  123. elif [ $fs = ext ]; then
  124.     draw; e2fsck -C 0 -p $1; wait; draw
  125. elif [ $fs = rei ]; then
  126.     draw; reiserfsck -p $1; wait; draw
  127. else
  128.     echo $i"detected unsupported fs - skipping fsck"
  129. fi }
  130. cpmod() { NUM=`grep -c '.' $1`
  131. for x in `cat $1`; do
  132.     echo -en """  ($NUM modules left)  \r"""; let NUM=NUM-1; NAME=`basename $x`
  133.     cp $x /memory/copy2ram 2>/dev/null
  134.     if [ $? -eq 0 ]; then
  135.     sed -i s@^.*/$NAME@/memory/copy2ram/$NAME@ /tmp/modules
  136.     else
  137.     rm /memory/copy2ram/$NAME; echo -e $i"""Not enough memory to copy $NAME"""; echo -e $i"""Other modules will be skipped."""
  138.     find /memory/copy2ram -name "*.xzm" | sort >/tmp/modules
  139.     break
  140.     fi
  141. done
  142. echo -en "                       \r"; }
  143.  
  144. ## Let's start!
  145. mount -nt devtmpfs none /dev
  146.  
  147. # Perform filesystem check:
  148. if param fsck; then
  149.     echo $i"performing linux filesystem check on all available devices:"
  150.     draw
  151.     for x in `blkid | grep 'TYPE="ext' | cut -d: -f1`; do e2fsck -C 0 -p $x; wait; done
  152.     for x in `blkid | grep 'TYPE="reiserfs"' | cut -d: -f1`; do reiserfsck -p $x; wait; done
  153.     draw
  154. fi
  155.  
  156. # Create /etc/fstab and mount devices:
  157. fstab
  158.  
  159. debug
  160. # Find *.sgn file:
  161. echo $i"searching for $SGN file"
  162. if [ $IP ]; then BOOTDEV=network; SGNDEV=/mnt/nfs
  163.     for x in `lspci | grep 0200: | cut -d: -f3-4 | sed s/:/.*/g | tr a-z A-Z`; do modprobe `grep $x /lib/modules/$(uname -r)/modules.alias | tail -n1 | rev | cut -d" " -f1 | rev` 2>/dev/null; done
  164.     ls /sys/class/net | grep -q eth || { for x in `find /lib/modules/$(uname -r)/kernel/drivers/net -name "*.ko" | sed 's/.ko//g'`; do modprobe `basename $x` 2>/dev/null; ls /sys/class/net | grep -q eth && break || modprobe -r `basename $x` 2>/dev/null; done; }
  165.     mkdir -p /mnt/nfs/porteus /mnt/nfs/storage; udhcpc; modprobe nfsv4; mount -t nfs4 $IP:/srv/pxe/porteus /mnt/nfs/porteus -o ro,nolock 2>/dev/null || { modprobe nfsv3; mount -t nfs $IP:/srv/pxe/porteus /mnt/nfs/porteus -o ro,nolock 2>/dev/null; }
  166.     MAC=`ifconfig | grep eth0 | cut -d: -f5-7 | sed s/://g | cut -d" " -f1`
  167.     if [ "$CHANGES" = /srv/pxe/storage ]; then
  168.     if lsmod | grep -q nfsv3; then
  169.         mount -t nfs $IP:/srv/pxe/storage /mnt/nfs/storage -o rw,nolock 2>/dev/null && { mkdir -p /mnt/nfs/storage/client-$MAC/changes/home; CHANGES="/storage/client-$MAC"; }
  170.     else
  171.         mount -t nfs4 $IP:/srv/pxe/storage /mnt/nfs/storage -o rw,nolock 2>/dev/null && { mkdir -p /mnt/nfs/storage/client-$MAC/changes/home; CHANGES="/storage/client-$MAC"; }
  172.     fi
  173.     fi
  174. elif [ $ISO ]; then SGNDEV=/mnt/isoloop
  175.     locate -e $FROM && { BOOTDEV=/mnt/$DEV; mkdir /mnt/isoloop; mount -o loop /mnt/$DEV/$LPTH /mnt/isoloop; }
  176. else
  177.     if [ $FROM ]; then
  178.     locate -e $FROM/debian/$SGN
  179.     if [ $? -eq 0 ]; then
  180.         DIR=`echo $LPTH | rev | cut -d/ -f3- | rev`; [ $DIR ] && FOLDER=$DIR/debian
  181.     else
  182.         echo $i"from= cheatcode is incorrect, press enter to search through all devices"
  183.         read -s; search -e debian/$SGN
  184.     fi
  185.     else
  186.     search -e debian/$SGN || lazy -e debian/$SGN
  187.     fi
  188.     SGNDEV=/mnt/$DEV
  189. fi
  190.  
  191. [ -e $SGNDEV/$FOLDER/$SGN ] && PTH=$SGNDEV/$FOLDER || . fatal
  192. echo $i"using Debian data from $PTH"
  193.  
  194. # Make all drivers available:
  195. mount -o loop $PTH/base/000-kernel.xzm /opt/000-kernel 2>/dev/null
  196. mount -o bind /opt/000-kernel/lib/modules /lib/modules 2>/dev/null
  197.  
  198. # Create symlinks used often by porteus scripts:
  199. if [ $SGNDEV = /mnt/nfs -o $SGNDEV = /mnt/isoloop ];then
  200.     ln -sf /mnt/live$PTH/modules  /porteus/modules
  201.     ln -sf /mnt/live$PTH/optional /porteus/optional
  202. else
  203.     ln -sf $PTH/modules  /porteus/modules
  204.     ln -sf $PTH/optional /porteus/optional
  205. fi
  206.  
  207. debug
  208. # Setup changes:
  209. if [ $CHANGES ]; then
  210.     echo $i"setting up directory for changes"
  211.     CHNEXIT=`echo $CHANGES | cut -d: -f1`; [ $CHNEXIT = EXIT ] && CHANGES=`echo $CHANGES | cut -d: -f2-`
  212.     #[ `echo $CHANGES | sed s@/@@g` = porteus ] && { DEV=`echo $SGNDEV | sed s@/mnt/@@`; LPTH=$FOLDER; } || locate -r $CHANGES
  213.     [ -r $SGNDEV/$CHANGES ] && { DEV=`echo $SGNDEV | sed s@/mnt/@@`; LPTH=$CHANGES; } || locate -r $CHANGES
  214.     if [ $? -eq 0 ]; then
  215.     if [ -d /mnt/$DEV/$LPTH ]; then
  216.         mkdir -p /mnt/$DEV/$LPTH/changes 2>/dev/null && \
  217.         mount -o bind /mnt/$DEV/$LPTH/changes /memory/changes && touch /memory/changes/._test1 2>/dev/null
  218.     else
  219.         if blkid /mnt/$DEV/$LPTH 2>/dev/null | cut -d" " -f3- | grep -q _LUKS; then
  220.         for x in dm_crypt cryptd cbc sha256_generic aes_generic aes_x86_64; do modprobe $x 2>/dev/null; done
  221.         losetup /dev/loop2 /mnt/$DEV/$LPTH
  222.         echo $i"found encrypted .dat container"
  223.         /opt/000-kernel/sbin/cryptsetup luksOpen /dev/loop2 crypt
  224.         fsck_dat /dev/mapper/crypt
  225.         mount /dev/mapper/crypt /memory/changes 2>/dev/null && touch /memory/changes/._test1 2>/dev/null
  226.         else
  227.         fsck_dat /mnt/$DEV/$LPTH
  228.         mount -o loop /mnt/$DEV/$LPTH /memory/changes 2>/dev/null && touch /memory/changes/._test1 2>/dev/null
  229.         fi
  230.     fi
  231.     if [ $? -eq 0 ]; then
  232.         echo $i"testing filesystem on "$CHANGES" for posix compatibility"
  233.         ln -s /memory/changes/._test1 /memory/changes/._test2 2>/dev/null && chmod +x /memory/changes/._test1 2>/dev/null && [ -x /memory/changes/._test1 ] && chmod -x /memory/changes/._test1 2>/dev/null && [ ! -x /memory/changes/._test1 ] && rm -f /memory/changes/._test1 /memory/changes/._test2
  234.         if [ $? -ne 0 ]; then
  235.         rm -f /memory/changes/._test1 /memory/changes/._test2; umount /memory/changes
  236.         echo && echo -e """A Windows filesystem (FAT, NTFS) or other non-posix compatible filesystem\nhas been detected on $CHANGES.\nYour changes cannot be saved directly to the specified storage media with this\nsetup. Please use the 'Porteus save file manager' to create a .dat container\nand use it for saving your changes after your next reboot."""
  237.         echo "press enter to continue in 'Always Fresh' mode for this session"
  238.         read; rmdir /mnt/$DEV/$LPTH/changes; fail_chn
  239.         else
  240.         echo $i"filesystem is posix compatible"; CHNDEV=/mnt/$DEV
  241.         rmdir /memory/changes/mnt/* 2>/dev/null
  242.         rm -rf /memory/changes/var/lock/* /var/run/laptop-mode-tools/* /var/spool/cron/cron.??????
  243.         for x in `find /memory/changes/var/run -name "*pid" 2>/dev/null`; do rm $x; done
  244.         if [ $CHNEXIT = EXIT -o "`egrep -o " changes-ro( |\$)" /proc/cmdline`" ]; then
  245.             CHNEXIT=$CHNDEV/$LPTH; echo $CHNEXIT >/tmp/changes-exit
  246.             param changes-ro && echo $i"""changes will not be saved for this session""" || echo $i"""changes will be saved only during reboot/shutdown"""
  247.             for x in `find /memory/changes -name ".wh.*" | grep -v '.wh..wh..opq'`; do cp -a --parents $x /var; done
  248.             umount /memory/changes; mount -nt tmpfs -o size=$RAMSIZE tmpfs /memory/changes
  249.             # need to fix busybox bug on 'cp -a' as it does not preserve perms on dirs:
  250.             chown -R 1000:1000 /var/memory/changes/home/guest 2>/dev/null
  251.             mv /var/memory/changes/* /memory/changes 2>/dev/null; CHANGES=memory
  252.         fi
  253.         fi
  254.     else
  255.         echo $i"changes not writable, using memory instead"; umount /memory/changes 2>/dev/null; fail_chn
  256.     fi
  257.     else
  258.     fail $CHANGES; fail_chn
  259.     fi
  260. else
  261.      echo $i"changes cheatcode not found, using memory only"; fail_chn
  262. fi
  263.  
  264. mkdir -p /memory/changes/mnt/live
  265.  
  266. debug
  267. # Setup aufs:
  268. echo $i"creating live filesystem and inserting modules"
  269. mount -t aufs -o nowarn_perm,xino=/memory/xino/.aufs.xino,br:/memory/changes=rw aufs /union
  270. if [ $? -ne 0 ]; then echo -e """cant setup union (aufs) - read only filesystem?\nWhen you finish debugging press Ctrl+Alt+Del to reboot."""; sh; fi
  271.  
  272. # Find modules:
  273. find $PTH/base $PTH/modules -name "*.xzm" 2>/dev/null | egrep -v "$NOLOAD" | sort >/tmp/modules
  274. find $PTH/optional -name "*.xzm" 2>/dev/null | egrep "$LOAD" | sort >>/tmp/modules
  275.  
  276. if param vga_detect; then
  277.     echo $i"detecting GPU"
  278.     lspci >/tmp/lspci; nv=`grep "0300: 10de:" /tmp/lspci | cut -d":" -f4`; amd=`grep "0300: 1002:" /tmp/lspci | cut -d":" -f4`
  279.     if [ $nv ]; then
  280.     echo $i"$nv chipset found, checking which nVidia driver supports it"
  281.     cd /usr/share/pciids/nVidia; NV=`grep $nv * | cut -d: -f1`; cd /
  282.     if [ $NV ]; then
  283.         echo $i"nVidia-$NV.xx driver will be activated -"
  284.         echo $i"if present in $PTH/optional folder"
  285.         find $PTH/optional -name "nVidia-$NV*" 2>/dev/null >>/tmp/modules
  286.     else
  287.         echo $i"latest nVidia driver will be activated -"
  288.         echo $i"if present in $PTH/optional folder"
  289.         find $PTH/optional -name "nVidia-*" 2>/dev/null | egrep -v '96.43.|173.14.|304.' >>/tmp/modules
  290.     fi
  291.     elif [ $amd ]; then
  292.     echo $i"checking if $amd GPU belongs to 'Radeon HD' series"
  293.     cd /usr/share/pciids/AMD; HD=`grep $amd * | cut -d: -f1`; cd /
  294.     if [ $HD ]; then
  295.             echo $i"$HD-xx driver will be activated -"
  296.             echo $i"if present in $PTH/optional folder"
  297.             find $PTH/optional -name "$HD-*" 2>/dev/null >>/tmp/modules
  298.         else
  299.             echo $i"$amd GPU is not supported by amd-catalyst driver - refusing activation"
  300.         fi
  301.     else
  302.         echo $i"could not find any nVidia/AMD GPU on this PC"
  303.     fi
  304. fi
  305.  
  306. if param base_only; then
  307.     grep base/0 /tmp/modules > /tmp/mod
  308.     mv /tmp/mod /tmp/modules
  309. else
  310.     if [ "$EXTRAMOD" ]; then
  311.     for folder in $EXTRAMOD; do
  312.         echo $i"searching for additional modules in $folder"
  313.         locate -d $folder && { find /mnt/$DEV/$LPTH -name "*.xzm" 2>/dev/null | egrep -v "$NOLOAD" | sort >>/tmp/modules; } || fail $folder
  314.     done
  315.     fi
  316. fi
  317.  
  318. # Copy data to RAM:
  319. if param copy2ram; then
  320.     echo $i"copying Porteus data to RAM, this may take some time..."
  321.     [ $RAMMOD ] && { egrep "$RAMMOD" /tmp/modules > /tmp/rammod; cpmod /tmp/rammod; } || cpmod /tmp/modules
  322. fi
  323.  
  324. # Populate aufs with modules:
  325. umount /lib/modules /opt/000-kernel 2>/dev/null
  326. for x in `cat /tmp/modules`; do
  327.     NAME=`basename $x`; mkdir /memory/images/$NAME; mount -o loop $x /memory/images/$NAME 2>/dev/null
  328.     if [ $? -eq 0 ]; then
  329.     echo "  $m  $NAME"; mount -no remount,add:1:/memory/images/$NAME=rr aufs /union
  330.     else
  331.     echo $i"""Cannot read $NAME - corrupted module?"""; rmdir /memory/images/$NAME
  332.     fi
  333. done
  334. mount -no bind /union/lib/modules /lib/modules 2>/dev/null
  335.  
  336. # Add "changes on exit" device/file/folder:
  337. if [ -e /tmp/changes-exit ]; then
  338.     mkdir /memory/images/changes
  339.     if [ -d $CHNEXIT ]; then
  340.     mount -o bind $CHNEXIT/changes /memory/images/changes
  341.     elif [ -b /dev/mapper/crypt ]; then
  342.     mount /dev/mapper/crypt /memory/images/changes
  343.     else
  344.     mount -o loop $CHNEXIT /memory/images/changes
  345.     fi
  346.     echo "  $m  changes"; mount -no remount,add:1:/memory/images/changes=ro aufs /union
  347.     echo $CHNEXIT/changes >>/tmp/modules
  348.     param changes-ro && rm /tmp/changes-exit
  349. fi
  350.  
  351. debug
  352. # Copy /rootcopy folder:
  353. if param norootcopy; then
  354.     ROOTCOPY=none
  355.     echo $i"skipping /rootcopy directory"
  356. else
  357.     if [ $ROOTCOPY ]; then
  358.     locate -d $ROOTCOPY
  359.     if [ $? -eq 0 ]; then echo $i"copying content of $ROOTCOPY directory"; cp -af /mnt/$DEV/$LPTH/. /union/. 2>/dev/null; else fail $ROOTCOPY; ROOTCOPY=none; fi
  360.     else
  361.     ROOTCOPY=none
  362.     echo $i"copying content of $PTH/rootcopy directory"
  363.     cp -af $PTH/rootcopy/. /union/. 2>/dev/null
  364.     fi
  365. fi
  366.  
  367. ## Finish:
  368. # Create 7 free loop devices for truecrypt, etc...
  369. x=`losetup | tail -n1 | cut -d: -f1 | sed 's@/dev/loop@@'`; let y=x+7
  370. while [ $x -le $y ]; do [ -b /dev/loop$y ] && break || mknod /dev/loop$y b 7 $y; let y=y-1; done
  371.  
  372. if param nonetwork; then
  373.     echo $i"disabling dhcpcd and NetworkManager services"
  374.     chmod -x /union/etc/rc.d/rc.inet1 /union/etc/rc.d/rc.networkmanager 2>/dev/null
  375.     nma=/union/etc/xdg/autostart/nm-applet.desktop
  376.     test -e $nma && ! grep -q "Hidden=true" $nma && echo "Hidden=true" >> $nma
  377. fi
  378.  
  379. if [ "$IP" -a -x /union/etc/rc.d/rc.networkmanager ]; then
  380.     if [ -z "`egrep -o " copy2ram( |\$)" /proc/cmdline`" -o -d /mnt/nfs/storage/client-$MAC ]; then
  381.     echo "nameserver $IP" > /union/etc/resolv.conf
  382.     nmc=/union/etc/NetworkManager/NetworkManager.conf; HW=`ifconfig | grep eth0 | cut -dW -f2 | cut -d" " -f2`
  383.     ! grep -q "unmanaged-devices=mac:$HW" $nmc && sed -i '/\[keyfile\]/ a\unmanaged-devices=mac:'$HW'' $nmc
  384.     fi
  385. fi
  386.  
  387. cp -af /dev/console /union/dev
  388. cat > /union/etc/mtab << EOF
  389. aufs / aufs rw 0 0
  390. proc /proc proc rw 0 0
  391. sysfs /sys sysfs rw 0 0
  392. devtmpfs /dev devtmpfs rw 0 0
  393. devpts /dev/pts devpts rw,mode=0620,gid=5 0 0
  394. EOF
  395. fstab
  396.  
  397. debug
  398. if param copy2ram; then
  399.     [ $SGNDEV = /mnt/isoloop -o $SGNDEV = /mnt/nfs ] && { umount `grep $SGNDEV /etc/mtab | sed -n 1p | cut -d" " -f2`; SGNDEV=$BOOTDEV; }
  400.     CHNDISK=`echo $CHNDEV | cut -b6-8`; SGNDISK=`echo $SGNDEV | cut -b6-8`; REMOVABLE=`cat /sys/block/$SGNDISK*/removable 2>/dev/null`
  401.     if [ -z "`egrep -o " noeject( |\$)" /proc/cmdline`" -a "$CHNDISK" != "$SGNDISK" ]; then
  402.     if [ "$REMOVABLE" = 1 ]; then
  403.         for rdisk in `ls /mnt | grep $SGNDISK`; do
  404.         umount -n /mnt/$rdisk 2>/dev/null && rmdir /mnt/$rdisk
  405.         if [ $? -eq 0 ]; then
  406.             ! grep -qw "/dev/$rdisk.*iso9660" /etc/fstab && echo $rdisk >> /tmp/ejected || /union/usr/bin/eject /dev/$rdisk
  407.             sed -i "/$rdisk/d" /etc/fstab
  408.         fi
  409.         done
  410.         [ `ls /mnt | grep $SGNDISK` ] || echo $i"""finished copying to RAM - booting media can be removed safely"""
  411.     else
  412.         if param nohd; then umount $SGNDEV 2>/dev/null; rmdir $SGNDEV 2>/dev/null; fi
  413.     fi
  414.     fi
  415. fi
  416.  
  417. # Create debug file:
  418. [ -e /tmp/devices ] && { echo "# Recognized devices:" >$livedbg; cat /tmp/devices >>$livedbg; }
  419. [ $BOOTDEV ] && SGNDEV=$BOOTDEV
  420. echo -e "\n# Booting device:\n$SGNDEV\n\n# Debian data found in:\n$PTH\n\n# Changes are stored in:\n$CHANGES\n\n# Non standard /rootcopy dir:\n$ROOTCOPY\n\n# Modules activated during boot time:" >>$livedbg; cat /tmp/modules >>$livedbg
  421. cp -af $livedbg /union/var/log/porteus-livedbg
  422.  
  423. echo $i"changing root directory"
  424. if param noauto; then
  425.     for x in `grep /mnt/ /etc/fstab | cut -d/ -f3`; do mkdir -p /union/mnt/$x; umount -n /mnt/$x 2>/dev/null && rmdir /mnt/$x; done
  426. else
  427.     grep /mnt/ /etc/fstab >> /union/etc/mtab
  428.     for x in `grep /mnt/ /etc/fstab | cut -d/ -f3`; do mkdir -p /union/mnt/$x; mount -n --move /mnt/$x /union/mnt/$x; rmdir /mnt/$x; done
  429. fi
  430. sed -i 's/ ntfs / ntfs-3g /g' /etc/fstab
  431. cp -f /etc/fstab /union/etc 2>/dev/null
  432. umount -n /lib/modules 2>/dev/null
  433. rm -r /lib/* /usr/*
  434.  
  435. debug
  436. echo """live system is ready now - starting Debian"""
  437. cp -f /union/sbin/init /bin
  438. if [ $? -eq 0 ]; then
  439.     pivot_root /union  /union/mnt/live
  440.     exec bin/chroot . /mnt/live/bin/init "$@" <dev/console >dev/console 2>&1
  441. else
  442.     echo -e """!!ERROR!!\nSomething went wrong and I cannot continue.\nPress Ctrl+Alt+Del to reboot."""
  443.     sh
  444. fi
Advertisement
Add Comment
Please, Sign In to add comment