ezarchproject

EZ-Arch-2nd-Setup-after-live-fs-copy.sh

Dec 28th, 2014
196
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 14.58 KB | None | 0 0
  1. #!/bin/bash
  2. #-------------------------------------------------------------------------------
  3. #Created by Vincent mailto: ezarchproject[at]gmail[dot]com
  4. #inspired by script that was created by user helmuthdu
  5. #mailto: helmuthdu[at]gmail[dot]com
  6. #Contribution: flexiondotorg
  7. #-------------------------------------------------------------------------------
  8. #This program is free software: you can redistribute it and/or modify
  9. #it under the terms of the GNU General Public License as published by
  10. #the Free Software Foundation, either version 3 of the License, or
  11. #(at your option) any later version.
  12. #
  13. #This program is distributed in the hope that it will be useful,
  14. #but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. #MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. #GNU General Public License for more details.
  17. #
  18. #You should have received a copy of the GNU General Public License
  19. #along with this program. If not, see <http://www.gnu.org/licenses/>.
  20. #-------------------------------------------------------------------------------
  21. # Run this script after your first boot with archlinux (as root)
  22. #--------------------------------------------------------------------------------
  23. # Explaination of the Script:
  24. #
  25. # This is the Main Script that runs the menu system. This is designed
  26. # for live Systems to install an Operating System to the hard disk.
  27. #
  28. # This is to be ran by root.
  29. #
  30. # This file is designed to be removed after installing.
  31. # However other scripts similar to this will be found in /opt/setup
  32. # for various stuff
  33. #
  34. #
  35. # This file is used by installers that do not require the internet
  36. # to install the live cd image to their hard disk and requires configuration
  37. #
  38. #
  39. #
  40.  
  41. EDITOR=nano
  42.  
  43. PROGDIR=/opt/setup
  44.  
  45.  
  46. #Global Settings
  47.  
  48.  
  49. ZONEINFOTXT='/opt/setup/txt/zone.txt'
  50. ZONEINFODIR='/usr/share/zoneinfo/'
  51. LOCALTIME='/etc/localtime'
  52. LOCALEGEN="/etc/locale.gen"
  53.  
  54.  
  55. # Boot Loader Stuff
  56.  
  57. BOOTLOADER=" "
  58.  
  59. SLFILES=/opt/setup/syslinux # Contains Syslinux related files
  60. SLTXT='/opt/setup/txt/syslinux.txt' # Contains filename list of Syslinux config files on in that directory
  61. SLCFGFILE=/boot/syslinux/syslinux.cfg # Default config file
  62. CVSPLASH=/opt/setup/syslinux/splash.png #Current Version Splash
  63.  
  64. # Xorg Defaults to install
  65.  
  66. XORGDEFAULTS='xorg xorg-xinit xorg-server xorg-xclock xorg-twm xterm openmotif terminus-font geany tmux feh'
  67.  
  68. #User Stuff
  69.  
  70.  
  71. DEFHOME=/home
  72. SKEL=/etc/skel
  73. PASSWD=/etc/passwd
  74. HOMEDIR=NULL
  75.  
  76. ROOTSHELL=/bin/bash
  77.  
  78. # Other Environment
  79.  
  80. DEV=/dev/
  81. TMP=/tmp/tmp.$$
  82. TMP2=/tmp/tmp2.$$
  83.  
  84.  
  85. ETC=/etc/
  86. DFOUT=/tmp/df.$$
  87.  
  88.  
  89. #TASKs
  90.  
  91. TASK0='-'
  92. TASK1='-'
  93. TASK2='-'
  94. TASK3='-'
  95. TASK4='-'
  96. TASK5='-'
  97. TASK6='-'
  98. TASK7='-'
  99. TASK8='-'
  100.  
  101. #Set Colors using echo -e ${COLOR} functions
  102. # Bash Colors are found here
  103. # http://misc.flogisoft.com/bash/tip_colors_and_formatting
  104. #
  105. # Color Idea came from Tuxhat installer but actual code below
  106. # came from the website above and implented in to tuxhat-installer
  107. # when correcting mistakes.
  108.  
  109.  
  110. if [[ `id -u ` -ne 0 ]] ; then
  111. echo "Need to be root"
  112. exit 1
  113. fi
  114.  
  115.  
  116. Bold=$(tput bold)
  117. Underline=$(tput sgr 0 1)
  118. Reset=$(tput sgr0)
  119. # Regular Colors
  120. Red=$(tput setaf 1)
  121. Green=$(tput setaf 2)
  122. Yellow=$(tput setaf 3)
  123. Blue=$(tput setaf 4)
  124. Purple=$(tput setaf 5)
  125. Cyan=$(tput setaf 6)
  126. White=$(tput setaf 7)
  127.  
  128.  
  129.  
  130.  
  131. ### This Section is from GlobalFunc so it does not rely on seperate files
  132. ### for the 2nd part of the installer.
  133. ###
  134. ########################################################################
  135. print_askopt() {
  136. echo
  137. echo -en "${Bold}Which Option do you require ${Reset}: "
  138.  
  139. }
  140.  
  141. print_title() { #{{{
  142. clear
  143. print_line
  144. echo -e "# $Red EZ-Arch Linux Installer ${Bold}$1${Reset} "
  145. print_line
  146. echo ""
  147. } #}}}
  148.  
  149. print_title_nocls() { #{{{
  150. echo -e "# ${Bold}$1${Reset} "
  151. print_line
  152. echo ""
  153. } #}}}
  154.  
  155.  
  156.  
  157. pause_function() { #{{{
  158. print_line
  159. if [[ $AUTOMATIC_MODE -eq 0 ]]; then
  160. read -e -sn 1 -p "Press enter to continue..."
  161. fi
  162. }
  163.  
  164. print_line() { #{{{
  165. printf "%$(tput cols)s\n"|tr ' ' '-'
  166. } #}}}
  167.  
  168. print_dbline() { #{{{
  169. printf "%$(tput cols)s\n"|tr ' ' '='
  170. } #}}}
  171.  
  172. print_confirmadd() {
  173. echo
  174. echo -en "${Bold} Is this OK? (Y/N): ${Reset}"
  175.  
  176. }
  177.  
  178. print_warning() { #{{{
  179. T_COLS=`tput cols`
  180. echo -e "${Bold}${Yellow}$1${Reset}\n" | fold -sw $(( $T_COLS - 1 ))
  181. } #}}}
  182.  
  183. invalid_option() { #{{{
  184. print_line
  185. echo "Invalid option. Try another one."
  186. pause_function
  187. } #}}}
  188.  
  189. contains_element() { #{{{
  190. #check if an element exist in a string
  191. for e in "${@:2}"; do [[ $e == $1 ]] && break; done;
  192. } #}}}
  193.  
  194.  
  195. dfspace() { #{{{{
  196. echo "******************* Disk Spaces *************************"
  197. df -Th -t ext4 -t ext3 -t ext2 -t vfat -t reiserfs |sed '1d' > $DFOUT
  198. printf "%-10s \t %-10s \t %-5s \t %-5s \t %-5s\n" Device FS-Type Total Avail 'Mount Dir'
  199. print_dbline
  200. awk '{printf "%-10s \t %-10s \t %-5s \t %-5s \t %-5s\n", $1, $2, $3, $5, $7 }' $DFOUT
  201. print_line
  202. rm $DFOUT
  203.  
  204. }
  205.  
  206.  
  207. # Functions
  208.  
  209. RemoveLiveCDStuff ()
  210.  
  211. {
  212. echo -e "${BYellow}This is a required Step for setting up the system${Reset}"
  213. echo
  214. echo "As you chose to install EZ-Arch with out using the internet"
  215. echo "The installer would of copied the live image to the hard disk"
  216. echo "The elements of the live image needs to be removed as it is useless"
  217. echo "to a running system"
  218. echo
  219. echo "This part is automatic and will get through this with minimal"
  220. echo "promptings."
  221. echo
  222. echo "This idea is probley best done with very big distros but installing"
  223. echo "via the internet should be still possible"
  224. echo
  225. echo "If you have a network do you use DHCP or manual"
  226. echo
  227.  
  228.  
  229. # while :
  230. # do
  231. echo " 1. DHCP 2. Manual 3. None "
  232. echo
  233. echo "Q to return to main manu"
  234. read NETOPTS
  235.  
  236. case $NETOPTS in
  237.  
  238. 1)
  239. echo "DHCP Is chosen it can be left there"
  240. NETWORK=DHCP
  241. ;;
  242. 2)
  243. echo "No DHCP is used so it can be removed"
  244. NETWORK=Manual
  245. rm -v /etc/udev/rules.d/81-dhcpcd.rules
  246. ;;
  247. 3)
  248. echo "No Network"
  249. NETWORK=none
  250. rm -v /etc/udev/rules.d/81-dhcpcd.rules
  251.  
  252. ;;
  253. *)
  254. invalid_option
  255. return 1
  256. ;;
  257. esac
  258. # done
  259.  
  260.  
  261. # Rest of this should be automatic
  262.  
  263. #Disable & remove the services created by ArchISO
  264.  
  265. echo "Setting Journal information"
  266.  
  267. sed -i 's/Storage=volatile/#Storage=auto/' /etc/systemd/journald.conf
  268.  
  269.  
  270. echo "Disabling pacman-init and choose-mirror services"
  271.  
  272. systemctl disable pacman-init.service choose-mirror.service
  273.  
  274. echo "Deleting the live cd services"
  275.  
  276. rm -vr /etc/systemd/system/{choose-mirror.service,pacman-init.service,etc-pacman.d-gnupg.mount,getty@tty1.service.d}
  277.  
  278. echo "Removing Spcecial Live CD Scripts"
  279.  
  280. #rm -v /etc/systemd/system/getty@tty1.service.d/autologin.conf
  281. rm -v /root/.automated_script.sh
  282. rm -v /root/.zlogin
  283. rm -v /etc/sudoers.d/g_wheel
  284. rm -v /etc/mkinitcpio-archiso.conf
  285. rm -rv /etc/initcpio
  286.  
  287. echo " Removing Arch user from the system"
  288.  
  289. userdel -r arch
  290.  
  291. TASK0="${Green}X${Reset}"
  292.  
  293.  
  294. }
  295.  
  296.  
  297. #--------------------- Add user Script some ideas taken from FreeBSD ---------
  298. addnewuser()
  299. {
  300. print_title "*** Adding new users to the new system ***"
  301. echo
  302. echo "Skel Files are automatically created with the home directory"
  303. echo "This can selected or re-ran for multiple users after it returns"
  304. echo "to main menu"
  305. echo
  306. read -p "Username: " username
  307. echo $username
  308. HOMEDIR=$DEFHOME/$username #Idea from Scripting on Novell Netware
  309. read -p "Full name (Press Enter to leave blank): " fname
  310.  
  311.  
  312.  
  313.  
  314. echo " User Name: $username"
  315. echo " Full name: $fname"
  316. echo " Home Directory $HOMEDIR"
  317.  
  318. while :
  319. do
  320. print_confirmadd
  321. read ConfirmYN
  322. case $ConfirmYN in
  323. [Yy][Ee][Ss]|[Yy][Ee]|[Yy])
  324. #adduser
  325. echo "User is added"
  326.  
  327. if [ "$fname" = "" ]
  328. then
  329. echo "useradd -m -d $HOMEDIR $username"
  330. useradd -m -d $HOMEDIR $username
  331. else
  332. echo useradd -m -c "$fname" -d $HOMEDIR $username
  333. useradd -m -c "$fname" -d $HOMEDIR $username
  334.  
  335.  
  336. #echo "Chfn ${username}"
  337. echo "Setting Password for ${username}"
  338. passwd ${username}
  339. while [[ $? -ne 0 ]]
  340. do
  341. passwd ${username}
  342. done
  343. fi
  344. return 1
  345.  
  346. ;;
  347. [Nn][Oo]|[Nn])
  348. return 1 # Returns to the Menu
  349.  
  350. ;;
  351. *)
  352. echo "You must select Y/N"
  353. ;;
  354. esac
  355. done
  356.  
  357.  
  358. }
  359.  
  360. printdisks() {
  361.  
  362. print_line
  363.  
  364. df / | sed '1d' > $TMP
  365. awk '{printf "Root Disk mount Point :%-5s \t Disk Device %5s\n", $6, $1}' $TMP
  366. print_line
  367. echo "Checking for boot partition if returns with nothing you can install to root"
  368. print_line
  369. mount | column -t | grep /boot > $TMP2
  370. awk '{printf "Boot Partition Mount %-5s \t Device: %-5s \n", $3, $1}' $TMP2
  371. print_line
  372. }
  373.  
  374.  
  375. install_bootloader() {
  376.  
  377.  
  378.  
  379. ROOTDSK=`df / | sed '1d' | awk '{print $1}'`
  380. print_title "**** Install Bootloader ****"
  381. echo
  382. printdisks
  383. echo
  384. echo "Root Disk appears to be $ROOTDSK"
  385.  
  386. echo "Running syslinux-install_update -iam"
  387. syslinux-install_update -iam
  388. echo "cp $SLCFGFILE $SLCFGFILE.orig"
  389. cp -v $SLCFGFILE $SLCFGFILE.orig
  390. cp -v $CVSPLASH /boot/syslinux
  391. sleep 1
  392. selectsyslinuxcfg
  393.  
  394.  
  395. }
  396.  
  397. # This script was taken from AUI installer as I always wanted a decent script that
  398. # does this
  399.  
  400. settimezone() { #{{{
  401.  
  402. local zone=(`cat $ZONEINFOTXT | sed 's/\/.*$//' | uniq`);
  403. PS3="$prompt1"
  404. echo "Select zone:"
  405. select ZONE in "${zone[@]}"; do
  406. if contains_element "$ZONE" "${zone[@]}"; then
  407. local subzone=(`cat $ZONEINFOTXT | grep ${ZONE} | sed 's/^.*\///'`)
  408. PS3="$What Timezone: "
  409. echo "Select subzone:"
  410. select SUBZONE in "${subzone[@]}"; do
  411. if contains_element "$SUBZONE" "${subzone[@]}"; then
  412. ln -sf $ZONEINFODIR/$ZONE/$SUBZONE $LOCALTIME
  413. break
  414. else
  415. invalid_option
  416. fi
  417. done
  418. break
  419. else
  420. invalid_option
  421. fi
  422. done
  423. } #}}}
  424.  
  425.  
  426.  
  427.  
  428. selectsyslinuxcfg(){
  429.  
  430. PS3="Select Config file relevent root disk: "
  431. #Already declared
  432. #SLFILES=/opt/setup/syslinux
  433. #SLTXT='/opt/setup/txt/syslinux.txt'
  434. #SLCFGFILE=/boot/syslinux/syslinux.cfg
  435.  
  436.  
  437. ROOTDSK=`df / | sed '1d' | awk '{print $1}'`
  438. print_title "Syslinux Configs"
  439. echo
  440. echo " Current root Disk is $ROOTDSK"
  441. print_line
  442. local cfgfiles=(`cat $SLTXT | sed 's/\/.*$//' | uniq`);
  443. echo "Select Syslinux cfg file that is right for your root disk"
  444. echo
  445. select SLCFG in "${cfgfiles[@]}"
  446. do
  447. if contains_element "$SLCFG" "${cfgfiles[@]}"
  448. then
  449. echo "cp -v $SLFILES/$SLCFG $SYSLINUXCFG"
  450. cp -v $SLFILES/$SLCFG $SLCFGFILE
  451. echo
  452. break
  453. else
  454. invalid_option
  455. fi
  456. done
  457.  
  458. }
  459.  
  460.  
  461.  
  462. ######################################## MENU
  463.  
  464. EditConfFiles() {
  465. while :
  466. do
  467. echo
  468. print_title "*** Edit Config Files ***"
  469. echo
  470. echo Default Editor $EDITOR
  471. echo
  472. echo "1. Select Editor"
  473. echo "2. Edit fstab"
  474. echo "3. Edit /etc/hosts"
  475. echo "4. Edit Pacman.conf & Update"
  476. echo "Q. Quit"
  477. echo
  478. print_askopt
  479. read Conf
  480.  
  481. case $Conf in
  482.  
  483. 1)
  484. echo "Available Editors on the system is"
  485. echo "vi or nano"
  486. echo -n "Which Editor: "
  487. read EDITOR
  488. ;;
  489. 2)
  490. $EDITOR /etc/fstab
  491. ;;
  492. 3)
  493. $EDITOR /etc/hosts
  494. ;;
  495. 4) $EDITOR /etc/pacman.conf
  496.  
  497. echo -ne "${Bold}Did you change anything Y/N${Reset}: "
  498. read YN
  499. case $YN in
  500.  
  501. Y|y|Yes|yes|YES)
  502. echo "Refreshing database"
  503. echo
  504. pacman -Sy
  505. ;;
  506. No|N|n|no)
  507. echo "Nothing Changed"
  508. ;;
  509. esac
  510. ;;
  511. q|Q)
  512. return 1
  513. ;;
  514. esac
  515. done
  516. }
  517.  
  518.  
  519.  
  520.  
  521. PostMenu() {
  522. print_title " *** Post Install *** "
  523. dfspace
  524. echo
  525. echo -e "1. Remove LiveCD stuff from system [$TASK0]"
  526. echo -e "2. Set Hostname [$TASK1]"
  527. echo -e "3. Set up Zone Info [$TASK2]"
  528. echo -e "4. Configure the Locales [$TASK3]"
  529. echo -e "5. Run mkinitcpio [Make Ramdisk] [$TASK4]"
  530. echo -e "6. Root Password [$TASK5]"
  531. echo -e "7. Add users to System [$TASK6]"
  532. echo -e "8. Install a Boot manager (Syslinux) [$TASK7]"
  533. #echo -e "9. Install X-Org & Open Motif [$TASK8]"
  534. print_line
  535. echo "Q. Quit"
  536. echo "E. Edit config files"
  537. print_askopt
  538. read OPT
  539.  
  540. case $OPT in
  541.  
  542. 1)
  543. RemoveLiveCDStuff
  544. TASK0="${Green}X${Reset}"
  545. ;;
  546.  
  547. 2)
  548. echo "1"
  549. echo -ne "${Bold}${Green}Type in a hostname for this pc: ${Reset}"
  550. read hostname
  551. echo "echo $hostname > /etc/hostname"
  552. echo "$hostname" > /etc/hostname
  553.  
  554. TASK1="${Green}X${Reset}"
  555. ;;
  556.  
  557. 3)
  558.  
  559. settimezone
  560. TASK2="${Green}X${Reset}"
  561. ;;
  562.  
  563. 4)
  564. echo "3"
  565. nano $LOCALEGEN
  566. echo -n "Have you edited it for your need? "
  567. read YN
  568. case $YN in
  569. Y|Yes|y|yes)
  570. locale-gen
  571. TASK3="${Green}X${Reset}"
  572. ;;
  573. N|No|n|no)
  574. echo "re-edit"
  575. TASK3="${Red}*${Reset}"
  576.  
  577. ;;
  578. esac
  579. ;;
  580.  
  581. 5)
  582. echo "4"
  583. mkinitcpio -p linux
  584. TASK4="${Green}X${Reset}"
  585. ;;
  586.  
  587. 6)
  588. echo "5"
  589. echo "Setting passwd for root"
  590. passwd
  591. while [[ $? -ne 0 ]]
  592. do
  593. passwd
  594. done
  595. chsh -s $ROOTSHELL
  596.  
  597. TASK5="${Green}X${Reset}"
  598. ;;
  599.  
  600. 7)
  601. echo "6"
  602. addnewuser
  603. TASK6="${Green}X${Reset}"
  604. ;;
  605.  
  606. 8)
  607. echo "7"
  608. install_bootloader
  609. TASK7="${Green}X${Reset}"
  610. ;;
  611.  
  612. 9)
  613. echo
  614. echo "Installation of Xorg as the same as on"
  615. echo "the Live CD with Open Motif"
  616. echo
  617. echo "You may install more Window managers manually with"
  618. echo "pacman -S window-manager"
  619. echo
  620. pause_function
  621. echo
  622. echo "Commencing......"
  623. echo
  624. pacman -S $XORGDEFAULTS
  625.  
  626. if [[ "$?" -ne 0 ]]
  627. then
  628. print_warning "Program Failed"
  629. TASK8="${Red}F${Reset}"
  630. else
  631. echo "Installed"
  632. TASK8="${Green}X${Reset}"
  633. fi
  634. ;;
  635.  
  636. Q|q)
  637. echo "Exiting............."
  638. echo "Removing Setup and placing it in /root"
  639. mv /Setup /root/setup.finished
  640. chmod -x /root/setup.finished
  641. exit 0
  642. ;;
  643. E|e)
  644. EditConfFiles
  645. ;;
  646. esac
  647. pause_function
  648. PostMenu
  649. }
  650.  
  651.  
  652.  
  653.  
  654. PostMenu
  655.  
  656. rm /tmp/tmp.*
Add Comment
Please, Sign In to add comment