Advertisement
ezarchproject

Setup.Postinstall.sh

Dec 25th, 2014
190
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.89 KB | None | 0 0
  1. #!/bin/bash
  2. #-------------------------------------------------------------------------------
  3. #Created by Vincent mailto: Vincent[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 Script is designed to be run independantly and to be deleted after completion
  26. # This file is usually put in to / of the hard disk during installation and then is
  27. # ran after doing arch-chroot /mnt
  28. #
  29. #
  30. # This is to be ran by root.
  31. #
  32. # This file is designed to be removed after installing.
  33. # However other scripts similar to this will be found in /opt/setup
  34. # for various stuff
  35.  
  36. #Global Settings
  37.  
  38.  
  39. DEV=/dev/
  40. TMP=/tmp/tmp.$$
  41. TMP2=/tmp/tmp2.$$
  42.  
  43. EDITOR=vim
  44. ETC=/etc/
  45. DFOUT=/tmp/df.$$
  46.  
  47. #Varibles to Ensure Configured Usually set to Not Configured until
  48. #task is done
  49.  
  50. TASK1='-'
  51. TASK2='-'
  52. TASK3='-'
  53. TASK4='-'
  54. TASK5='-'
  55. TASK6='-'
  56. TASK7='-'
  57.  
  58. ZONEINFOTXT='/opt/setup/txt/zone.txt'
  59. ZONEINFODIR='/usr/share/zoneinfo/'
  60. LOCALTIME='/etc/localtime'
  61. LOCALEGEN="/etc/locale.gen"
  62. BOOTLOADER=" "
  63. SYSLINUXCFG=/boot/syslinux/syslinux.cfg
  64.  
  65.  
  66. #User Stuff
  67.  
  68.  
  69. DEFHOME=/home
  70. SKEL=/etc/skel
  71. PASSWD=/etc/passwd
  72. HOMEDIR=NULL
  73.  
  74. #Set Colors using echo -e ${COLOR} functions
  75. # Bash Colors are found here
  76. # http://misc.flogisoft.com/bash/tip_colors_and_formatting
  77. #
  78. # Color Idea came from Tuxhat installer but actual code below
  79. # came from the website above and implented in to tuxhat-installer
  80. # when correcting mistakes.
  81.  
  82.  
  83. if [[ `id -u ` -ne 0 ]] ; then
  84. echo "Need to be root"
  85. exit 1
  86. fi
  87.  
  88.  
  89. Bold=$(tput bold)
  90. Underline=$(tput sgr 0 1)
  91. Reset=$(tput sgr0)
  92. # Regular Colors
  93. Red=$(tput setaf 1)
  94. Green=$(tput setaf 2)
  95. Yellow=$(tput setaf 3)
  96. Blue=$(tput setaf 4)
  97. Purple=$(tput setaf 5)
  98. Cyan=$(tput setaf 6)
  99. White=$(tput setaf 7)
  100.  
  101.  
  102.  
  103.  
  104.  
  105. #The config users.
  106.  
  107. # ---------------------- To Confirm ------------------------------
  108. print_confirmadd() {
  109. echo
  110. echo -en "${Bold} Is this OK? (Y/N): ${Reset}"
  111.  
  112. }
  113. #--------------------- Add user Script some ideas taken from FreeBSD ---------
  114. addnewuser()
  115. {
  116. print_title "*** Adding new users to the new system ***"
  117. echo
  118. echo "Skel Files are automatically created with the home directory"
  119. echo "This can selected or re-ran for multiple users after it returns"
  120. echo "to main menu"
  121. echo
  122. read -p "Username: " username
  123. echo $username
  124. HOMEDIR=$DEFHOME/$username #Idea from Scripting on Novell Netware
  125. read -p "Full name (Press Enter to leave blank): " fname
  126.  
  127.  
  128.  
  129.  
  130. echo " User Name: $username"
  131. echo " Full name: $fname"
  132. echo " Home Directory $HOMEDIR"
  133.  
  134. while :
  135. do
  136. print_confirmadd
  137. read ConfirmYN
  138. case $ConfirmYN in
  139. [Yy][Ee][Ss]|[Yy][Ee]|[Yy])
  140. #adduser
  141. echo "User is added"
  142.  
  143. if [ "$fname" = "" ]
  144. then
  145. echo "useradd -m -d $HOMEDIR $username"
  146. useradd -m -d $HOMEDIR $username
  147. else
  148. echo useradd -m -c "$fname" -d $HOMEDIR $username
  149. useradd -m -c "$fname" -d $HOMEDIR $username
  150.  
  151.  
  152. #echo "Chfn ${username}"
  153. echo "Setting Password for ${username}"
  154. passwd ${username}
  155. while [[ $? -ne 0 ]]
  156. do
  157. passwd ${username}
  158. done
  159. fi
  160. return 1
  161.  
  162. ;;
  163. [Nn][Oo]|[Nn])
  164. return 1 # Returns to the Menu
  165.  
  166. ;;
  167. *)
  168. echo "You must select Y/N"
  169. ;;
  170. esac
  171. done
  172.  
  173.  
  174. }
  175.  
  176. printdisks() {
  177.  
  178. print_line
  179.  
  180. df / | sed '1d' > $TMP
  181. awk '{printf "Root Disk mount Point :%-5s \t Disk Device %5s\n", $6, $1}' $TMP
  182. print_line
  183. echo "Checking for boot partition if returns with nothing you can install to root"
  184. print_line
  185. mount | column -t | grep /boot > $TMP2
  186. awk '{printf "Boot Partition Mount %-5s \t Device: %-5s \n", $3, $1}' $TMP2
  187. print_line
  188. }
  189.  
  190.  
  191. install_bootloader() {
  192.  
  193. ROOTDSK=`df / | sed '1d' | awk '{print $1}'`
  194. print_title "**** Install Bootloader ****"
  195. echo
  196. printdisks
  197. echo
  198. echo "Root Disk appears to be $ROOTDSK"
  199.  
  200. echo
  201. echo 1. Syslinux
  202. echo 2. Grub
  203. echo 3. Change Root Disk
  204.  
  205. echo
  206. print_askopt
  207. read bootopt
  208. case $bootopt in
  209. 1)
  210. echo "Syslinux Seleted"
  211. BOOTLOADER=Sys linux
  212. echo "pacman -S syslinux"
  213. pacman -S syslinux
  214. echo "syslinux-install_update -iam"
  215. syslinux-install_update -iam
  216. echo "cp $SYSLINUXCFG $SYSLINUXCFG.orig"
  217. cp $SYSLINUXCFG $SYSLINUXCFG.orig
  218. echo "Edit sys linux to match the root disk"
  219. echo "of /dev/sda3 to the one on this computer"
  220. sleep 4
  221. vi $SYSLINUXCFG
  222.  
  223. ;;
  224.  
  225. 2)
  226. echo "Grub Selected"
  227.  
  228. read -p "What partition to install it to (Without /dev/)? " partition
  229.  
  230. echo "pacman -S grub"
  231. pacman -S grub
  232.  
  233. echo "grub-install --target=i386-pc --recheck /dev/$partition"
  234. grub-install --target=i386-pc --recheck /dev/$partition
  235. echo "grub-mkconfig -o /boot/grub/grub.cfg"
  236. grub-mkconfig -o /boot/grub/grub.cfg
  237.  
  238. ;;
  239. 3)
  240. echo
  241. echo -en "${Bold}What do you want as root disk${Reset}:"
  242. read $ROOTDSK
  243.  
  244.  
  245. esac
  246.  
  247. if [ "$BOOTLOADER" != " " ]
  248. then
  249. echo "continue"
  250. echo "Boot loader: $BOOTLOADER"
  251. else
  252. echo "Select a boot loader"
  253. fi
  254. }
  255.  
  256.  
  257.  
  258. ### This Section is from GlobalFunc so it does not rely on seperate files
  259. ### for the 2nd part of the installer.
  260. ###
  261. ########################################################################
  262. print_askopt() {
  263. echo
  264. echo -en "${Bold}Which Option do you require ${Reset}: "
  265.  
  266. }
  267.  
  268. print_title() { #{{{
  269. clear
  270. print_line
  271. echo -e "# $Red Arch Linux Installer ${Bold}$1${Reset} "
  272. print_line
  273. echo ""
  274. } #}}}
  275.  
  276. print_title_nocls() { #{{{
  277. echo -e "# ${Bold}$1${Reset} "
  278. print_line
  279. echo ""
  280. } #}}}
  281.  
  282.  
  283.  
  284. pause_function() { #{{{
  285. print_line
  286. if [[ $AUTOMATIC_MODE -eq 0 ]]; then
  287. read -e -sn 1 -p "Press enter to continue..."
  288. fi
  289. }
  290.  
  291. print_line() { #{{{
  292. printf "%$(tput cols)s\n"|tr ' ' '-'
  293. } #}}}
  294.  
  295. print_dbline() { #{{{
  296. printf "%$(tput cols)s\n"|tr ' ' '='
  297. } #}}}
  298.  
  299. print_warning() { #{{{
  300. T_COLS=`tput cols`
  301. echo -e "${Bold}${Yellow}$1${Reset}\n" | fold -sw $(( $T_COLS - 1 ))
  302. } #}}}
  303.  
  304. invalid_option() { #{{{
  305. print_line
  306. echo "Invalid option. Try another one."
  307. pause_function
  308. } #}}}
  309.  
  310. contains_element() { #{{{
  311. #check if an element exist in a string
  312. for e in "${@:2}"; do [[ $e == $1 ]] && break; done;
  313. } #}}}
  314.  
  315.  
  316. dfspace() { #{{{{
  317. echo "******************* Disk Spaces *************************"
  318. df -Th -t ext4 -t ext3 -t ext2 -t vfat -t reiserfs |sed '1d' > $DFOUT
  319. printf "%-10s \t %-10s \t %-5s \t %-5s \t %-5s\n" Device FS-Type Total Avail 'Mount Dir'
  320. print_dbline
  321. awk '{printf "%-10s \t %-10s \t %-5s \t %-5s \t %-5s\n", $1, $2, $3, $5, $7 }' $DFOUT
  322. print_line
  323. rm $DFOUT
  324.  
  325.  
  326. # This script was taken from AUI installer as I always wanted a decent script that
  327. # does this
  328.  
  329. settimezone() { #{{{
  330. # local zone=(`timedatectl list-timezones | sed 's/\/.*$//' | uniq`);
  331. local zone=(`cat $ZONEINFOTXT | sed 's/\/.*$//' | uniq`);
  332. PS3="$prompt1"
  333. echo "Select zone:"
  334. select ZONE in "${zone[@]}"; do
  335. if contains_element "$ZONE" "${zone[@]}"; then
  336. #local subzone=(`ls $ZONEINFO | grep ${ZONE} | sed 's/^.*\///'`)
  337. local subzone=(`cat $ZONEINFOTXT | grep ${ZONE} | sed 's/^.*\///'`)
  338. PS3="$What Timezone: "
  339. echo "Select subzone:"
  340. select SUBZONE in "${subzone[@]}"; do
  341. if contains_element "$SUBZONE" "${subzone[@]}"; then
  342. echo " ln -sf $ZONEINFODIR/$ZONE/$SUBZONE $LOCALTIME"
  343. ln -sf $ZONEINFODIR/$ZONE/$SUBZONE $LOCALTIME
  344. break
  345. else
  346. invalid_option
  347. fi
  348. done
  349. break
  350. else
  351. invalid_option
  352. fi
  353. done
  354. } #}}}
  355.  
  356.  
  357.  
  358.  
  359. } #}}}
  360.  
  361. ##########################################################################
  362.  
  363. ########################## Main Part of the Installer ##################
  364. PostMenu() {
  365. print_title " *** Post Install *** "
  366. dfspace
  367. echo
  368. echo -e "1. Set Hostname [$TASK1]"
  369. echo "2. Set up Zone Info [$TASK2]"
  370. echo "3. Configure the Locales [$TASK3]"
  371. echo "4. Run mkinitcpio [Make Ramdisk] [$TASK4]"
  372. echo "5. Root Password [$TASK5]"
  373. echo "6. Add users to System [$TASK6]"
  374. echo "7. Install a Boot manager [$TASK7]"
  375. echo "8. Anything Else (Not Implented)"
  376. print_line
  377. echo "Q. Quit"
  378. print_askopt
  379. read OPT
  380.  
  381. case $OPT in
  382.  
  383. 1)
  384. echo "1"
  385. echo -ne "${Bold}${Green}Type in a hostname for this pc: ${Reset}"
  386. read hostname
  387. echo "echo $hostname > /etc/hostname"
  388. echo "$hostname" > /etc/hostname
  389.  
  390. TASK1="${Green}X${Reset}"
  391. ;;
  392.  
  393. 2)
  394.  
  395. settimezone
  396. TASK2="${Green}X${Reset}"
  397. ;;
  398.  
  399. 3)
  400. echo "3"
  401. vi $LOCALEGEN
  402. echo -n "Have you edited it for your need? "
  403. read YN
  404. case $YN in
  405. Y|Yes|y|yes)
  406. locale-gen
  407. TASK3="${Green}X${Reset}"
  408. ;;
  409. N|No|n|no)
  410. echo "re-edit"
  411. TASK3="${Red}F${Reset}"
  412.  
  413. ;;
  414. esac
  415. ;;
  416.  
  417. 4)
  418. echo "4"
  419. mkinitcpio -p linux
  420. TASK4="${Green}X${Reset}"
  421. ;;
  422.  
  423. 5)
  424. echo "5"
  425. echo "Setting passwd for root"
  426. passwd
  427. while [[ $? -ne 0 ]]
  428. do
  429. passwd
  430. done
  431.  
  432. TASK5="${Green}X${Reset}"
  433. ;;
  434.  
  435. 6)
  436. echo "6"
  437. addnewuser
  438. TASK6="${Green}X${Reset}"
  439. ;;
  440.  
  441. 7)
  442. echo "7"
  443. install_bootloader
  444. TASK7="${Green}X${Reset}"
  445. ;;
  446.  
  447. 8)
  448. echo "8"
  449. TASK8="${Green}X${Reset}"
  450. ;;
  451.  
  452. Q|q)
  453. echo "Exiting............."
  454. mv /Setup /root/setup.finished
  455. chmod -x /root/setup.finished
  456. exit 0
  457. ;;
  458. esac
  459. pause_function
  460. PostMenu
  461. }
  462.  
  463.  
  464.  
  465.  
  466. PostMenu
  467.  
  468.  
  469. rm /tmp/tmp.*
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement