Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- #-------------------------------------------------------------------------------
- # Script Created by Vincent - EZ-Arch Project (ezarchproject@gmail.com)
- # Distro Sourceforge - https://sourceforge.net/projects/ezarchlinux/
- # Distro Dailymotion - http://www.dailymotion.com/ezarchproject
- #
- # I shall be using Dailymotion more for the videos instead of Youtube.
- #
- #-------------------------------------------------------------------------------
- #This program is free software: you can redistribute it and/or modify
- #it under the terms of the GNU General Public License as published by
- #the Free Software Foundation, either version 3 of the License, or
- #(at your option) any later version.
- #
- #This program is distributed in the hope that it will be useful,
- #but WITHOUT ANY WARRANTY; without even the implied warranty of
- #MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- #GNU General Public License for more details.
- #
- #You should have received a copy of the GNU General Public License
- #along with this program. If not, see <http://www.gnu.org/licenses/>.
- #-------------------------------------------------------------------------------
- # Run this script after your first boot with archlinux (as root)
- #--------------------------------------------------------------------------------
- # Explaination of the Script:
- #
- # Disk Related Files and Menu. This deals with formatting, partitioning
- # and mounting of disks.
- #
- # MESGCONSOLE is pointed to /dev/tty8 in the ezarchinstall.conf
- # This may be different with Xorg version
- ##########################################################################
- ############################### Errors
- SelectDiskError()
- {
- $DIALOG --infobox "You must Select a Disk.\n\n This program cannot continue without a disk selected.\n\nPausing for 10 Seconds" 10 30 ; sleep 10
- }
- SelectFSError()
- {
- $DIALOG --infobox "You must select a filesystem that corresponds to the information" 8 30 ; sleep 10
- }
- SelectRootPartError()
- {
- $DIALOG --infobox "You must Select a partition to be /\n\n Pausing for 10 Seconds" 8 30 ; sleep 10
- }
- ########################################################################################################################
- DiskSetupMenu () # Root Menu for Disk Related Stuff
- {
- while :
- do
- $DIALOG --backtitle "$DISTNAME $DISTVER " --no-shadow \
- --ok-label 'Select' --cancel-label 'Back' \
- --title "$DISKFUNCTION" --menu "Select a menu option" 20 78 16 \
- "Select Disk" "Select Disk to use. ($DEV$DISK)" \
- "Partition" "Partition Selected Disk with choice of program ->" \
- "Main Partitions" "Format & Mount Root & Swap " \
- "Other Paritions" "Format & Mount Other Paritions " \
- "Mount Other Disks" "Mount other partitions without format" \
- "-----------------" "-------------------------------------" \
- "View Diskspace" "Shows disk spaces via df" 2> $tempfile
- mmretval=$?
- choice=`cat $tempfile`
- case $mmretval in
- 0)
- #Go to Choices
- echo "Selected $choice "
- diskmenuchoices
- rm -f $DELETEALLTMP > /dev/null
- ;;
- 1)
- #Returns to previous menu
- rm -f $DELETEALLTMP > /dev/null
- break
- ;;
- 255)
- # echo "ESC key pressed"
- rm -f $DELETEALLTMP > /dev/null
- break
- ;;
- esac
- done
- }
- diskmenuchoices()
- {
- case $choice in
- "Select Disk")
- SelectDisk
- ;;
- "Partition")
- PartitionDisk
- ;;
- "Main Partitions")
- RootandSwapPart
- ;;
- "Other Paritions")
- OtherPart
- ;;
- "Mount Other Disks")
- MountOtherDisk
- ;;
- "View Diskspace")
- #df -h | grep "^/" > statsfile.$$
- $DF -h > $TMP/statsfile.$$
- $DIALOG --backtitle "$DISTNAME $DISTVER" \
- --title "View Disk Spaces" \
- --textbox $TMP/statsfile.$$ 20 100
- rm -f $TMP/statsfile.$$
- ;;
- esac
- }
- SelectDisk()
- {
- # Shows disk and then Input Box
- # --begin 2 (Up/Down) 2 (Side Way)
- $LSBLK | grep disk > $TMP/statsfile.$$
- $DIALOG --begin 2 2 --backtitle "$DISTNAME $DISTVER" \
- --title "List of Disks on this computer" \
- --textbox $TMP/statsfile.$$ 7 50 --and-widget \
- --begin 10 2 \
- --backtitle "$DISTNAME $DISTVER" \
- --title "$DISKTITLE" \
- --inputbox "Please type the disk you want?\nYou do not need to include /dev" 10 50 2> $DISKTMP
- returnval=$?
- case $returnval in
- 0)
- DISK=`cat $DISKTMP`
- rm -f $DISKTMP
- rm -f $TMP/statsfile.$$
- ;;
- 1)
- rm -f $DISKTMP
- rm -f $TMP/statsfile.$$
- ;;
- 255)
- rm -f $DISKTMP
- rm -f $TMP/statsfile.$$
- ;;
- esac
- }
- ########################################### Other Disk Functions
- PartitionDisk()
- {
- if [ "$DISK" != "NULL" ]
- then
- while :
- do
- $DIALOG --backtitle "$DISTNAME $DISTVER " --no-shadow \
- --ok-label 'Select' --cancel-label 'Back' \
- --title "Partition $DEV$DISK" --menu "Select a menu option" 20 78 16 \
- "Fdisk" "Use the Linux Fdisk program" \
- "CFdisk" "Use CFDisk" \
- "Parted" "Use Parted" 2> $tempfile
- mmretval=$?
- choice=`cat $tempfile`
- case $mmretval in
- 0)
- case $choice in
- "Fdisk")
- $FDISK $DEV$DISK
- ;;
- "CFdisk")
- $CFDISK $DEV$DISK
- ;;
- "Parted")
- $PARTED $DEV$DISK
- ;;
- esac
- ;;
- 1)
- #Returns to previous menu
- break
- ;;
- 255)
- # echo "ESC key pressed"
- break
- ;;
- esac
- done
- else
- SelectDiskError
- fi
- }
- RootandSwapPart()
- {
- if [ "$DISK" != "NULL" ]
- then
- # Root Partition
- $LSBLK | grep $DISK | grep part > $TMP/statsfile.$$
- $DIALOG --begin 2 2 --backtitle "$DISTNAME $DISTVER" \
- --title "List of Disk partitions on this computer for $DEV$DISK" \
- --textbox $TMP/statsfile.$$ 10 75 --and-widget \
- --begin 10 2 \
- --backtitle "$DISTNAME $DISTVER" \
- --title "What Partition to Select for Root Partition" \
- --inputbox "Please type the partition to use as /\nYou do not need to include /dev" 9 75 2> $PARTMP
- RetPVal=$?
- case $RetPVal in
- 0)
- PART=`cat $PARTMP`
- ;;
- 1)
- rm -f $PARTMP $SWAPTMP $FILESYSTMP > /dev/null
- return 1
- ;;
- # 255
- # ;;
- esac
- # Prompt for Formatting the Root Partition
- $DIALOG --title "Confirm / partition" \
- --yesno "You Selected $DEV$PART\nDo you want to use it as /" 8 30
- ConfirmPartVal=$?
- case $ConfirmPartVal in
- 0)
- $DIALOG --backtitle "$DISTNAME $DISTVER " --no-shadow \
- --ok-label 'Select' --cancel-label 'Back' \
- --title "Format $DEV$DISK" --menu "Select a menu option" 20 78 16 \
- "ext4" "Use Ext4" \
- "ext3" "Use Ext3" \
- "ext2" "Use Ext2" \
- "reiserfs" "Use ReiserFS" 2> $FILESYSTMP
- FSTYPE=`cat $FILESYSTMP`
- case $FSTYPE in
- "ext4")
- $DIALOG --title "Formatting / partition" \
- --infobox "Formatting $DEV$PART with $FSTYPE" 8 30 ; sleep 2
- echo "Formatting $DEV$PART with $FSTYPE" > $MESGCONSOLE
- mkfs.ext4 -q -F $DEV$PART > $MESGCONSOLE
- $DIALOG --title "Mounting partition" \
- --infobox "Mount $DEV$PART to $MNT" 8 30 ; sleep 2
- echo "Mounting $DEV$PART to $MNT" > $MESGCONSOLE
- mount -v $DEV$PART $MNT > $MESGCONSOLE
- ;;
- "ext3")
- $DIALOG --title "Formatting / partition" \
- --infobox "Formatting $DEV$PART with $FSTYPE" 8 30 ; sleep 2
- echo "Formatting $DEV$PART with $FSTYPE" > $MESGCONSOLE
- mkfs.ext3 -q -F $DEV$PART > $MESGCONSOLE
- $DIALOG --title "Mounting partition" \
- --infobox "Mount $DEV$PART to $MNT" 8 30 ; sleep 2
- echo "Mounting $DEV$PART to $MNT" > $MESGCONSOLE
- mount -v $DEV$PART $MNT > $MESGCONSOLE
- ;;
- "ext2")
- $DIALOG --title "Formatting / partition" \
- --infobox "Formatting $DEV$PART with $FSTYPE" 8 30 ; sleep 2
- echo "Formatting $DEV$PART with $FSTYPE" > $MESGCONSOLE
- mkfs.ext2 -q -F $DEV$PART > $MESGCONSOLE
- $DIALOG --title "Mounting partition" \
- --infobox "Mount $DEV$PART to $MNT" 8 30 ; sleep 2
- echo "Mounting $DEV$PART to $MNT" > $MESGCONSOLE
- mount -v $DEV$PART $MNT > $MESGCONSOLE
- ;;
- "reiserfs" )
- $DIALOG --title "Formatting / partition" \
- --infobox "Formatting $DEV$PART with $FSTYPE" 8 30 ; sleep 2
- echo "Formatting $DEV$PART with $FSTYPE" > $MESGCONSOLE
- mkreiserfs -q -f $DEV$PART > $MESGCONSOLE
- $DIALOG --title "Mounting partition" \
- --infobox "Mount $DEV$PART to $MNT" 8 30 ; sleep 2
- echo "Mounting $DEV$PART to $MNT" > $MESGCONSOLE
- mount -v $DEV$PART $MNT > $MESGCONSOLE
- ;;
- esac
- ;;
- 1)
- rm -f $PARTMP $SWAPTMP $FILESYSTMP > /dev/null
- return 1
- ;;
- 255)
- ;;
- esac
- # -- Confirm Set up Swap Partition - Contains Nested Dialogs
- $DIALOG --title "Swap Partition" \
- --yesno "Do you want to set up a Swap partition" 8 30
- WantSwapVal=$?
- case $WantSwapVal in # 1st Dialog Box case Choice
- 0)
- $FDISK -l $DEV$DISK | grep swap > $TMP/statsfile.$$
- # $LSBLK | grep $DISK |grep part > $TMP/statsfile.$$
- $DIALOG --begin 2 2 --backtitle "$DISTNAME $DISTVER" \
- --title "List of Disk partitions on this computer for $DEV$DISK" \
- --textbox $TMP/statsfile.$$ 8 75 --and-widget \
- --begin 10 2 \
- --backtitle "$DISTNAME $DISTVER" \
- --title "What Swap Partition do you want?" \
- --inputbox "Please type the partition to use as swap if required\nYou do not need to include /dev" 10 75 2> $SWAPTMP
- RetSVal=$?
- case $RetSVal in # 2nd Dialog Box case choice
- 0)
- SWAP=`cat $SWAPTMP`
- # Prompt for Formatting the Swap Partition
- $DIALOG --title "Confirm Swap partition" \
- --yesno "You Selected $DEV$SWAP\nDo you want to use it as swap" 8 30
- ConfirmSwapVal=$?
- case $ConfirmSwapVal in #3rd Dialog Box Case Choice
- 0)
- $DIALOG --title "Confirm Swap partition" \
- --infobox "Formatting and swap on $DEV$SWAP" 8 30 ; sleep 3
- echo "Making Swap" > $MESGCONSOLE
- mkswap $DEV$SWAP > $MESGCONSOLE
- echo "Turning on Swap" $MESGCONSOLE
- swapon $DEV$SWAP > $MESGCONSOLE
- ;;
- 1)
- rm -f $DELETEALLTMP > /dev/null
- return 1
- ;;
- esac # ConfirmSwapVal
- ;;
- 1)
- rm -f $PARTMP $SWAPTMP $FILESYSTMP > /dev/null
- return 1
- ;;
- esac # RetSVal
- ;;
- 1)
- rm -f $PARTMP $SWAPTMP $FILESYSTMP > /dev/null
- return 1
- ;;
- esac #WantSwapVal
- rm -f $DELETEALLTMP > /dev/null
- else
- SelectDiskError
- fi
- }
- OtherPart() # Format and Mount other Partitions
- {
- if [ "$DISK" != "NULL" ]
- then
- $LSBLK | grep part > $TMP/statsfile.$$
- $DIALOG --begin 2 2 --backtitle "$DISTNAME $DISTVER" \
- --title "List of Disk partitions on this computer" \
- --textbox $TMP/statsfile.$$ 10 60 --and-widget \
- --begin 10 2 \
- --backtitle "$DISTNAME $DISTVER" \
- --title "$DISKTITLE" \
- --inputbox "Please type the partition to format & mount\nYou do not need to include /dev" 10 60 2> $PARTMP
- RetVal=$?
- case $RetVal in #1st Case
- 0)
- #Format Other Disk Part
- FOTHERDSKPART=`cat $PARTMP`
- $DIALOG --title "Confirm Other Disk partition" \
- --yesno "You Selected $DEV$FOTHERDSKPART\nDo you want to format it" 8 30
- FormatVal=$?
- case $FormatVal in # 2nd Case
- 0)
- $DIALOG --backtitle "$DISTNAME $DISTVER " --no-shadow \
- --ok-label 'Select' --cancel-label 'Back' \
- --title "Format $DEV$FOTHERDSKPART" --menu "Select a menu option" 20 78 16 \
- "ext4" "Use Ext4" \
- "ext3" "Use Ext3" \
- "ext2" "Use Ext2" \
- "reiserfs" "Use ReiserFS" 2> $FILESYSTMP
- FSTYPE=`cat $FILESYSTMP`
- case $FSTYPE in # 3rd Case
- "ext4")
- $DIALOG --title "Formatting partition" \
- --infobox "Formatting $DEV$FOTHERDSKPART with $FSTYPE" 8 30 ; sleep 2
- mkfs.ext4 -q -F $DEV$FOTHERDSKPART > $MESGCONSOLE
- ;;
- "ext3")
- $DIALOG --title "Formatting partition" \
- --infobox "Formatting $DEV$FOTHERDSKPART with $FSTYPE" 8 30 ; sleep 2
- mkfs.ext3 -q -F $DEV$FOTHERDSKPART > $MESGCONSOLE
- ;;
- "ext2")
- $DIALOG --title "Formatting partition" \
- --infobox "Formatting $DEV$FOTHERDSKPART with $FSTYPE" 8 30 ; sleep 2
- mkfs.ext2 -q -F $DEV$FOTHERDSKPART > $MESGCONSOLE
- ;;
- "reiserfs" )
- $DIALOG --title "Formatting partition" \
- --infobox "Formatting $DEV$FOTHERDSKPART with $FSTYPE" 8 30 ; sleep 2
- mkreiserfs -q -f $DEV$FOTHERDSKPART $MESGCONSOLE
- ;;
- esac #End of 3rd Case
- ;;
- 1)
- return 1
- ;;
- esac #End of 2nd Case
- ;;
- 1)
- return 1
- ;;
- esac # Finish 1st Case
- # Mount Points
- $DIALOG --backtitle "$DISTNAME $DISTVER" \
- --title "Mount the Partition" \
- --inputbox "Where do you want to mount it\nThis will mount under /mnt/custom dir" 10 75 2> $FODMNTPNTMP
- MntRetVal=$?
- case $MntRetVal in
- 0)
- MNTPNTSUBDIR=`cat $FODMNTPNTMP`
- $DIALOG --title "Mounting partition" \
- --infobox "Mount -t $FSTYPE $DEV$FOTHERDSKPART to $MNT$MNTPNTSUBDIR" 8 30 ; sleep 2
- if [ -d $MNT$MNTPNTSUBDIR ]
- then
- echo "$MNT$MNTPNTSUBDIR Exists, mounting" > $MESGCONSOLE
- mount -v -t $FSTYPE $DEV$FOTHERDSKPART $MNT$MNTPNTSUBDIR > $MESGCONSOLE
- else
- echo "$MNT$MNTPNTSUBDIR does not exists, creating dir & mounting" > $MESGCONSOLE
- mkdir -v $MNT$MNTPNTSUBDIR > $MESGCONSOLE
- mount -v -t $FSTYPE $DEV$FOTHERDSKPART $MNT$MNTPNTSUBDIR > $MESGCONSOLE
- fi
- ;;
- 1)
- return 1
- ;;
- esac
- $DIALOG --title "Any more to do?" \
- --yesno "Do you wish to format & mount more?" 8 30
- ConfirmRetVal=$?
- case $ConfirmRetVal in
- 0)
- OtherPart
- ;;
- 1)
- return 1
- ;;
- 255)
- return 1
- ;;
- esac
- else
- SelectDiskError
- fi
- rm -f $PARTMP $SWAPTMP $FILESYSTMP $FODMNTPNTMP > /dev/null
- }
- MountOtherDisk()
- {
- $LSBLK | grep part > $TMP/statsfile.$$
- $DIALOG --begin 2 2 --backtitle "$DISTNAME $DISTVER" \
- --title "List of Disk partitions on this computer" \
- --textbox $TMP/statsfile.$$ 10 60 --and-widget \
- --begin 10 2 \
- --backtitle "$DISTNAME $DISTVER" \
- --title "Mount Disk" \
- --inputbox "Please type the partition to mount\nYou do not need to include /dev" 10 60 2> $DISKTMP
- RetVal1=$?
- case $RetVal1 in
- 0)
- OTHERDISK=`cat $DISKTMP`
- ;;
- 1)
- return 1
- ;;
- esac
- $DIALOG --backtitle "$DISTNAME $DISTVER " --no-shadow \
- --ok-label 'Select' --cancel-label 'Back' \
- --title "Mount with Filesystem type" --menu "Select a menu option" 20 78 16 \
- "--------" "Linux Filesystems" \
- "ext4" "Mount ext4 filesystem" \
- "ext3" "Mount ext3 filesystem" \
- "ext2" "Mount ext2 filesystem" \
- "reiserfs" "Use ReiserFS" \
- "--------" "Other Filesystems" \
- "msdos" "Dos Formatted" \
- "vfat" "Windows 9x or higher filesystem" 2> $FSTYPTMP
- # Filesystem Type
- RetVal2=$?
- case $RetVal2 in # RetVal2
- 0)
- FSTYPE=`cat $FSTYPTMP`
- case $FSTYPE in
- "ext4")
- ;;
- "ext3")
- ;;
- "ext2")
- ;;
- "reiserfs")
- ;;
- "msdos")
- ;;
- "vfat")
- ;;
- esac
- ;;
- 1)
- return 1
- ;;
- esac # RetVal2
- #Mounting the Disk
- $DIALOG --backtitle "$DISTNAME $DISTVER" \
- --title "Mount Point" \
- --inputbox "Please Enter the Mount Point\nThis will be placed under $MNT/subdir\nSo do not type /mnt" 10 60 2> $MNTPRTTMP
- RetVal3=$?
- case $RetVal3 in
- 0)
- CMNTPNT=`cat $MNTPRTTMP`
- $DIALOG --title "Mounting partition" \
- --infobox "mount -t $FSTYPE $DEV$OTHERDISK to $MNT$CMNTPNT" 8 30 ; sleep 10
- if [ -d $MNT$CMTPNT]
- then
- echo "$MNT$CMNTPNT exists mounting" > $MESGCONSOLE
- mount -v -t $FSTYPE $DEV$OTHERDISK $MNT$CMNTPNT > $MESGCONSOLE
- else
- echo "$MNT$CMNTPNT does not exist, creating then mounting" > $MESGCONSOLE
- mkdir -v $MNT$CMNTPNT > $MESGCONSOLE
- mount -v -t $FSTYPE $DEV$OTHERDISK $MNT$CMNTPNT > $MESGCONSOLE
- fi
- ;;
- 1)
- return 1
- ;;
- esac
- $DIALOG --title "Any more to do?" \
- --yesno "Do you wish to mount any more disks?" 8 30
- ConfirmRetVal=$?
- case $ConfirmRetVal in
- 0)
- MountOtherDisk
- ;;
- 1)
- return 1
- ;;
- 255)
- return 1
- ;;
- esac
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement