Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- #-------------------------------------------------------------------------------
- #Created by Vincent mailto: Vincent[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 Script is designed to be run independantly and to be deleted after completion
- # This file is usually put in to / of the hard disk during installation and then is
- # ran after doing arch-chroot /mnt
- #
- #
- # 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
- #Global Settings
- DEV=/dev/
- TMP=/tmp/tmp.$$
- TMP2=/tmp/tmp2.$$
- EDITOR=vim
- ETC=/etc/
- DFOUT=/tmp/df.$$
- #Varibles to Ensure Configured Usually set to Not Configured until
- #task is done
- TASK1='-'
- TASK2='-'
- TASK3='-'
- TASK4='-'
- TASK5='-'
- TASK6='-'
- TASK7='-'
- ZONEINFOTXT='/opt/setup/txt/zone.txt'
- ZONEINFODIR='/usr/share/zoneinfo/'
- LOCALTIME='/etc/localtime'
- LOCALEGEN="/etc/locale.gen"
- BOOTLOADER=" "
- SYSLINUXCFG=/boot/syslinux/syslinux.cfg
- #User Stuff
- DEFHOME=/home
- SKEL=/etc/skel
- PASSWD=/etc/passwd
- HOMEDIR=NULL
- #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)
- #The config users.
- # ---------------------- To Confirm ------------------------------
- print_confirmadd() {
- echo
- echo -en "${Bold} Is this OK? (Y/N): ${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
- echo 1. Syslinux
- echo 2. Grub
- echo 3. Change Root Disk
- echo
- print_askopt
- read bootopt
- case $bootopt in
- 1)
- echo "Syslinux Seleted"
- BOOTLOADER=Sys linux
- echo "pacman -S syslinux"
- pacman -S syslinux
- echo "syslinux-install_update -iam"
- syslinux-install_update -iam
- echo "cp $SYSLINUXCFG $SYSLINUXCFG.orig"
- cp $SYSLINUXCFG $SYSLINUXCFG.orig
- echo "Edit sys linux to match the root disk"
- echo "of /dev/sda3 to the one on this computer"
- sleep 4
- vi $SYSLINUXCFG
- ;;
- 2)
- echo "Grub Selected"
- read -p "What partition to install it to (Without /dev/)? " partition
- echo "pacman -S grub"
- pacman -S grub
- echo "grub-install --target=i386-pc --recheck /dev/$partition"
- grub-install --target=i386-pc --recheck /dev/$partition
- echo "grub-mkconfig -o /boot/grub/grub.cfg"
- grub-mkconfig -o /boot/grub/grub.cfg
- ;;
- 3)
- echo
- echo -en "${Bold}What do you want as root disk${Reset}:"
- read $ROOTDSK
- esac
- if [ "$BOOTLOADER" != " " ]
- then
- echo "continue"
- echo "Boot loader: $BOOTLOADER"
- else
- echo "Select a boot loader"
- fi
- }
- ### 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 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_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
- # This script was taken from AUI installer as I always wanted a decent script that
- # does this
- settimezone() { #{{{
- # local zone=(`timedatectl list-timezones | sed 's/\/.*$//' | uniq`);
- 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=(`ls $ZONEINFO | grep ${ZONE} | sed 's/^.*\///'`)
- 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
- echo " ln -sf $ZONEINFODIR/$ZONE/$SUBZONE $LOCALTIME"
- ln -sf $ZONEINFODIR/$ZONE/$SUBZONE $LOCALTIME
- break
- else
- invalid_option
- fi
- done
- break
- else
- invalid_option
- fi
- done
- } #}}}
- } #}}}
- ##########################################################################
- ########################## Main Part of the Installer ##################
- PostMenu() {
- print_title " *** Post Install *** "
- dfspace
- echo
- echo -e "1. Set Hostname [$TASK1]"
- echo "2. Set up Zone Info [$TASK2]"
- echo "3. Configure the Locales [$TASK3]"
- echo "4. Run mkinitcpio [Make Ramdisk] [$TASK4]"
- echo "5. Root Password [$TASK5]"
- echo "6. Add users to System [$TASK6]"
- echo "7. Install a Boot manager [$TASK7]"
- echo "8. Anything Else (Not Implented)"
- print_line
- echo "Q. Quit"
- print_askopt
- read OPT
- case $OPT in
- 1)
- 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}"
- ;;
- 2)
- settimezone
- TASK2="${Green}X${Reset}"
- ;;
- 3)
- echo "3"
- vi $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}F${Reset}"
- ;;
- esac
- ;;
- 4)
- echo "4"
- mkinitcpio -p linux
- TASK4="${Green}X${Reset}"
- ;;
- 5)
- echo "5"
- echo "Setting passwd for root"
- passwd
- while [[ $? -ne 0 ]]
- do
- passwd
- done
- TASK5="${Green}X${Reset}"
- ;;
- 6)
- echo "6"
- addnewuser
- TASK6="${Green}X${Reset}"
- ;;
- 7)
- echo "7"
- install_bootloader
- TASK7="${Green}X${Reset}"
- ;;
- 8)
- echo "8"
- TASK8="${Green}X${Reset}"
- ;;
- Q|q)
- echo "Exiting............."
- mv /Setup /root/setup.finished
- chmod -x /root/setup.finished
- exit 0
- ;;
- esac
- pause_function
- PostMenu
- }
- PostMenu
- rm /tmp/tmp.*
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement