Advertisement
Guest User

Untitled

a guest
Jan 11th, 2017
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.93 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. # Slax Installation Script
  4.  
  5. # $1 mountdir: /media
  6.  
  7. # $2 Device name: hda, hdb, sda, sdb...
  8.  
  9. # $3 partition number: sda[1]
  10.  
  11. # $4 SWAP partition number: sda[2]
  12.  
  13. # $5 File system type: ext2, ext3, ext4 etc...
  14.  
  15. # $6 Drive Label: Slax [optional]
  16.  
  17. # $7 Slax's main folder (default: slax) [optional]
  18.  
  19. # Example Command line: ./script /media/hdd sda 1 2 ext3 slax64 myslax
  20.  
  21. # Author: Mert Akengin
  22.  
  23. # Version: 0.82 (beta)
  24.  
  25. # Last Update: 2013 June 19
  26.  
  27.  
  28.  
  29. scrname="$0"
  30.  
  31. helptext="$0: Slax Installation Script;
  32.  
  33. Usage: $scrname [mountpoint-dir] [device] [install-partition-num]
  34.  
  35. [swap-partition-num] [file-system] [disk-label*]
  36.  
  37. [main-folder*] [boot-files*]
  38.  
  39. Example: $scrname /media/hdd sda 1 2 ext3 slax64 myslax
  40.  
  41. -> This will install to sda1 with 'slax64' labelled ext3 fs. Swap partition will be set on sdb2...
  42.  
  43. Module & Bundle data and boot data will search in 'myslax' dir in usb root.
  44.  
  45. Note: Attributes with * (star) are OPTIONAL. You don't have to specify these values.
  46.  
  47. Note2: You can disable SWAP by just putting 0 (zero) for it..."
  48.  
  49.  
  50.  
  51. if [ "$1" == "--help" ]; then
  52.  
  53. echo -e "$helptext"
  54.  
  55. exit 1
  56.  
  57. else
  58.  
  59. echo "CHECKING & STARTING..."
  60.  
  61. fi
  62.  
  63.  
  64.  
  65. if [ ! "$1" ] || [ ! "$2" ] || [ ! "$3" ] || [ ! "$4" ] || [ ! "$5" ] ; then
  66.  
  67. echo -e "Wrong Syntax in: $*\nMissing Statement(s)!"
  68.  
  69. echo -e "$helptext"
  70.  
  71. exit 2
  72.  
  73. fi
  74.  
  75.  
  76.  
  77. MOUNT="$1"
  78.  
  79. DEV="$2"
  80.  
  81. PART="$3"
  82.  
  83. SWAP="$4"
  84.  
  85. FILE="$5"
  86.  
  87. LABEL="$6"
  88.  
  89.  
  90.  
  91. if [ "$7" ]; then
  92.  
  93. FROM="$7"
  94.  
  95. else
  96.  
  97. FROM="slax"
  98.  
  99. fi
  100.  
  101.  
  102.  
  103. if [ "$8" ]; then
  104.  
  105. BOOT="$8"
  106.  
  107. else
  108.  
  109. BOOT="$FROM/boot"
  110.  
  111. fi
  112.  
  113.  
  114.  
  115. folders=('bin' 'boot' 'dev' 'etc' 'home' 'lib' 'lib64' 'opt' 'root' 'sbin' 'srv' 'usr' 'var')
  116.  
  117.  
  118.  
  119. LIVE="/mnt/live/memory/data"
  120.  
  121.  
  122.  
  123. filesb="
  124.  
  125. $LIVE/$FROM/initrfs.img
  126.  
  127. $LIVE/$FROM/vmlinuz
  128.  
  129. $LIVE/$BOOT/initrfs.img
  130.  
  131. $LIVE/$BOOT/vmlinuz
  132.  
  133. "
  134.  
  135.  
  136.  
  137. EXTL="$LIVE/$BOOT/extlinux.exe"
  138.  
  139. COM32_1="$LIVE/$BOOT/libcom32.c32"
  140.  
  141. COM32_2="$LIVE/$BOOT/libutil_com.c32"
  142.  
  143.  
  144.  
  145. if echo $SWAP | grep -q '0' ; then
  146.  
  147. SWAP=""
  148.  
  149. DEVINFO="Device: $2 (Install on: $2$3 No-Swap-Space)"
  150.  
  151. else
  152.  
  153. SWAP="/dev/$2$4 swap swap defaults 0 0"
  154.  
  155. DEVINFO="Device: $2 (Install on: $2$3 Swap: $2$4)"
  156.  
  157.  
  158.  
  159. fi
  160.  
  161.  
  162.  
  163. echo "Before starting installation, make sure your disk well-formatted and ready to use..."
  164.  
  165. #echo "Starting FDISK as you specified in command line..."
  166.  
  167. echo "You can verify your disk at this stage! After that, there is no way to return!"
  168.  
  169. echo "ALL OF YOUR DATA ON SPECIFIED DISK WILL BE ERASED!"
  170.  
  171. echo "Press [ENTER] to continue, [CTRL+C] to exit."
  172.  
  173. read junk
  174.  
  175.  
  176.  
  177. echo "Notes about your input: "
  178.  
  179. echo "Mount point: $1"
  180.  
  181. echo "$DEVINFO"
  182.  
  183. echo "Target file-system format ($2$3): $5"
  184.  
  185. echo "File system label *If exists*($2$3): $6"
  186.  
  187. echo -n "Are these values are true? [Y/N]: "
  188.  
  189. read junk
  190.  
  191.  
  192.  
  193. if echo $junk | grep -qi 'y' ; then
  194.  
  195. echo "Proceeding Setup..."
  196.  
  197. else
  198.  
  199. echo "Cancelled by user..."
  200.  
  201. exit 3
  202.  
  203. fi
  204.  
  205.  
  206.  
  207. #fdisk /dev/$2
  208.  
  209. if [ "$6" ]; then
  210.  
  211. mkfs.$5 /dev/$2$3 -L "$6"
  212.  
  213. else
  214.  
  215. mkfs.$5 /dev/$2$3
  216.  
  217. fi
  218.  
  219.  
  220.  
  221. if [ "$SWAP" ]; then
  222.  
  223. mkfs.swap /dev/$2$4 -L slax-swap
  224.  
  225. fi
  226.  
  227.  
  228.  
  229. mkdir "$1" &>/dev/null
  230.  
  231. mount /dev/$2$3 "$1"
  232.  
  233.  
  234.  
  235. for dir in ${folders[*]}
  236.  
  237. do
  238.  
  239. echo -n "Copying /$dir ..."
  240.  
  241. cp -R --preserve=all /"$dir" "$1" && echo " [ OK ]"
  242.  
  243. done
  244.  
  245.  
  246.  
  247. echo -n "Creating system directories..."
  248.  
  249. mkdir -p "$1"/media
  250.  
  251. mkdir -p "$1"/mnt
  252.  
  253. mkdir -p "$1"/opt
  254.  
  255. mkdir -p "$1"/proc
  256.  
  257. mkdir -p "$1"/sys
  258.  
  259. mkdir -p "$1"/tmp
  260.  
  261. echo " [ OK ]"
  262.  
  263.  
  264.  
  265. echo -n "Creating FSTAB..."
  266.  
  267. echo -e "
  268.  
  269. aufs / aufs defaults 0 0
  270.  
  271. /dev/$2$3 / $5 defaults 1 1
  272.  
  273. /dev/cdrom /mnt/cdrom auto noauto,owner,ro 0 0
  274.  
  275. /dev/fd0 /mnt/floppy auto noauto,owner 0 0
  276.  
  277. devpts /dev/pts devpts gid=5,mode=620 0 0
  278.  
  279. proc /proc proc defaults 0 0
  280.  
  281. tmpfs /dev/shm tmpfs defaults 0 0
  282.  
  283. none /mnt/slaxdrive slaxdrive defaults 0 0
  284.  
  285. $SWAP" > "$1"/etc/fstab && echo " [ OK ]"
  286.  
  287.  
  288.  
  289. echo -n "Creating MTAB..."
  290.  
  291. echo -e "
  292.  
  293. /dev/root / $5 rw,errors=continue,data=ordered 0 0
  294.  
  295. proc /proc proc rw 0 0
  296.  
  297. sysfs /sys sysfs rw 0 0
  298.  
  299. usbfs /proc/bus/usb usbfs rw 0 0
  300.  
  301. tmpfs /dev/shm tmpfs rw 0 0
  302.  
  303. " > "$1"/etc/mtab_ && echo " [ OK ]"
  304.  
  305.  
  306.  
  307. echo -n "Copying BOOT data..."
  308.  
  309.  
  310.  
  311.  
  312.  
  313. for file in $(echo "$filesb")
  314.  
  315. do
  316.  
  317. if [ -f "$file" ]; then
  318.  
  319. cp "$file" "$1"/boot/
  320.  
  321. fi
  322.  
  323. done
  324.  
  325.  
  326.  
  327. cp "$LIVE"/"$BOOT"/*.c32 "$1"/boot/
  328.  
  329.  
  330.  
  331. if [ -f "$COM32_1" ]; then
  332.  
  333. cp "$COM32_1" "$1"/boot/
  334.  
  335. fi
  336.  
  337.  
  338.  
  339. if [ -f "$COM32_2" ]; then
  340.  
  341. cp "$COM32_2" "$1"/boot/
  342.  
  343. fi
  344.  
  345.  
  346.  
  347. echo " [ OK ]"
  348.  
  349.  
  350.  
  351. echo -n "Installing Boot-Sector..."
  352.  
  353. #cat "$1"/boot/mbr.bin > /dev/$2
  354.  
  355. cat "$LIVE"/"$BOOT"/mbr.bin > /dev/$2
  356.  
  357. echo " [ OK ]"
  358.  
  359. if [ ! -e "$EXTL" ]; then
  360.  
  361. echo -e "Could not found 'extlinux' binary..."
  362.  
  363. echo -n "Please enter location of 'EXTLINUX' binary: "
  364.  
  365. read EXTL
  366.  
  367. fi
  368.  
  369. "$EXTL" --install "$1"/boot/
  370.  
  371. echo "Installing Boot-Loader... [ OK ]"
  372.  
  373.  
  374.  
  375. ##### ASKING SOME... #####
  376.  
  377. echo -n "Do you want to start X-Server automatically right after boot? [Y/N]: "
  378.  
  379. read bootopt
  380.  
  381. if echo $bootopt | grep -qi 'y' ; then
  382.  
  383. flags="xmode,$flags"
  384.  
  385. fi
  386.  
  387. echo -n "Do you want to start PXE Server automatically right after boot? [Y/N]: "
  388.  
  389. read bootopt
  390.  
  391. if echo $bootopt | grep -qi 'y' ; then
  392.  
  393. flags="pxe,$flags"
  394.  
  395. fi
  396.  
  397. echo -n "Enter VGA= parameter or leave it empty for default [normal]: "
  398.  
  399. read bootopt
  400.  
  401. if [ "$bootopt" ]; then
  402.  
  403. vga="$bootopt"
  404.  
  405. else
  406.  
  407. vga="normal"
  408.  
  409. fi
  410.  
  411. ###-----###
  412.  
  413.  
  414.  
  415. echo -n "Creating SYSLINUX.CFG..."
  416.  
  417. echo -e "
  418.  
  419. UI /boot/vesamenu.c32
  420.  
  421. MENU TITLE Slax | Syslinux
  422.  
  423. PROMPT 0
  424.  
  425. TIMEOUT 10
  426.  
  427. LABEL Slax
  428.  
  429. MENU LABEL Slax 7
  430.  
  431. KERNEL /boot/vmlinuz
  432.  
  433. APPEND root=/dev/$2$3 printk.time=0 vga=$vga ro quiet slax.flags=$flags
  434.  
  435. " > "$1"/boot/extlinux.conf
  436.  
  437. echo " [ OK ]"
  438.  
  439.  
  440.  
  441. if [ "$LABEL" ]; then
  442.  
  443. sed 's/hostname=slax//g' /etc/NetworkManager/NetworkManager.conf > "$1"/etc/NetworkManager/NetworkManager.conf
  444.  
  445. echo "hostname=$LABEL" >> "$1"/etc/NetworkManager/NetworkManager.conf
  446.  
  447. fi
  448.  
  449.  
  450.  
  451. modprobe -c >> "$1"/lib/modprobe.d/slax-modules.conf
  452.  
  453. echo "\l `uname -o` \r | `cat /etc/slax-version` | \t - \d
  454.  
  455. >> \n @ \o
  456.  
  457. \s \m \v
  458.  
  459. >> \U logged in.
  460.  
  461. " >"$1"/etc/issue
  462.  
  463. echo -n "Last question: Do you want to enable auto-login of root?
  464.  
  465. (This may cause security issues) [Y/N]: "
  466.  
  467. read autologin
  468.  
  469. if echo $autologin | grep -qi 'y' ; then
  470.  
  471. passwd -d root
  472.  
  473. cp /etc/{shadow,passwd} "$1"/etc/
  474.  
  475. sed 's/agetty/agetty -a root/g' /etc/inittab > "$1"/etc/inittab
  476.  
  477. fi
  478.  
  479. sed 's/\ --noclear//g' "$1"/etc/inittab > "$1"/inittab
  480.  
  481. rm -f "$1"/etc/inittab && mv "$1"/inittab "$1"/etc/
  482.  
  483.  
  484.  
  485. echo -n "Unmounting File Systems..."
  486.  
  487. umount /dev/$2$3
  488.  
  489. echo " [ OK ]"
  490.  
  491.  
  492.  
  493. echo " --- "
  494.  
  495. echo "
  496.  
  497. Setup is (seems to be) completed.
  498.  
  499. If you haven't set your partition active, set it now!
  500.  
  501. Then reboot your computer!
  502.  
  503. PS. Do 'fdisk /dev/$2' command
  504.  
  505. Then press [A] and hit [ENTER]
  506.  
  507. Press $3 and hit [ENTER] again.
  508.  
  509. For saving and writing changes, press [W] and hit [ENTER] "
  510.  
  511. exit 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement