unixwz0r

UNIXwz0r - setup-tuxhat.conf (re-written for dialog)

Jan 23rd, 2015
369
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 13.87 KB | None | 0 0
  1. #!/bin/bash
  2. #----------------------------------------------------------------------------------------
  3. # Script Created by Gary Perreault - Tux Hat Linux Project ([email protected])
  4. # Distro Sourceforge - https://sourceforge.net/projects/tuxhatlinux/
  5. # Distro Dailymotion - http://www.dailymotion.com/tuxhatlinux
  6. #----------------------------------------------------------------------------------------
  7. #This program is free software: you can redistribute it and/or modify
  8. #it under the terms of the GNU General Public License as published by
  9. #the Free Software Foundation, either version 3 of the License, or
  10. #(at your option) any later version.
  11. #
  12. #This program is distributed in the hope that it will be useful,
  13. #but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. #MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15. #GNU General Public License for more details.
  16. #
  17. #You should have received a copy of the GNU General Public License
  18. #along with this program.  If not, see <http://www.gnu.org/licenses/>.
  19. #----------------------------------------------------------------------------------------
  20. # Run this script after your first boot with archlinux (as root)
  21. #----------------------------------------------------------------------------------------
  22. # Explaination of the Script:
  23. #
  24. # Setup-Tuxhat using Dialog
  25. #
  26. ##########################################################################################
  27.  
  28. #----------------{ Colours for the text part }----------------#
  29. Bold=$(tput bold)
  30. Underline=$(tput sgr 0 1)
  31. Reset=$(tput sgr0)
  32. # Regular Colors
  33. Red=$(tput setaf 1)
  34. Green=$(tput setaf 2)
  35. Yellow=$(tput setaf 3)
  36. Blue=$(tput setaf 4)
  37. Purple=$(tput setaf 5)
  38. Cyan=$(tput setaf 6)
  39. White=$(tput setaf 7)
  40. # Bold
  41. BRed=${Bold}$(tput setaf 1)
  42. BGreen=${Bold}$(tput setaf 2)
  43. BYellow=${Bold}$(tput setaf 3)
  44. BBlue=${Bold}$(tput setaf 4)
  45. BPurple=${Bold}$(tput setaf 5)
  46. BCyan=${Bold}$(tput setaf 6)
  47. BWhite=${Bold}$(tput setaf 7)
  48.  
  49. #Menu Specific Stuff
  50. DIALOG=${DIALOG=dialog}
  51. FUNCTION='Main Menu Setup'
  52. DIALOGRC=/opt/setup/tuxhat
  53. DIALOGRC=${DIALOGRC}
  54.  
  55.  
  56. #--------------------{ Global Settings }-------------------------#
  57. DISTNAME='Tux Hat Linux '
  58. DISTVER='v3.4'
  59. DEV=/dev/
  60. DISK=NULL
  61. MNT=/mnt  #Default mount point for filesystem's root upon preparing
  62. EDITOR=nano
  63. PS3="$prompt1"
  64. TMP=/tmp/tmp.$$
  65. TMP2=/tmp/tmp2.$$
  66. SELECTEDDSK="No Disk Selected: $DEV$DISK"
  67. DFOUT=/tmp/dfout.$$
  68. ROOTDSK=`df / | sed '1d' | awk '{print $1}'`
  69. BOOTLOADERINSTALL="pacstrap /mnt syslinux"
  70. HOSTS="nano /mnt/etc/hosts"
  71. EDITLOCALE="nano /mnt/etc/locale.gen"
  72. EDITOR=nano
  73. #-----------{ Functions to be used as a helper program }-------------#
  74. CONFIGFILE=/opt/setup/setup-tuxhat.conf
  75. # PROMPT {{{
  76. prompt1="Enter your option: "
  77.  
  78. print_askopt() {
  79.     echo
  80.     echo -en "${Bold}${Blue}Which Option do you require: "
  81.    
  82. }
  83.  
  84. print_askopt2() {
  85.     echo
  86.     echo -en "${Bold}${Blue}Which setup script do you require: "
  87. }
  88.  
  89. print_title0() { #{{{
  90.     clear
  91.     echo -e "${BBlue}**** Setup Hostname ****"
  92.   } #}}}
  93.  
  94. print_title1() { #{{{
  95.     clear
  96.     echo -e "${BBlue}**** Setup New User ****"
  97.   } #}}}  
  98.  
  99. print_title2() { #{{{
  100.     clear
  101.     echo -e "${BBlue}**** Setup Network *****"
  102. }  #}}}
  103.  
  104. pause_function() { #{{{
  105.     #print_line
  106.     printf "%$(tput cols)s\n"|tr ' ' '-'
  107.     echo
  108.     if [[ $AUTOMATIC_MODE -eq 0 ]]; then
  109.       read -e -sn 1 -p "Press enter to continue..."
  110.     fi
  111. }
  112.  
  113. print_line() { #{{{
  114. printf "%$(tput cols)s\n"|tr ' ' '-'
  115. } #}}}
  116.  
  117. print_dbline() { #{{{
  118. printf "%$(tput cols)s\n"|tr ' ' '='
  119. } #}}}
  120.  
  121. #-------------------{ Disk partition and stuff }---------------------#
  122. SelectDisk() { #{{{
  123.  
  124.             echo "${BBlue}Available Disks on Computer"
  125.             echo
  126.             lsblk | grep disk > $TMP
  127.             printf "%-10s \t %-10s\n" 'Available Disk' 'Total Size'
  128.             print_dbline
  129.             awk '{printf "%-17s %-10s\n", $1, $4}' $TMP
  130.             print_line
  131.             echo
  132.             echo "${BBlue}sda usually means whole disk so no partition"
  133.             echo  "number is required"
  134.             echo
  135.             echo "${BBlue}There is no need to put /dev on front as it is"
  136.             echo  "a default directory."
  137.             echo
  138.             echo -n "${BBlue}What Disk do you want to use: "
  139.             read DISK
  140.             echo "${BBlue}You selected $DEV$DISK"
  141.             echo ""
  142.             rm $TMP
  143.             sleep
  144.  
  145. } #}}}}
  146.  
  147. PartitionDisks() { #{{{
  148.    
  149.     if [ "$DISK" != "NULL" ]
  150.             then
  151.                     echo "${BBlue}What partition program to use on $DEV$DISK"
  152.                     echo ""
  153.                     echo "${BBlue}F  - Fdisk"
  154.                     echo "${BBlue}C  - Cfdisk"
  155.                     echo "${BBlue}P  - Parted"
  156.                     echo ""
  157.                     print_askopt
  158.                     read PARTPROG
  159.                    
  160.                     case $PARTPROG in
  161.                         F|f)
  162.                             fdisk $DEV$DISK
  163.                             ;;
  164.                         C|c)
  165.                             cfdisk $DEV$DISK
  166.                             ;;
  167.                         P|p)
  168.                             parted $DEV$DISK
  169.                             ;;
  170.                        
  171.                     esac
  172.                 else
  173.                     echo "${Bold}${Red}No Disk is Selected, please select one"
  174.                     sleep 5
  175.            
  176.             fi
  177.  
  178. } #}}}
  179.    
  180. formatrootpart() {
  181.    
  182. if [ "$DISK" != "NULL" ]
  183.         then
  184.             print_line
  185.             lsblk | grep $DISK
  186.             print_line
  187.             echo ""
  188.             echo "${BBlue}Tux Hat Linux is only setup with / Root"
  189.             echo ""
  190.             read -p "Partition name without the /dev [ex: sda1]: " ROOTDISK
  191.             clear
  192.             print_line
  193.             echo "Please choose 1 partition format usually ext4"
  194.             print_line
  195.             echo ""
  196.             echo "1. Ext2"
  197.             echo "2. Ext3"
  198.             echo "3. Ext4"
  199.             echo "4. ReiserFS"
  200.             echo ""
  201.             print_askopt
  202.             read FSOPT
  203.                     case $FSOPT in
  204.                     1) 
  205.                     mkfs.ext2 $DEV$ROOTDISK
  206.                     ;;
  207.                     2)
  208.                     mkfs.ext3 $DEV$ROOTDISK
  209.                     ;;
  210.                     3)
  211.                     mkfs.ext4 $DEV$ROOTDISK
  212.                     ;;
  213.                     4)
  214.                     mkfs.reiserfs $DEV$ROOTDISK
  215.                     ;;
  216.                     esac
  217.                
  218.            
  219.             echo "${BBlue}Mounting $DEV$ROOTDISK to $MNT"
  220.             mount $DEV$ROOTDISK $MNT
  221.             else
  222.             echo "${Bold}${Red}You must select a disk"
  223.             sleep 5
  224.         fi
  225.  
  226. }
  227.  
  228. #----------------------{ Copy /opt to /mnt/opt }----------------------#
  229. cp_opt(){
  230. DIALOGRC=${DIALOGRC}
  231. CONFIGFILE=/opt/setup/setup-tuxhat.conf
  232. DIALOG=${DIALOG=dialog}
  233.  
  234. # config file for theme black and white
  235. if [[ -f $CONFIGFILE ]]; then
  236.   source $CONFIGFILE
  237. else
  238.   echo "Error missing file: setup-tuxhat.conf - Required by program"
  239.   exit 1
  240. fi
  241. ## Create an array of all files in /opt directory
  242. DIRS=(/opt/*)
  243.  
  244. #Destination directory
  245. DEST="/mnt/opt"
  246.  
  247. # Create $DEST if does not exits
  248. [ ! -d $DEST ] && mkdir -p $DEST
  249.  
  250. # Show a progress bar
  251. # ---------------------------------
  252. # Redirect dialog commands input using substitution
  253. #
  254. DIALOGRC="$DIALOGRC" $DIALOG  --backtitle "$DISTNAME$DISTVER" --title "Copy System files" --gauge "Copying files..." 10 75 < <(
  255.  
  256. # Get total number of files in array
  257.    n=${#DIRS[*]};
  258.  
  259.    # set counter - it will increase every-time a file is copied to $DEST
  260.    i=0
  261.  
  262.    #
  263.    # Start the for loop
  264.    #
  265.    # read each file from $DIRS array
  266.    # $f has filename
  267.    for f in "${DIRS[@]}"
  268.    do
  269.       # calculate progress
  270.       PCT=$(( 100*(++i)/n ))
  271.  
  272.       # update dialog box
  273. cat <<EOF
  274. XXX
  275. $PCT
  276. Copying file $f
  277. To $DEST
  278. XXX
  279. EOF
  280.   # copy file $f to $DEST
  281.   /bin/cp -ar $f ${DEST} &>/dev/null
  282.    done
  283. )                                    
  284. }
  285.  
  286. #--------------------{ Copy Bin to /mnt/usr/bin }-----------------#
  287. cp_bin(){
  288. DIALOGRC=${DIALOGRC}
  289. CONFIGFILE=/opt/setup/setup-tuxhat.conf
  290. DIALOG=${DIALOG=dialog}
  291.  
  292. # config file for theme black and white
  293. if [[ -f $CONFIGFILE ]]; then
  294.   source $CONFIGFILE
  295. else
  296.   echo "Error missing file: setup-tuxhat.conf - Required by program"
  297.   exit 1
  298. fi
  299. ## Create an array of all files in /opt directory
  300. DIRS=(/opt/setup/bin/setup-tuxhat/*)
  301.  
  302. #Destination directory
  303. DEST="/mnt/usr/bin/"
  304.  
  305. # Create $DEST if does not exits
  306. [ ! -d $DEST ] && mkdir -p $DEST
  307.  
  308. # Show a progress bar
  309. # ---------------------------------
  310. # Redirect dialog commands input using substitution
  311. #
  312. DIALOGRC="$DIALOGRC" $DIALOG  --backtitle "$DISTNAME$DISTVER" --title "Copy System files" --gauge "Copying files..." 10 75 < <(
  313.  
  314. # Get total number of files in array
  315.    n=${#DIRS[*]};
  316.  
  317.    # set counter - it will increase every-time a file is copied to $DEST
  318.    i=0
  319.  
  320.    #
  321.    # Start the for loop
  322.    #
  323.    # read each file from $DIRS array
  324.    # $f has filename
  325.    for f in "${DIRS[@]}"
  326.    do
  327.       # calculate progress
  328.       PCT=$(( 100*(++i)/n ))
  329.  
  330.       # update dialog box
  331. cat <<EOF
  332. XXX
  333. $PCT
  334. Copying file $f
  335. To $DEST
  336. XXX
  337. EOF
  338.   # copy file $f to $DEST
  339.   /bin/cp -ar $f ${DEST} &>/dev/null
  340.    done
  341. )
  342. }
  343. #-------------------------{ CREATE NEW USER }--------------------------#
  344. create_new_user(){
  345. print_title1
  346. echo ""
  347. read -p "Enter New User: " username
  348. username=`echo $username | tr '[:upper:]' '[:lower:]'`
  349. arch-chroot /mnt useradd -m -g users -G wheel -s /bin/bash ${username}
  350. arch-chroot /mnt chfn ${username}
  351. arch-chroot /mnt passwd ${username}
  352. }
  353. #---------------------{ Copy Skel to new user }------------------------#
  354. cp_skel(){
  355. ## Create an array of all files in /opt directory
  356. DIRS=(/home/arch/.*)
  357.  
  358. #Destination directory
  359. DEST=/mnt/home/${username}
  360.  
  361. # Create $DEST if does not exits
  362. [ ! -d $DEST ] && mkdir -p $DEST
  363.  
  364. # Show a progress bar
  365. # ---------------------------------
  366. # Redirect dialog commands input using substitution
  367. #
  368. DIALOGRC="$DIALOGRC" $DIALOG --backtitle "$DISTNAME$DISTVER" --title "Copy System files" --gauge "Copying files..." 10 75 < <(
  369.  
  370. # Get total number of files in array
  371.    n=${#DIRS[*]};
  372.  
  373.    # set counter - it will increase every-time a file is copied to $DEST
  374.    i=0
  375.  
  376.    #
  377.    # Start the for loop
  378.    #
  379.    # read each file from $DIRS array
  380.    # $f has filename
  381.    for f in "${DIRS[@]}"
  382.    do
  383.       # calculate progress
  384.       PCT=$(( 100*(++i)/n ))
  385.  
  386.       # update dialog box
  387. cat <<EOF
  388. XXX
  389. $PCT
  390. Copying file $f
  391. To $DEST
  392. XXX
  393. EOF
  394.   # copy file $f to $DEST
  395.   /bin/cp -r $f ${DEST} &>/dev/null
  396.   /bin/rm -rf /mnt/home/${username}/arch
  397.    done
  398. )
  399. }
  400.  
  401. #To setup awesome rc.lua for new user
  402. configure_awesome() {                          
  403.                                      
  404. cat /mnt/opt/awesome/rc.lua | sed s/arch/${username}/g > /mnt/opt/awesome/rc.out
  405. cp -v /mnt/opt/awesome/rc.out /mnt/home/${username}/.config/awesome/rc.lua                                        
  406. }
  407. #Chmod New User
  408. chmod_user(){
  409. arch-chroot /mnt chmod -R 777 /home/${username}
  410. arch-chroot /mnt chmod -R 777 /home/${username}/.config
  411. }
  412. #--------------{ Hostname Setup }----------------#
  413. configure_hostname(){
  414. print_title0   
  415. echo ""
  416. read -p "Please enter a hostname [ex: tuxhatlinux]: " host_name
  417. echo "$host_name" > /mnt/etc/hostname
  418. }
  419.  
  420. syslinux_setup() {                                                                
  421. arch-chroot /mnt syslinux-install_update -iam                                    
  422. }  
  423.  
  424. #--------------{ Copy Syslinux/* to /mnt/boot/syslinux }---------------#
  425. cp_syslinux(){
  426. ## Create an array of all files in /opt directory
  427. DIRS=(/opt/syslinux/.*)
  428.  
  429. #Destination directory
  430. DEST=/mnt/boot/syslinux/
  431.  
  432. # Create $DEST if does not exits
  433. [ ! -d $DEST ] && mkdir -p $DEST
  434.  
  435. # Show a progress bar
  436. # ---------------------------------
  437. # Redirect dialog commands input using substitution
  438. #
  439. DIALOGRC="$DIALOGRC" $DIALOG --backtitle "$DISTNAME$DISTVER" --title "Copy System files" --gauge "Copying files..." 10 75 < <(
  440.  
  441. # Get total number of files in array
  442.    n=${#DIRS[*]};
  443.  
  444.    # set counter - it will increase every-time a file is copied to $DEST
  445.    i=0
  446.  
  447.    #
  448.    # Start the for loop
  449.    #
  450.    # read each file from $DIRS array
  451.    # $f has filename
  452.    for f in "${DIRS[@]}"
  453.    do
  454.       # calculate progress
  455.       PCT=$(( 100*(++i)/n ))
  456.  
  457.       # update dialog box
  458. cat <<EOF
  459. XXX
  460. $PCT
  461. Copying file $f
  462. To $DEST
  463. XXX
  464. EOF
  465.   # copy file $f to $DEST
  466.   /bin/cp -r $f ${DEST} &>/dev/null
  467.    done
  468. )
  469. }
  470.  
  471. #--------------{ Copy THL Session Menu to profile.d }---------------#
  472. cp_thlspd(){
  473. ## Create an array of all files in /opt directory
  474. DIRS=(/etc/profile.d/tuxhatlinux.sh)
  475.  
  476. #Destination directory
  477. DEST=/mnt/etc/profile.d/
  478.  
  479. # Create $DEST if does not exits
  480. [ ! -d $DEST ] && mkdir -p $DEST
  481.  
  482. # Show a progress bar
  483. # ---------------------------------
  484. # Redirect dialog commands input using substitution
  485. #
  486. DIALOGRC="$DIALOGRC" $DIALOG --backtitle "$DISTNAME$DISTVER" --title "Copy System files" --gauge "Copying files..." 10 75 < <(
  487.  
  488. # Get total number of files in array
  489.    n=${#DIRS[*]};
  490.  
  491.    # set counter - it will increase every-time a file is copied to $DEST
  492.    i=0
  493.  
  494.    #
  495.    # Start the for loop
  496.    #
  497.    # read each file from $DIRS array
  498.    # $f has filename
  499.    for f in "${DIRS[@]}"
  500.    do
  501.       # calculate progress
  502.       PCT=$(( 100*(++i)/n ))
  503.  
  504.       # update dialog box
  505. cat <<EOF
  506. XXX
  507. $PCT
  508. Copying file $f
  509. To $DEST
  510. XXX
  511. EOF
  512.   # copy file $f to $DEST
  513.   /bin/cp -r $f ${DEST} &>/dev/null
  514.    done
  515. )
  516. }
  517.  
  518. #--------------{ Copy pacman.conf to /mnt/etc/ }---------------#
  519. cp_pacman(){
  520. ## Create an array of all files in /opt directory
  521. DIRS=(/etc/pacman.conf)
  522.  
  523. #Destination directory
  524. DEST=/mnt/etc/
  525.  
  526. # Create $DEST if does not exits
  527. [ ! -d $DEST ] && mkdir -p $DEST
  528.  
  529. # Show a progress bar
  530. # ---------------------------------
  531. # Redirect dialog commands input using substitution
  532. #
  533. DIALOGRC="$DIALOGRC" $DIALOG --backtitle "$DISTNAME$DISTVER" --title "Copy System files" --gauge "Copying files..." 10 75 < <(
  534.  
  535. # Get total number of files in array
  536.    n=${#DIRS[*]};
  537.  
  538.    # set counter - it will increase every-time a file is copied to $DEST
  539.    i=0
  540.  
  541.    #
  542.    # Start the for loop
  543.    #
  544.    # read each file from $DIRS array
  545.    # $f has filename
  546.    for f in "${DIRS[@]}"
  547.    do
  548.       # calculate progress
  549.       PCT=$(( 100*(++i)/n ))
  550.  
  551.       # update dialog box
  552. cat <<EOF
  553. XXX
  554. $PCT
  555. Copying file $f
  556. To $DEST
  557. XXX
  558. EOF
  559.   # copy file $f to $DEST
  560.   /bin/cp -r $f ${DEST} &>/dev/null
  561.    done
  562. )
  563. }
  564.  
  565. #------------------------{ Network Setup }-------------------------#
  566. network_interface(){
  567. print_title2
  568. echo ""
  569. ip link show
  570. print_line
  571. read -p "${BBlue}dhcp-interface: " dhcpif
  572. dhcpif=`echo $dhcpif | tr '[:upper:]' '[:lower:]'`
  573. sudo systemctl enable dhcpcd@${dhcpif}.service
  574. sudo systemctl start dhcpcd@${dhcpif}.service
  575.  
  576. }
Advertisement
Add Comment
Please, Sign In to add comment