Saist Arch Install Script

 

Currently, there are several different Arch install scripts to choose from if so desired. Of the ones I've looked into, they mostly seem to work well if you stay focused enough to read and follow all the details as the script runs. Most of these install scripts seem to be "do it all solutions" for nearly any imaginable install scenario. These efforts unavoidably lead to the production of lengthy and likely complex scripts or series of scripts. Based on whats available, it's easy to ascertain that a "do it all" install script cannot also be a small and simple shell script.

Now onto my latest efforts, Saist is a tiny, 26 lines of code, bash script to automate the installation of an Arch Linux base. It's customized for my personal use and is not flexible without editing. Since the script is so small and simple, it would be very easy to edit to suite any install process for x86_64, non efi, standard bios hardware. I'm putting the code up as a template, for anyone who may find it useful. There's two versions of it. One bare bones called saist (Simple Arch Install Script Template). A longer version is called Aist (Arch Install Script Template) that's setup with feedback to let the user know whats up while running, and is in a more traditional scripting style implementing functions.

The saist install scripts are not in the same category, offer the features of, or are comparable to the larger above mentioned installers and scripts. They are however, very simple and therefore easy to read, edit and work with.

I'm also working on a small simple post install script that semi automates the setup of wheel group, installs packages for xorg, graphics drivers, polkit, a DE, sets up xorg, xinit, xserverrc, etc. It's called Pstins (Post Install Script) It puts the user directly into manually editing config files. I spent some time to add comments, etc to make it similar to using the saist script. I may make a longer version of this in the future, and would then offer it for use as well.

Working on these scropts has re-motivated me to bring Makeiso back from the dead (see images). I'm toying with the idea of combining these projects into one. Perhaps Saist and Pstins along with another script or two could finally complete the original goals of Makeiso, but with the added flexibility of various install methods and results.
 












                                                           
                                                                            Downloads and more info: https://github.com/jeffscode/saist



____________________________________________________________________________________________________________________________________
#!/bin/bash
	#............................................... saist script June 2 2017
# set -x
	mount /dev/sda1 /mnt
	mkdir -p /mnt/home
	mount /dev/sda3 /mnt/home
                                                                               #  Create a /home dir and mount file systems
  	swapon /dev/sda2
        yes y |pacman -S reflector
                                                                               #  Swapon for fstab inclusion
	reflector --latest 5 --sort rate --save /etc/pacman.d/mirrorlist
                                                                               #  Setup mirrors with reflector
 	pacstrap /mnt base base-devel wget grub
                                                                               #  Install packages using pacstrap
	genfstab -L /mnt > /mnt/etc/fstab
                                                                               #  Generate /etc/fstab
	arch-chroot /mnt << INchrootOUT
                                       # ===================================== #  ENTER Here Doc for chroot
	ln -sf /usr/share/zoneinfo/America/Los_Angeles /etc/localtime
                                                                               #  Set America/Los_Angeles time zone in /etc/localtime
	hwclock --systohc
                                                                               #  Run hwclock to generate /etc/adjtime
	echo "en_US.UTF-8 UTF-8" >> /etc/locale.gen
	locale-gen
                                                                               #  Set en_US.UTF-8 UTF-8 in and generate /etc/locale.conf 
	echo "LANG=en_US.UTF-8" >> /etc/locale.conf
                                                                               #  Set the language in /etc/locale.conf
	echo "KEYMAP=us" >> /etc/vconsole.conf
                                                                               #  Setup the keyboard layout in /etc/vconsole.conf
	echo "archtest" > /etc/hostname
                                                                               #  Set the hostname in /etc/hostname
	echo "127.0.1.1  archtest.localdomain  archtest" >> /etc/hosts
                                                                               #  Add hostname to /etc/hosts
	systemctl enable dhcpcd  
                                                                               #  Enable dhcp dameon  
	grub-install --target=i386-pc /dev/sda
                                                                               #  Install and config grub
	grub-mkconfig -o /boot/grub/grub.cfg

	useradd -m -g users -G wheel -s /bin/bash jeff
                                                                               #  Create a user asccount
	yes test | passwd root
	yes test | passwd jeff
                                                                               #  Set both passwords to "test"

INchrootOUT
           # ================================================================= #  EXIT Here Doc for chroot

# set +x
	exit

__________________________________________________________________________________________________________________________________








__________________________________________________________________________________________________________________________________
#!/bin/bash
	#............................................. pstins script May 31 2017

	#....................................................................................... Install packages with pacman 
 	pacman -Syu  xorg-server  xorg-xinit  xterm xorg-fonts  xorg-twm virtualbox-guest-utils\
		     virtualbox-guest-modules-arch  linux-headers  polkit  ttf-liberation\
		     leafpad  xfce4  xfce4-goodies  gvfs  sudo

set -x
	cp /etc/X11/xinit/xinitrc /home/jeff/.xinitrc
						       #......................................... Copy xinitrc to ~/
	cp /etc/X11/xinit/xserverrc /home/jeff/.xserverrc
							   #..................................... Copy xserverrc to ~/

	sed -i '/twm/s/^/#/g' /home/jeff/.xinitrc
	sed -i '/xclock/s/^/#/g' /home/jeff/.xinitrc
	sed -i '/xterm/s/^/#/g' /home/jeff/.xinitrc
						    #............................................ Comment out lines in ~/.xinitrc
	sed -i '/exec/s/^/#/g' /home/jeff/.xserverrc
						      #.......................................... Comment out line in ~/.xserverrc
	sed -i '/End/s/^/#/g' /etc/hosts
					  #...................................................... Comment out line in /etc/hosts
	echo 'exec startxfce4 -- vt$XDG_VTNR' >> /home/jeff/.xinitrc
								      #.......................... Append line to ~/.xinitrc
	echo 'exec /usr/bin/Xorg -nolisten tcp "$@" vt$XDG_VTNR' >> /home/jeff/.xserverrc
											  #...... Append line to ~/.xserverrc
	echo '# End of file' >> /etc/hosts
					    #.................................................... Append line to /etc/hosts
	nano /home/jeff/.xinitrc
				 #............................................................... Check ~/.xinitrc
	nano /home/jeff/.xserverrc
				   #............................................................. Check ~/.xserverrc
	nano /etc/hosts
			#........................................................................ Check /etc/hosts
 	sed -i '/%wheel ALL=(ALL) ALL/s/^#//' /etc/sudoers
							    #.................................... Set up wheel for sudo 
	EDITOR=nano visudo
			    #..................................................................... Check suoders file

	chown jeff /home/jeff/.xinitrc
					 #........................................................ Ch owner of ~/.xinitrc to jeff 
  	chown jeff /home/jeff/.xserverrc
					   #...................................................... Ch owner of ~/.xserverrc to jeff
set +x


____________________________________________________________________________________________________________________________________









____________________________________________________________________________________________________________________________________
#!/bin/bash
#----------------------------------------------- Aist Script June 6 2017
# set -x
#
# NOTE: Edit /usr/bin/pacstrap line 339 to add
# "--needed" option to pacman to expedite testing
#
#----------------------------------------------------------------------
## Color Variables NEED MANUALLY EDITED TO SUIT INSTALL.##

# Black '\033[0;30m'
# Blue '\033[0;34m' # Light Blue '\033[1;34m'
# Brown/Orange '\033[0;33m'
# Cyan '\033[0;36m' # Light Cyan '\033[1;36m'
# Dark Gray '\033[1;30m' # Light Gray '\033[0;37m'
# Green '\033[0;32m' # Light Green '\033[1;32m'
# Purple '\033[0;35m' # Light Purple '\033[1;35m'
# Red '\033[0;31m' # Light Red '\033[1;31m'
# White '\033[1;37m' # Yellow '\033[1;33m'
# Cancel Color '\033[0m'


MT='\033[1;37m' # For Main Text # White
CH='\033[1;33m' # For Chroot Text # Yellow
CC='\033[0m' # To Cancel Text Color


#----------------------------------------------------------------------
## Set Up User And Passwords NEED MANUALLY EDITED TO SUIT INSTALL.##

URN=jeff # Username
URP=tess # User Password
RTP=root # Root Password


#----------------------------------------------------------------------
## STORAGE VARIABLES NEED MANUALLY EDITED TO SUIT INSTALL.##

# set the hdd or hdd. uncomment first comment on line to activate #

HDD=sda
# HDD=sdb
# HDD=sdc
# HDD=sdd
# HDD=sde

# set root partition. uncomment line to activate #

ROOTP=/dev/sda1
# ROOTP=/dev/sda2
# ROOTP=/dev/sda3
# ROOTP=/dev/sda4
# ROOTP=/dev/sda5

# set home partition. uncomment line to activate #

# HOMEP=/dev/sda1
# HOMEP=/dev/sda2
HOMEP=/dev/sda3
# HOMEP=/dev/sda4
# HOMEP=/dev/sda5

# set swap partition. uncomment line to activate #

# SWAP=/dev/sda1
SWAP=/dev/sda2
# SWAP=/dev/sda3
# SWAP=/dev/sda4
# SWAP=/dev/sda5

##################################################################################
########## ALL VARIABLES ABOVE NEED MANUAL EDITING TO SUITE INSALL ###############
##################################################################################


echo -e "${MT}#------------------------------------------------------------------#
## Aist ##
### ###
#### Arch Install Script Template ####
##### Read, edit and add to it for your preferences #####
#### Please provide your edits for inclusion at: ####
### http://www.xxxxx.com ###
## Lets keep this kiss, there are existing partitioning tools ##
#------------------------------------------------------------------#${CC}"

echo
echo -e "${CH} Chroot section = yellow font. ${CC}"
echo
echo
echo

#----------------------------------------------------------------------
## asksure is an "ask to proceed" fuction used in all functions ##

asksure() {

echo
echo -n -e "${MT} Proceed (Y/N) ? ${CC}"
while read -r -n 1 -s answer; do
if [[ $answer = [YyNn] ]] ; then
[[ $answer = [Yy] ]] && retval=0 && echo -e " ${CC}Answered ${MT}Yes${CC}, Proceeding ${CC} "
[[ $answer = [Nn] ]] && retval=0 && echo -e " ${CC}Answered ${MT}No${CC}, Exiting Installer ${CC} " && echo && exit
break
fi
done
return $retval
}

#----------------------------------------------------------------------

umounts(){

## unmount just in case ##
umount $HOMEP &> /dev/null
umount $ROOTP &> /dev/null
swapoff $SWAP &> /dev/null
echo "root is mounted on $ROOTP"
echo "home is mounted on $HOMEP"
echo "swap is mounted on $SWAP"
echo "username is $URN"
echo "user password is $URP"
echo "root password is $RTP"
echo
echo -e "${MT} The partitions you set up will be formatted. ${CC}"
echo -e "${MT} All data will be lost. Last chance to stop. ${CC}"
asksure
}

#----------------------------------------------------------------------

formats(){

## SET PARTITIONS TO BE FORMATTED HERE ##
yes | mkfs.ext4 $ROOTP
yes | mkfs.ext4 $HOMEP
}

#----------------------------------------------------------------------

mounts(){

## set mount points and swap ##
echo
mount $ROOTP /mnt
mkdir -p /mnt/home
mount $HOMEP /mnt/home
swapon $SWAP
lsblk | grep $HDD
echo
echo -e "${MT} Partitions shown mounted have been formatted, ready for installation. ${CC}"

asksure
echo
}

#----------------------------------------------------------------------

setrepos(){

## set repos ##
echo
yes y |pacman -Sy --needed reflector > /dev/null
reflector --latest 5 --sort rate --save /etc/pacman.d/mirrorlist
echo
cat /etc/pacman.d/mirrorlist
echo
echo -e "${MT} Updated the local mirrorlist. ${CC}"
echo -e "${MT} These will be integrated into new install. ${CC}"
asksure
echo
}

#----------------------------------------------------------------------

install(){

## install packages ##
echo
echo
echo -e "${MT} Installing the packages. This will take a while. ${CC}"
echo
pacstrap /mnt base grub #base-devel wget

genfstab -L /mnt > /mnt/etc/fstab
echo
echo -e "${MT} Installed packages and set up /etc/fstab. ${CC}"
asksure
echo
}

#----------------------------------------------------------------------
## Chroot ##
chroot-heredoc(){
## INFO TO USER ##
## COMMANDS ##
echo -e "${CH} Chrooting into new filesystem to configure ${CC}"
arch-chroot /mnt << INchrootOUT /bin/bash
echo 'command: arch-chroot /mnt << ICChrootOUT /bin/bash'

echo -e "${CH} Setting Timezone ${CC}"
ln -sf /usr/share/zoneinfo/America/Los_Angeles /etc/localtime
hwclock --systohc
echo 'command: ln -sf /usr/share/zoneinfo/America/Los_Angeles /etc/localtime'
echo 'command: hwclock --systohc'

echo -e "${CH} Setting Locale ${CC}"
echo "en_US.UTF-8 UTF-8" >> /etc/locale.gen
locale-gen
echo 'command: echo en_US.UTF-8 UTF-8" >> /etc/locale.gen'
echo 'command: locale-gen'

echo -e "${CH} Setting Language ${CC}"
echo "LANG=en_US.UTF-8" >> /etc/locale.conf
echo 'command: echo "LANG=en_US.UTF-8" >> /etc/locale.conf'

echo -e "${CH} Setting up Keyboard ${CC}"
echo "KEYMAP=us" >> /etc/vconsole.conf
echo 'command: echo "KEYMAP=us" >> /etc/vconsole.conf'

echo -e "${CH} Setting Hostname ${CC}"
echo "archtest" > /etc/hostname
echo "127.0.1.1 archtest.localdomain archtest" >> /etc/hosts
echo 'command: echo "archtest" > /etc/hostname'
echo 'command: echo "127.0.1.1 archtest.localdomain archtest" >> /etc/hosts'

echo -e "${CH} Setting up Network ${CC}"
systemctl enable dhcpcd
echo 'command: systemctl enable dhcpcd'


echo -e "${CH} Setting up Bootloader ${CC}"
grub-install --target=i386-pc /dev/sda
grub-mkconfig -o /boot/grub/grub.cfg

echo -e "${CH} Setting up User ${CC}"
useradd -m -g users -G wheel -s /bin/bash $URN
echo 'command: useradd -m -g users -G wheel -s /bin/bash $URN'
echo -e "${CH} Seting Passwords ${CC}"
yes $RTP | passwd root
yes $URP | passwd $URN

echo -e "${CH} Chrooting out of new filesystem. ${CC}"
echo

INchrootOUT

}

#----------------------------------------------------------------------
## Just A Message ##
completedchr(){

echo -e "${MT} Completed chroot configuration. ${CC}"
asksure
echo
}

#----------------------------------------------------------------------
## Unmount Partitions ##
unmounts(){

umount $HOMEP
umount $ROOTP
swapoff $SWAP
echo
}

#----------------------------------------------------------------------
## Run Functions, Optionally Log Them ##

umounts # 2> umount.log
formats # 2> format.log
mounts # 2> mounts.log
setrepos # 2> setrepos.log
install # 2> install.log
chroot-heredoc # 2> chrdoc.log
completedchr # 2> completedchr
unmounts # 2> tee unmounts.log

#----------------------------------------------------------------------
## Show Partitions Unmounted And Message ##

lsblk | grep $HDD

echo
echo -e "${MT} Installation completed. ${CC}"
echo -e "${MT} Above to verify partitions unmounted. ${CC}"
echo

#----------------------------------------------------------------------

# set +x
exit




____________________________________________________________________________________________________________________________________






Comments