Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- # Slax Installation Script
- # $1 mountdir: /media
- # $2 Device name: hda, hdb, sda, sdb...
- # $3 partition number: sda[1]
- # $4 SWAP partition number: sda[2]
- # $5 File system type: ext2, ext3, ext4 etc...
- # $6 Drive Label: Slax [optional]
- # $7 Slax's main folder (default: slax) [optional]
- # Example Command line: ./script /media/hdd sda 1 2 ext3 slax64 myslax
- # Author: Mert Akengin
- # Version: 0.82 (beta)
- # Last Update: 2013 June 19
- scrname="$0"
- helptext="$0: Slax Installation Script;
- Usage: $scrname [mountpoint-dir] [device] [install-partition-num]
- [swap-partition-num] [file-system] [disk-label*]
- [main-folder*] [boot-files*]
- Example: $scrname /media/hdd sda 1 2 ext3 slax64 myslax
- -> This will install to sda1 with 'slax64' labelled ext3 fs. Swap partition will be set on sdb2...
- Module & Bundle data and boot data will search in 'myslax' dir in usb root.
- Note: Attributes with * (star) are OPTIONAL. You don't have to specify these values.
- Note2: You can disable SWAP by just putting 0 (zero) for it..."
- if [ "$1" == "--help" ]; then
- echo -e "$helptext"
- exit 1
- else
- echo "CHECKING & STARTING..."
- fi
- if [ ! "$1" ] || [ ! "$2" ] || [ ! "$3" ] || [ ! "$4" ] || [ ! "$5" ] ; then
- echo -e "Wrong Syntax in: $*\nMissing Statement(s)!"
- echo -e "$helptext"
- exit 2
- fi
- MOUNT="$1"
- DEV="$2"
- PART="$3"
- SWAP="$4"
- FILE="$5"
- LABEL="$6"
- if [ "$7" ]; then
- FROM="$7"
- else
- FROM="slax"
- fi
- if [ "$8" ]; then
- BOOT="$8"
- else
- BOOT="$FROM/boot"
- fi
- folders=('bin' 'boot' 'dev' 'etc' 'home' 'lib' 'lib64' 'opt' 'root' 'sbin' 'srv' 'usr' 'var')
- LIVE="/mnt/live/memory/data"
- filesb="
- $LIVE/$FROM/initrfs.img
- $LIVE/$FROM/vmlinuz
- $LIVE/$BOOT/initrfs.img
- $LIVE/$BOOT/vmlinuz
- "
- EXTL="$LIVE/$BOOT/extlinux.exe"
- COM32_1="$LIVE/$BOOT/libcom32.c32"
- COM32_2="$LIVE/$BOOT/libutil_com.c32"
- if echo $SWAP | grep -q '0' ; then
- SWAP=""
- DEVINFO="Device: $2 (Install on: $2$3 No-Swap-Space)"
- else
- SWAP="/dev/$2$4 swap swap defaults 0 0"
- DEVINFO="Device: $2 (Install on: $2$3 Swap: $2$4)"
- fi
- echo "Before starting installation, make sure your disk well-formatted and ready to use..."
- #echo "Starting FDISK as you specified in command line..."
- echo "You can verify your disk at this stage! After that, there is no way to return!"
- echo "ALL OF YOUR DATA ON SPECIFIED DISK WILL BE ERASED!"
- echo "Press [ENTER] to continue, [CTRL+C] to exit."
- read junk
- echo "Notes about your input: "
- echo "Mount point: $1"
- echo "$DEVINFO"
- echo "Target file-system format ($2$3): $5"
- echo "File system label *If exists*($2$3): $6"
- echo -n "Are these values are true? [Y/N]: "
- read junk
- if echo $junk | grep -qi 'y' ; then
- echo "Proceeding Setup..."
- else
- echo "Cancelled by user..."
- exit 3
- fi
- #fdisk /dev/$2
- if [ "$6" ]; then
- mkfs.$5 /dev/$2$3 -L "$6"
- else
- mkfs.$5 /dev/$2$3
- fi
- if [ "$SWAP" ]; then
- mkfs.swap /dev/$2$4 -L slax-swap
- fi
- mkdir "$1" &>/dev/null
- mount /dev/$2$3 "$1"
- for dir in ${folders[*]}
- do
- echo -n "Copying /$dir ..."
- cp -R --preserve=all /"$dir" "$1" && echo " [ OK ]"
- done
- echo -n "Creating system directories..."
- mkdir -p "$1"/media
- mkdir -p "$1"/mnt
- mkdir -p "$1"/opt
- mkdir -p "$1"/proc
- mkdir -p "$1"/sys
- mkdir -p "$1"/tmp
- echo " [ OK ]"
- echo -n "Creating FSTAB..."
- echo -e "
- aufs / aufs defaults 0 0
- /dev/$2$3 / $5 defaults 1 1
- /dev/cdrom /mnt/cdrom auto noauto,owner,ro 0 0
- /dev/fd0 /mnt/floppy auto noauto,owner 0 0
- devpts /dev/pts devpts gid=5,mode=620 0 0
- proc /proc proc defaults 0 0
- tmpfs /dev/shm tmpfs defaults 0 0
- none /mnt/slaxdrive slaxdrive defaults 0 0
- $SWAP" > "$1"/etc/fstab && echo " [ OK ]"
- echo -n "Creating MTAB..."
- echo -e "
- /dev/root / $5 rw,errors=continue,data=ordered 0 0
- proc /proc proc rw 0 0
- sysfs /sys sysfs rw 0 0
- usbfs /proc/bus/usb usbfs rw 0 0
- tmpfs /dev/shm tmpfs rw 0 0
- " > "$1"/etc/mtab_ && echo " [ OK ]"
- echo -n "Copying BOOT data..."
- for file in $(echo "$filesb")
- do
- if [ -f "$file" ]; then
- cp "$file" "$1"/boot/
- fi
- done
- cp "$LIVE"/"$BOOT"/*.c32 "$1"/boot/
- if [ -f "$COM32_1" ]; then
- cp "$COM32_1" "$1"/boot/
- fi
- if [ -f "$COM32_2" ]; then
- cp "$COM32_2" "$1"/boot/
- fi
- echo " [ OK ]"
- echo -n "Installing Boot-Sector..."
- #cat "$1"/boot/mbr.bin > /dev/$2
- cat "$LIVE"/"$BOOT"/mbr.bin > /dev/$2
- echo " [ OK ]"
- if [ ! -e "$EXTL" ]; then
- echo -e "Could not found 'extlinux' binary..."
- echo -n "Please enter location of 'EXTLINUX' binary: "
- read EXTL
- fi
- "$EXTL" --install "$1"/boot/
- echo "Installing Boot-Loader... [ OK ]"
- ##### ASKING SOME... #####
- echo -n "Do you want to start X-Server automatically right after boot? [Y/N]: "
- read bootopt
- if echo $bootopt | grep -qi 'y' ; then
- flags="xmode,$flags"
- fi
- echo -n "Do you want to start PXE Server automatically right after boot? [Y/N]: "
- read bootopt
- if echo $bootopt | grep -qi 'y' ; then
- flags="pxe,$flags"
- fi
- echo -n "Enter VGA= parameter or leave it empty for default [normal]: "
- read bootopt
- if [ "$bootopt" ]; then
- vga="$bootopt"
- else
- vga="normal"
- fi
- ###-----###
- echo -n "Creating SYSLINUX.CFG..."
- echo -e "
- UI /boot/vesamenu.c32
- MENU TITLE Slax | Syslinux
- PROMPT 0
- TIMEOUT 10
- LABEL Slax
- MENU LABEL Slax 7
- KERNEL /boot/vmlinuz
- APPEND root=/dev/$2$3 printk.time=0 vga=$vga ro quiet slax.flags=$flags
- " > "$1"/boot/extlinux.conf
- echo " [ OK ]"
- if [ "$LABEL" ]; then
- sed 's/hostname=slax//g' /etc/NetworkManager/NetworkManager.conf > "$1"/etc/NetworkManager/NetworkManager.conf
- echo "hostname=$LABEL" >> "$1"/etc/NetworkManager/NetworkManager.conf
- fi
- modprobe -c >> "$1"/lib/modprobe.d/slax-modules.conf
- echo "\l `uname -o` \r | `cat /etc/slax-version` | \t - \d
- >> \n @ \o
- \s \m \v
- >> \U logged in.
- " >"$1"/etc/issue
- echo -n "Last question: Do you want to enable auto-login of root?
- (This may cause security issues) [Y/N]: "
- read autologin
- if echo $autologin | grep -qi 'y' ; then
- passwd -d root
- cp /etc/{shadow,passwd} "$1"/etc/
- sed 's/agetty/agetty -a root/g' /etc/inittab > "$1"/etc/inittab
- fi
- sed 's/\ --noclear//g' "$1"/etc/inittab > "$1"/inittab
- rm -f "$1"/etc/inittab && mv "$1"/inittab "$1"/etc/
- echo -n "Unmounting File Systems..."
- umount /dev/$2$3
- echo " [ OK ]"
- echo " --- "
- echo "
- Setup is (seems to be) completed.
- If you haven't set your partition active, set it now!
- Then reboot your computer!
- PS. Do 'fdisk /dev/$2' command
- Then press [A] and hit [ENTER]
- Press $3 and hit [ENTER] again.
- For saving and writing changes, press [W] and hit [ENTER] "
- exit 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement