Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- #-------------------------------------------------------------------------------
- #Created by Vincent mailto: ezarchproject[at]gmail[dot]com
- #inspired by script that was created by user helmuthdu
- #mailto: helmuthdu[at]gmail[dot]com
- #Contribution: flexiondotorg
- #-------------------------------------------------------------------------------
- #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:
- #
- # This is the Main Script that runs the menu system. This is designed
- # for live Systems to install an Operating System to the hard disk.
- #
- # This is to be ran by root.
- #
- # This file is designed to be removed after installing.
- # However other scripts similar to this will be found in /opt/setup
- # for various stuff
- #
- #
- # This file is used by installers that do not require the internet
- # to install the live cd image to their hard disk and requires configuration
- #
- #
- #
- EDITOR=nano
- PROGDIR=/opt/setup
- #Global Settings
- ZONEINFOTXT='/opt/setup/txt/zone.txt'
- ZONEINFODIR='/usr/share/zoneinfo/'
- LOCALTIME='/etc/localtime'
- LOCALEGEN="/etc/locale.gen"
- # Boot Loader Stuff
- BOOTLOADER=" "
- SLFILES=/opt/setup/syslinux # Contains Syslinux related files
- SLTXT='/opt/setup/txt/syslinux.txt' # Contains filename list of Syslinux config files on in that directory
- SLCFGFILE=/boot/syslinux/syslinux.cfg # Default config file
- CVSPLASH=/opt/setup/syslinux/splash.png #Current Version Splash
- # Xorg Defaults to install
- XORGDEFAULTS='xorg xorg-xinit xorg-server xorg-xclock xorg-twm xterm openmotif terminus-font geany tmux feh'
- #User Stuff
- DEFHOME=/home
- SKEL=/etc/skel
- PASSWD=/etc/passwd
- HOMEDIR=NULL
- ROOTSHELL=/bin/bash
- # Other Environment
- DEV=/dev/
- TMP=/tmp/tmp.$$
- TMP2=/tmp/tmp2.$$
- ETC=/etc/
- DFOUT=/tmp/df.$$
- #TASKs
- TASK0='-'
- TASK1='-'
- TASK2='-'
- TASK3='-'
- TASK4='-'
- TASK5='-'
- TASK6='-'
- TASK7='-'
- TASK8='-'
- #Set Colors using echo -e ${COLOR} functions
- # Bash Colors are found here
- # http://misc.flogisoft.com/bash/tip_colors_and_formatting
- #
- # Color Idea came from Tuxhat installer but actual code below
- # came from the website above and implented in to tuxhat-installer
- # when correcting mistakes.
- if [[ `id -u ` -ne 0 ]] ; then
- echo "Need to be root"
- exit 1
- fi
- Bold=$(tput bold)
- Underline=$(tput sgr 0 1)
- Reset=$(tput sgr0)
- # Regular Colors
- Red=$(tput setaf 1)
- Green=$(tput setaf 2)
- Yellow=$(tput setaf 3)
- Blue=$(tput setaf 4)
- Purple=$(tput setaf 5)
- Cyan=$(tput setaf 6)
- White=$(tput setaf 7)
- ### This Section is from GlobalFunc so it does not rely on seperate files
- ### for the 2nd part of the installer.
- ###
- ########################################################################
- print_askopt() {
- echo
- echo -en "${Bold}Which Option do you require ${Reset}: "
- }
- print_title() { #{{{
- clear
- print_line
- echo -e "# $Red EZ-Arch Linux Installer ${Bold}$1${Reset} "
- print_line
- echo ""
- } #}}}
- print_title_nocls() { #{{{
- echo -e "# ${Bold}$1${Reset} "
- print_line
- echo ""
- } #}}}
- pause_function() { #{{{
- print_line
- if [[ $AUTOMATIC_MODE -eq 0 ]]; then
- read -e -sn 1 -p "Press enter to continue..."
- fi
- }
- print_line() { #{{{
- printf "%$(tput cols)s\n"|tr ' ' '-'
- } #}}}
- print_dbline() { #{{{
- printf "%$(tput cols)s\n"|tr ' ' '='
- } #}}}
- print_confirmadd() {
- echo
- echo -en "${Bold} Is this OK? (Y/N): ${Reset}"
- }
- print_warning() { #{{{
- T_COLS=`tput cols`
- echo -e "${Bold}${Yellow}$1${Reset}\n" | fold -sw $(( $T_COLS - 1 ))
- } #}}}
- invalid_option() { #{{{
- print_line
- echo "Invalid option. Try another one."
- pause_function
- } #}}}
- contains_element() { #{{{
- #check if an element exist in a string
- for e in "${@:2}"; do [[ $e == $1 ]] && break; done;
- } #}}}
- dfspace() { #{{{{
- echo "******************* Disk Spaces *************************"
- df -Th -t ext4 -t ext3 -t ext2 -t vfat -t reiserfs |sed '1d' > $DFOUT
- printf "%-10s \t %-10s \t %-5s \t %-5s \t %-5s\n" Device FS-Type Total Avail 'Mount Dir'
- print_dbline
- awk '{printf "%-10s \t %-10s \t %-5s \t %-5s \t %-5s\n", $1, $2, $3, $5, $7 }' $DFOUT
- print_line
- rm $DFOUT
- }
- # Functions
- RemoveLiveCDStuff ()
- {
- echo -e "${BYellow}This is a required Step for setting up the system${Reset}"
- echo
- echo "As you chose to install EZ-Arch with out using the internet"
- echo "The installer would of copied the live image to the hard disk"
- echo "The elements of the live image needs to be removed as it is useless"
- echo "to a running system"
- echo
- echo "This part is automatic and will get through this with minimal"
- echo "promptings."
- echo
- echo "This idea is probley best done with very big distros but installing"
- echo "via the internet should be still possible"
- echo
- echo "If you have a network do you use DHCP or manual"
- echo
- # while :
- # do
- echo " 1. DHCP 2. Manual 3. None "
- echo
- echo "Q to return to main manu"
- read NETOPTS
- case $NETOPTS in
- 1)
- echo "DHCP Is chosen it can be left there"
- NETWORK=DHCP
- ;;
- 2)
- echo "No DHCP is used so it can be removed"
- NETWORK=Manual
- rm -v /etc/udev/rules.d/81-dhcpcd.rules
- ;;
- 3)
- echo "No Network"
- NETWORK=none
- rm -v /etc/udev/rules.d/81-dhcpcd.rules
- ;;
- *)
- invalid_option
- return 1
- ;;
- esac
- # done
- # Rest of this should be automatic
- #Disable & remove the services created by ArchISO
- echo "Setting Journal information"
- sed -i 's/Storage=volatile/#Storage=auto/' /etc/systemd/journald.conf
- echo "Disabling pacman-init and choose-mirror services"
- systemctl disable pacman-init.service choose-mirror.service
- echo "Deleting the live cd services"
- rm -vr /etc/systemd/system/{choose-mirror.service,pacman-init.service,etc-pacman.d-gnupg.mount,getty@tty1.service.d}
- echo "Removing Spcecial Live CD Scripts"
- #rm -v /etc/systemd/system/getty@tty1.service.d/autologin.conf
- rm -v /root/.automated_script.sh
- rm -v /root/.zlogin
- rm -v /etc/sudoers.d/g_wheel
- rm -v /etc/mkinitcpio-archiso.conf
- rm -rv /etc/initcpio
- echo " Removing Arch user from the system"
- userdel -r arch
- TASK0="${Green}X${Reset}"
- }
- #--------------------- Add user Script some ideas taken from FreeBSD ---------
- addnewuser()
- {
- print_title "*** Adding new users to the new system ***"
- echo
- echo "Skel Files are automatically created with the home directory"
- echo "This can selected or re-ran for multiple users after it returns"
- echo "to main menu"
- echo
- read -p "Username: " username
- echo $username
- HOMEDIR=$DEFHOME/$username #Idea from Scripting on Novell Netware
- read -p "Full name (Press Enter to leave blank): " fname
- echo " User Name: $username"
- echo " Full name: $fname"
- echo " Home Directory $HOMEDIR"
- while :
- do
- print_confirmadd
- read ConfirmYN
- case $ConfirmYN in
- [Yy][Ee][Ss]|[Yy][Ee]|[Yy])
- #adduser
- echo "User is added"
- if [ "$fname" = "" ]
- then
- echo "useradd -m -d $HOMEDIR $username"
- useradd -m -d $HOMEDIR $username
- else
- echo useradd -m -c "$fname" -d $HOMEDIR $username
- useradd -m -c "$fname" -d $HOMEDIR $username
- #echo "Chfn ${username}"
- echo "Setting Password for ${username}"
- passwd ${username}
- while [[ $? -ne 0 ]]
- do
- passwd ${username}
- done
- fi
- return 1
- ;;
- [Nn][Oo]|[Nn])
- return 1 # Returns to the Menu
- ;;
- *)
- echo "You must select Y/N"
- ;;
- esac
- done
- }
- printdisks() {
- print_line
- df / | sed '1d' > $TMP
- awk '{printf "Root Disk mount Point :%-5s \t Disk Device %5s\n", $6, $1}' $TMP
- print_line
- echo "Checking for boot partition if returns with nothing you can install to root"
- print_line
- mount | column -t | grep /boot > $TMP2
- awk '{printf "Boot Partition Mount %-5s \t Device: %-5s \n", $3, $1}' $TMP2
- print_line
- }
- install_bootloader() {
- ROOTDSK=`df / | sed '1d' | awk '{print $1}'`
- print_title "**** Install Bootloader ****"
- echo
- printdisks
- echo
- echo "Root Disk appears to be $ROOTDSK"
- echo "Running syslinux-install_update -iam"
- syslinux-install_update -iam
- echo "cp $SLCFGFILE $SLCFGFILE.orig"
- cp -v $SLCFGFILE $SLCFGFILE.orig
- cp -v $CVSPLASH /boot/syslinux
- sleep 1
- selectsyslinuxcfg
- }
- # This script was taken from AUI installer as I always wanted a decent script that
- # does this
- settimezone() { #{{{
- local zone=(`cat $ZONEINFOTXT | sed 's/\/.*$//' | uniq`);
- PS3="$prompt1"
- echo "Select zone:"
- select ZONE in "${zone[@]}"; do
- if contains_element "$ZONE" "${zone[@]}"; then
- local subzone=(`cat $ZONEINFOTXT | grep ${ZONE} | sed 's/^.*\///'`)
- PS3="$What Timezone: "
- echo "Select subzone:"
- select SUBZONE in "${subzone[@]}"; do
- if contains_element "$SUBZONE" "${subzone[@]}"; then
- ln -sf $ZONEINFODIR/$ZONE/$SUBZONE $LOCALTIME
- break
- else
- invalid_option
- fi
- done
- break
- else
- invalid_option
- fi
- done
- } #}}}
- selectsyslinuxcfg(){
- PS3="Select Config file relevent root disk: "
- #Already declared
- #SLFILES=/opt/setup/syslinux
- #SLTXT='/opt/setup/txt/syslinux.txt'
- #SLCFGFILE=/boot/syslinux/syslinux.cfg
- ROOTDSK=`df / | sed '1d' | awk '{print $1}'`
- print_title "Syslinux Configs"
- echo
- echo " Current root Disk is $ROOTDSK"
- print_line
- local cfgfiles=(`cat $SLTXT | sed 's/\/.*$//' | uniq`);
- echo "Select Syslinux cfg file that is right for your root disk"
- echo
- select SLCFG in "${cfgfiles[@]}"
- do
- if contains_element "$SLCFG" "${cfgfiles[@]}"
- then
- echo "cp -v $SLFILES/$SLCFG $SYSLINUXCFG"
- cp -v $SLFILES/$SLCFG $SLCFGFILE
- echo
- break
- else
- invalid_option
- fi
- done
- }
- ######################################## MENU
- EditConfFiles() {
- while :
- do
- echo
- print_title "*** Edit Config Files ***"
- echo
- echo Default Editor $EDITOR
- echo
- echo "1. Select Editor"
- echo "2. Edit fstab"
- echo "3. Edit /etc/hosts"
- echo "4. Edit Pacman.conf & Update"
- echo "Q. Quit"
- echo
- print_askopt
- read Conf
- case $Conf in
- 1)
- echo "Available Editors on the system is"
- echo "vi or nano"
- echo -n "Which Editor: "
- read EDITOR
- ;;
- 2)
- $EDITOR /etc/fstab
- ;;
- 3)
- $EDITOR /etc/hosts
- ;;
- 4) $EDITOR /etc/pacman.conf
- echo -ne "${Bold}Did you change anything Y/N${Reset}: "
- read YN
- case $YN in
- Y|y|Yes|yes|YES)
- echo "Refreshing database"
- echo
- pacman -Sy
- ;;
- No|N|n|no)
- echo "Nothing Changed"
- ;;
- esac
- ;;
- q|Q)
- return 1
- ;;
- esac
- done
- }
- PostMenu() {
- print_title " *** Post Install *** "
- dfspace
- echo
- echo -e "1. Remove LiveCD stuff from system [$TASK0]"
- echo -e "2. Set Hostname [$TASK1]"
- echo -e "3. Set up Zone Info [$TASK2]"
- echo -e "4. Configure the Locales [$TASK3]"
- echo -e "5. Run mkinitcpio [Make Ramdisk] [$TASK4]"
- echo -e "6. Root Password [$TASK5]"
- echo -e "7. Add users to System [$TASK6]"
- echo -e "8. Install a Boot manager (Syslinux) [$TASK7]"
- #echo -e "9. Install X-Org & Open Motif [$TASK8]"
- print_line
- echo "Q. Quit"
- echo "E. Edit config files"
- print_askopt
- read OPT
- case $OPT in
- 1)
- RemoveLiveCDStuff
- TASK0="${Green}X${Reset}"
- ;;
- 2)
- echo "1"
- echo -ne "${Bold}${Green}Type in a hostname for this pc: ${Reset}"
- read hostname
- echo "echo $hostname > /etc/hostname"
- echo "$hostname" > /etc/hostname
- TASK1="${Green}X${Reset}"
- ;;
- 3)
- settimezone
- TASK2="${Green}X${Reset}"
- ;;
- 4)
- echo "3"
- nano $LOCALEGEN
- echo -n "Have you edited it for your need? "
- read YN
- case $YN in
- Y|Yes|y|yes)
- locale-gen
- TASK3="${Green}X${Reset}"
- ;;
- N|No|n|no)
- echo "re-edit"
- TASK3="${Red}*${Reset}"
- ;;
- esac
- ;;
- 5)
- echo "4"
- mkinitcpio -p linux
- TASK4="${Green}X${Reset}"
- ;;
- 6)
- echo "5"
- echo "Setting passwd for root"
- passwd
- while [[ $? -ne 0 ]]
- do
- passwd
- done
- chsh -s $ROOTSHELL
- TASK5="${Green}X${Reset}"
- ;;
- 7)
- echo "6"
- addnewuser
- TASK6="${Green}X${Reset}"
- ;;
- 8)
- echo "7"
- install_bootloader
- TASK7="${Green}X${Reset}"
- ;;
- 9)
- echo
- echo "Installation of Xorg as the same as on"
- echo "the Live CD with Open Motif"
- echo
- echo "You may install more Window managers manually with"
- echo "pacman -S window-manager"
- echo
- pause_function
- echo
- echo "Commencing......"
- echo
- pacman -S $XORGDEFAULTS
- if [[ "$?" -ne 0 ]]
- then
- print_warning "Program Failed"
- TASK8="${Red}F${Reset}"
- else
- echo "Installed"
- TASK8="${Green}X${Reset}"
- fi
- ;;
- Q|q)
- echo "Exiting............."
- echo "Removing Setup and placing it in /root"
- mv /Setup /root/setup.finished
- chmod -x /root/setup.finished
- exit 0
- ;;
- E|e)
- EditConfFiles
- ;;
- esac
- pause_function
- PostMenu
- }
- PostMenu
- rm /tmp/tmp.*
Add Comment
Please, Sign In to add comment