Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- #----------------------------------------------------------------------------------------
- # Script Created by Gary Perreault - Tux Hat Linux Project ([email protected])
- # Distro Sourceforge - https://sourceforge.net/projects/tuxhatlinux/
- # Distro Dailymotion - http://www.dailymotion.com/tuxhatlinux
- #----------------------------------------------------------------------------------------
- #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:
- #
- # Setup-Tuxhat using Dialog
- #
- ##########################################################################################
- #----------------{ Colours for the text part }----------------#
- 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)
- # Bold
- BRed=${Bold}$(tput setaf 1)
- BGreen=${Bold}$(tput setaf 2)
- BYellow=${Bold}$(tput setaf 3)
- BBlue=${Bold}$(tput setaf 4)
- BPurple=${Bold}$(tput setaf 5)
- BCyan=${Bold}$(tput setaf 6)
- BWhite=${Bold}$(tput setaf 7)
- #Menu Specific Stuff
- DIALOG=${DIALOG=dialog}
- FUNCTION='Main Menu Setup'
- DIALOGRC=/opt/setup/tuxhat
- DIALOGRC=${DIALOGRC}
- #--------------------{ Global Settings }-------------------------#
- DISTNAME='Tux Hat Linux '
- DISTVER='v3.4'
- DEV=/dev/
- DISK=NULL
- MNT=/mnt #Default mount point for filesystem's root upon preparing
- EDITOR=nano
- PS3="$prompt1"
- TMP=/tmp/tmp.$$
- TMP2=/tmp/tmp2.$$
- SELECTEDDSK="No Disk Selected: $DEV$DISK"
- DFOUT=/tmp/dfout.$$
- ROOTDSK=`df / | sed '1d' | awk '{print $1}'`
- BOOTLOADERINSTALL="pacstrap /mnt syslinux"
- HOSTS="nano /mnt/etc/hosts"
- EDITLOCALE="nano /mnt/etc/locale.gen"
- EDITOR=nano
- #-----------{ Functions to be used as a helper program }-------------#
- CONFIGFILE=/opt/setup/setup-tuxhat.conf
- # PROMPT {{{
- prompt1="Enter your option: "
- print_askopt() {
- echo
- echo -en "${Bold}${Blue}Which Option do you require: "
- }
- print_askopt2() {
- echo
- echo -en "${Bold}${Blue}Which setup script do you require: "
- }
- print_title0() { #{{{
- clear
- echo -e "${BBlue}**** Setup Hostname ****"
- } #}}}
- print_title1() { #{{{
- clear
- echo -e "${BBlue}**** Setup New User ****"
- } #}}}
- print_title2() { #{{{
- clear
- echo -e "${BBlue}**** Setup Network *****"
- } #}}}
- pause_function() { #{{{
- #print_line
- printf "%$(tput cols)s\n"|tr ' ' '-'
- echo
- 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 ' ' '='
- } #}}}
- #-------------------{ Disk partition and stuff }---------------------#
- SelectDisk() { #{{{
- echo "${BBlue}Available Disks on Computer"
- echo
- lsblk | grep disk > $TMP
- printf "%-10s \t %-10s\n" 'Available Disk' 'Total Size'
- print_dbline
- awk '{printf "%-17s %-10s\n", $1, $4}' $TMP
- print_line
- echo
- echo "${BBlue}sda usually means whole disk so no partition"
- echo "number is required"
- echo
- echo "${BBlue}There is no need to put /dev on front as it is"
- echo "a default directory."
- echo
- echo -n "${BBlue}What Disk do you want to use: "
- read DISK
- echo "${BBlue}You selected $DEV$DISK"
- echo ""
- rm $TMP
- sleep
- } #}}}}
- PartitionDisks() { #{{{
- if [ "$DISK" != "NULL" ]
- then
- echo "${BBlue}What partition program to use on $DEV$DISK"
- echo ""
- echo "${BBlue}F - Fdisk"
- echo "${BBlue}C - Cfdisk"
- echo "${BBlue}P - Parted"
- echo ""
- print_askopt
- read PARTPROG
- case $PARTPROG in
- F|f)
- fdisk $DEV$DISK
- ;;
- C|c)
- cfdisk $DEV$DISK
- ;;
- P|p)
- parted $DEV$DISK
- ;;
- esac
- else
- echo "${Bold}${Red}No Disk is Selected, please select one"
- sleep 5
- fi
- } #}}}
- formatrootpart() {
- if [ "$DISK" != "NULL" ]
- then
- print_line
- lsblk | grep $DISK
- print_line
- echo ""
- echo "${BBlue}Tux Hat Linux is only setup with / Root"
- echo ""
- read -p "Partition name without the /dev [ex: sda1]: " ROOTDISK
- clear
- print_line
- echo "Please choose 1 partition format usually ext4"
- print_line
- echo ""
- echo "1. Ext2"
- echo "2. Ext3"
- echo "3. Ext4"
- echo "4. ReiserFS"
- echo ""
- print_askopt
- read FSOPT
- case $FSOPT in
- 1)
- mkfs.ext2 $DEV$ROOTDISK
- ;;
- 2)
- mkfs.ext3 $DEV$ROOTDISK
- ;;
- 3)
- mkfs.ext4 $DEV$ROOTDISK
- ;;
- 4)
- mkfs.reiserfs $DEV$ROOTDISK
- ;;
- esac
- echo "${BBlue}Mounting $DEV$ROOTDISK to $MNT"
- mount $DEV$ROOTDISK $MNT
- else
- echo "${Bold}${Red}You must select a disk"
- sleep 5
- fi
- }
- #----------------------{ Copy /opt to /mnt/opt }----------------------#
- cp_opt(){
- DIALOGRC=${DIALOGRC}
- CONFIGFILE=/opt/setup/setup-tuxhat.conf
- DIALOG=${DIALOG=dialog}
- # config file for theme black and white
- if [[ -f $CONFIGFILE ]]; then
- source $CONFIGFILE
- else
- echo "Error missing file: setup-tuxhat.conf - Required by program"
- exit 1
- fi
- ## Create an array of all files in /opt directory
- DIRS=(/opt/*)
- #Destination directory
- DEST="/mnt/opt"
- # Create $DEST if does not exits
- [ ! -d $DEST ] && mkdir -p $DEST
- # Show a progress bar
- # ---------------------------------
- # Redirect dialog commands input using substitution
- #
- DIALOGRC="$DIALOGRC" $DIALOG --backtitle "$DISTNAME$DISTVER" --title "Copy System files" --gauge "Copying files..." 10 75 < <(
- # Get total number of files in array
- n=${#DIRS[*]};
- # set counter - it will increase every-time a file is copied to $DEST
- i=0
- #
- # Start the for loop
- #
- # read each file from $DIRS array
- # $f has filename
- for f in "${DIRS[@]}"
- do
- # calculate progress
- PCT=$(( 100*(++i)/n ))
- # update dialog box
- cat <<EOF
- XXX
- $PCT
- Copying file $f
- To $DEST
- XXX
- EOF
- # copy file $f to $DEST
- /bin/cp -ar $f ${DEST} &>/dev/null
- done
- )
- }
- #--------------------{ Copy Bin to /mnt/usr/bin }-----------------#
- cp_bin(){
- DIALOGRC=${DIALOGRC}
- CONFIGFILE=/opt/setup/setup-tuxhat.conf
- DIALOG=${DIALOG=dialog}
- # config file for theme black and white
- if [[ -f $CONFIGFILE ]]; then
- source $CONFIGFILE
- else
- echo "Error missing file: setup-tuxhat.conf - Required by program"
- exit 1
- fi
- ## Create an array of all files in /opt directory
- DIRS=(/opt/setup/bin/setup-tuxhat/*)
- #Destination directory
- DEST="/mnt/usr/bin/"
- # Create $DEST if does not exits
- [ ! -d $DEST ] && mkdir -p $DEST
- # Show a progress bar
- # ---------------------------------
- # Redirect dialog commands input using substitution
- #
- DIALOGRC="$DIALOGRC" $DIALOG --backtitle "$DISTNAME$DISTVER" --title "Copy System files" --gauge "Copying files..." 10 75 < <(
- # Get total number of files in array
- n=${#DIRS[*]};
- # set counter - it will increase every-time a file is copied to $DEST
- i=0
- #
- # Start the for loop
- #
- # read each file from $DIRS array
- # $f has filename
- for f in "${DIRS[@]}"
- do
- # calculate progress
- PCT=$(( 100*(++i)/n ))
- # update dialog box
- cat <<EOF
- XXX
- $PCT
- Copying file $f
- To $DEST
- XXX
- EOF
- # copy file $f to $DEST
- /bin/cp -ar $f ${DEST} &>/dev/null
- done
- )
- }
- #-------------------------{ CREATE NEW USER }--------------------------#
- create_new_user(){
- print_title1
- echo ""
- read -p "Enter New User: " username
- username=`echo $username | tr '[:upper:]' '[:lower:]'`
- arch-chroot /mnt useradd -m -g users -G wheel -s /bin/bash ${username}
- arch-chroot /mnt chfn ${username}
- arch-chroot /mnt passwd ${username}
- }
- #---------------------{ Copy Skel to new user }------------------------#
- cp_skel(){
- ## Create an array of all files in /opt directory
- DIRS=(/home/arch/.*)
- #Destination directory
- DEST=/mnt/home/${username}
- # Create $DEST if does not exits
- [ ! -d $DEST ] && mkdir -p $DEST
- # Show a progress bar
- # ---------------------------------
- # Redirect dialog commands input using substitution
- #
- DIALOGRC="$DIALOGRC" $DIALOG --backtitle "$DISTNAME$DISTVER" --title "Copy System files" --gauge "Copying files..." 10 75 < <(
- # Get total number of files in array
- n=${#DIRS[*]};
- # set counter - it will increase every-time a file is copied to $DEST
- i=0
- #
- # Start the for loop
- #
- # read each file from $DIRS array
- # $f has filename
- for f in "${DIRS[@]}"
- do
- # calculate progress
- PCT=$(( 100*(++i)/n ))
- # update dialog box
- cat <<EOF
- XXX
- $PCT
- Copying file $f
- To $DEST
- XXX
- EOF
- # copy file $f to $DEST
- /bin/cp -r $f ${DEST} &>/dev/null
- /bin/rm -rf /mnt/home/${username}/arch
- done
- )
- }
- #To setup awesome rc.lua for new user
- configure_awesome() {
- cat /mnt/opt/awesome/rc.lua | sed s/arch/${username}/g > /mnt/opt/awesome/rc.out
- cp -v /mnt/opt/awesome/rc.out /mnt/home/${username}/.config/awesome/rc.lua
- }
- #Chmod New User
- chmod_user(){
- arch-chroot /mnt chmod -R 777 /home/${username}
- arch-chroot /mnt chmod -R 777 /home/${username}/.config
- }
- #--------------{ Hostname Setup }----------------#
- configure_hostname(){
- print_title0
- echo ""
- read -p "Please enter a hostname [ex: tuxhatlinux]: " host_name
- echo "$host_name" > /mnt/etc/hostname
- }
- syslinux_setup() {
- arch-chroot /mnt syslinux-install_update -iam
- }
- #--------------{ Copy Syslinux/* to /mnt/boot/syslinux }---------------#
- cp_syslinux(){
- ## Create an array of all files in /opt directory
- DIRS=(/opt/syslinux/.*)
- #Destination directory
- DEST=/mnt/boot/syslinux/
- # Create $DEST if does not exits
- [ ! -d $DEST ] && mkdir -p $DEST
- # Show a progress bar
- # ---------------------------------
- # Redirect dialog commands input using substitution
- #
- DIALOGRC="$DIALOGRC" $DIALOG --backtitle "$DISTNAME$DISTVER" --title "Copy System files" --gauge "Copying files..." 10 75 < <(
- # Get total number of files in array
- n=${#DIRS[*]};
- # set counter - it will increase every-time a file is copied to $DEST
- i=0
- #
- # Start the for loop
- #
- # read each file from $DIRS array
- # $f has filename
- for f in "${DIRS[@]}"
- do
- # calculate progress
- PCT=$(( 100*(++i)/n ))
- # update dialog box
- cat <<EOF
- XXX
- $PCT
- Copying file $f
- To $DEST
- XXX
- EOF
- # copy file $f to $DEST
- /bin/cp -r $f ${DEST} &>/dev/null
- done
- )
- }
- #--------------{ Copy THL Session Menu to profile.d }---------------#
- cp_thlspd(){
- ## Create an array of all files in /opt directory
- DIRS=(/etc/profile.d/tuxhatlinux.sh)
- #Destination directory
- DEST=/mnt/etc/profile.d/
- # Create $DEST if does not exits
- [ ! -d $DEST ] && mkdir -p $DEST
- # Show a progress bar
- # ---------------------------------
- # Redirect dialog commands input using substitution
- #
- DIALOGRC="$DIALOGRC" $DIALOG --backtitle "$DISTNAME$DISTVER" --title "Copy System files" --gauge "Copying files..." 10 75 < <(
- # Get total number of files in array
- n=${#DIRS[*]};
- # set counter - it will increase every-time a file is copied to $DEST
- i=0
- #
- # Start the for loop
- #
- # read each file from $DIRS array
- # $f has filename
- for f in "${DIRS[@]}"
- do
- # calculate progress
- PCT=$(( 100*(++i)/n ))
- # update dialog box
- cat <<EOF
- XXX
- $PCT
- Copying file $f
- To $DEST
- XXX
- EOF
- # copy file $f to $DEST
- /bin/cp -r $f ${DEST} &>/dev/null
- done
- )
- }
- #--------------{ Copy pacman.conf to /mnt/etc/ }---------------#
- cp_pacman(){
- ## Create an array of all files in /opt directory
- DIRS=(/etc/pacman.conf)
- #Destination directory
- DEST=/mnt/etc/
- # Create $DEST if does not exits
- [ ! -d $DEST ] && mkdir -p $DEST
- # Show a progress bar
- # ---------------------------------
- # Redirect dialog commands input using substitution
- #
- DIALOGRC="$DIALOGRC" $DIALOG --backtitle "$DISTNAME$DISTVER" --title "Copy System files" --gauge "Copying files..." 10 75 < <(
- # Get total number of files in array
- n=${#DIRS[*]};
- # set counter - it will increase every-time a file is copied to $DEST
- i=0
- #
- # Start the for loop
- #
- # read each file from $DIRS array
- # $f has filename
- for f in "${DIRS[@]}"
- do
- # calculate progress
- PCT=$(( 100*(++i)/n ))
- # update dialog box
- cat <<EOF
- XXX
- $PCT
- Copying file $f
- To $DEST
- XXX
- EOF
- # copy file $f to $DEST
- /bin/cp -r $f ${DEST} &>/dev/null
- done
- )
- }
- #------------------------{ Network Setup }-------------------------#
- network_interface(){
- print_title2
- echo ""
- ip link show
- print_line
- read -p "${BBlue}dhcp-interface: " dhcpif
- dhcpif=`echo $dhcpif | tr '[:upper:]' '[:lower:]'`
- sudo systemctl enable dhcpcd@${dhcpif}.service
- sudo systemctl start dhcpcd@${dhcpif}.service
- }
Advertisement
Add Comment
Please, Sign In to add comment