unixwz0r

gfuncs.sh

Dec 30th, 2014
309
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 23.63 KB | None | 0 0
  1. #!/bin/bash
  2. #-------------------------------------------------------------------------------
  3. #Created by Gary Perreault mailto: tuxhatlinuxdistro[at]gmail[dot]com
  4. #inspired by script that was created by user helmuthdu & Vincent0ne-
  5. #mailto: helmuthdu[at]gmail[dot]com
  6. #Contribution: flexiondotorg
  7. #mailto: Vincent[at]gmail[dot]com
  8. #-------------------------------------------------------------------------------
  9. #This program is free software: you can redistribute it and/or modify
  10. #it under the terms of the GNU General Public License as published by
  11. #the Free Software Foundation, either version 3 of the License, or
  12. #(at your option) any later version.
  13. #
  14. #This program is distributed in the hope that it will be useful,
  15. #but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. #MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. #GNU General Public License for more details.
  18. #
  19. #You should have received a copy of the GNU General Public License
  20. #along with this program. If not, see <http://www.gnu.org/licenses/>.
  21. #-------------------------------------------------------------------------------
  22. # Run this script after your first boot with archlinux (as root)
  23. #--------------------------------------------------------------------------------
  24. # Explaination of the Script: this is the script global functions for the
  25. # arch-setup & tuxhat-install installer scripts.
  26. # Keep it simple!
  27. # What you see, is what you get!
  28.  
  29. #Varibles to Show weather is configured
  30. checklist=( 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 )
  31. # COLORS {{{
  32. Bold=$(tput bold)
  33. Underline=$(tput sgr 0 1)
  34. Reset=$(tput sgr0)
  35. # Regular Colors
  36. Red=$(tput setaf 1)
  37. Green=$(tput setaf 2)
  38. Yellow=$(tput setaf 3)
  39. Blue=$(tput setaf 4)
  40. Purple=$(tput setaf 5)
  41. Cyan=$(tput setaf 6)
  42. White=$(tput setaf 7)
  43. # Bold
  44. BRed=${Bold}$(tput setaf 1)
  45. BGreen=${Bold}$(tput setaf 2)
  46. BYellow=${Bold}$(tput setaf 3)
  47. BBlue=${Bold}$(tput setaf 4)
  48. BPurple=${Bold}$(tput setaf 5)
  49. BCyan=${Bold}$(tput setaf 6)
  50. BWhite=${Bold}$(tput setaf 7)
  51. #}}}
  52.  
  53.  
  54. DFOUT=/tmp/dfout.$$
  55.  
  56. print_askopt() {
  57. echo
  58. echo -en "${Bold}${White}Which Option do you require: "
  59.  
  60. }
  61.  
  62. print_askopt2() {
  63. echo
  64. echo -en "${Yellow}Which setup script do you require: "
  65. }
  66.  
  67. # CONNECTION CHECK
  68. XPINGS=0
  69. #MISC
  70. SPIN="/-\|"
  71. AUTOMATIC_MODE=0
  72.  
  73. #CREATE NEW USER {{{
  74. create_new_user(){
  75. read -p "Username: " username
  76. username=`echo $username | tr '[:upper:]' '[:lower:]'`
  77. useradd -m -g users -G wheel -s /bin/bash ${username}
  78. chfn ${username}
  79. passwd ${username}
  80. chmod -R 777 /home/${username}
  81. while [[ $? -ne 0 ]]; do
  82. passwd ${username}
  83. chmod -R 777 /home/${username}
  84. done
  85. }
  86.  
  87. configure_awesome() {
  88.  
  89. cat /opt/awesome/rc.lua | sed s/arch/${username}/g > /opt/awesome/rc.out
  90. cp -v /opt/awesome/rc.out /home/${username}/.config/awesome/rc.lua
  91.  
  92. }
  93.  
  94.  
  95. #COPY ISO SKEL TO NEW USER {{{
  96. cp_skel(){
  97. cp -vr /home/arch/.* /home/${username}
  98. chmod -R 777 /home/${username}
  99. rm -rf /home/arch
  100. rm -rf /home/${username}/arch
  101. rm -rf /home/${username}/${username}
  102. configure_awesome
  103. }
  104.  
  105. # PROMPT {{{
  106. prompt1="Enter your option: "
  107. prompt2="Enter n° of options (ex: 1 2 3 or 1-3): "
  108. prompt3="You have to manually enter the following commands, then press ${BYellow}ctrl+d${Reset} or type ${BYellow}exit${Reset}:"
  109. #}}}
  110.  
  111. #}}}
  112. #CONFIGURE HOSTNAME {{{
  113. configure_hostname(){
  114. print_title2 "Setup hostname"
  115. read -p "Hostname [ex: tuxhatlinux]: " host_name
  116. echo "$host_name" > /etc/hostname
  117. }
  118.  
  119. print_title0() { #{{{
  120. clear
  121. print_line
  122. echo -e "${Bold}${Red}**** Syslinux Configs **** Current root Disk is $ROOTDSK ****${Reset}"
  123. } #}}}
  124.  
  125. print_title1() { #{{{
  126. clear
  127. echo -e "${Bold}${Red} **** ${Underline}Welcome To Arch Linux Base Installer Script${Reset} ${Bold}${Red}****"
  128. echo ""
  129. } #}}}
  130.  
  131. print_title2() { #{{{
  132. clear
  133. echo -e "${Bold}${Red} **** ${Underline}Welcome To Tux Hat Linux Installer Script${Reset} ${Bold}${Red}****"
  134. echo ""
  135. } #}}}
  136.  
  137. print_title3() { #{{{
  138. clear
  139. echo -e "${Bold}${Cyan} **** ${Underline}Welcome Distro-Setup Script${Reset} ${Bold}${Cyan}****"
  140. echo ""
  141. } #}}}
  142.  
  143. print_title4() { #{{{
  144. clear
  145. echo -e "${Bold}${Green} **** ${Underline}Video Setup Script + Steam${Reset} ${Bold}${Green}****"
  146. echo""
  147. } #}}}
  148.  
  149. print_title5() { #{{{
  150. clear
  151. echo -e "${Bold}${Green} **** ${Underline}Compton Setup Script${Reset} ${Bold}${Green}****"
  152. echo""
  153. } #}}}
  154.  
  155. print_title6() { #{{{
  156. clear
  157. echo -e "${Bold}${Red} **** ${Underline}Network Setup Script${Reset} ${Bold}${Red}****"
  158. echo""
  159. } #}}}
  160.  
  161. print_title7() { #{{{
  162. clear
  163. echo -e "${Bold}${Red} **** ${Underline}Virtualbox Guest Setup Script${Reset} ${Bold}${Red}****"
  164. echo""
  165. } #}}}
  166.  
  167. print_title8() { #{{{
  168. clear
  169. echo -e "${Bold}${Red} **** ${Underline}Steam Client Setip Script${Reset} ${Bold}${Red}****"
  170. echo""
  171. } #}}}
  172.  
  173. print_title_nocls() { #{{{
  174. echo -e "${Green}# ${Bold}$1"
  175. print_line
  176. echo ""
  177. } #}}}
  178.  
  179.  
  180.  
  181. pause_function() { #{{{
  182. print_line
  183. if [[ $AUTOMATIC_MODE -eq 0 ]]; then
  184. read -e -sn 1 -p "${White}Press enter to continue..."
  185. fi
  186. }
  187.  
  188. print_line() { #{{{
  189. printf "%$(tput cols)s\n"|tr ' ' '-'
  190. } #}}}
  191.  
  192. print_dbline() { #{{{
  193. printf "%$(tput cols)s\n"|tr ' ' '='
  194. } #}}}
  195.  
  196. print_info() { #{{{
  197. #Console width number
  198. T_COLS=`tput cols`
  199. echo -e "${Bold}$1${Reset}\n" | fold -sw $(( $T_COLS - 18 )) | sed 's/^/\t/'
  200. } #}}}
  201.  
  202.  
  203. print_warning() { #{{{
  204. T_COLS=`tput cols`
  205. echo -e "${BYellow}$1${Reset}\n" | fold -sw $(( $T_COLS - 1 ))
  206. } #}}}
  207. print_danger() { #{{{
  208. T_COLS=`tput cols`
  209. echo -e "${BRed}$1${Reset}\n" | fold -sw $(( $T_COLS - 1 ))
  210. } #}}}
  211. start_module() { #{{{
  212. modprobe $1
  213. } #}}}
  214. add_module() { #{{{
  215. #check if the number of arguments is less then 2
  216. for MODULE in $1; do
  217. [[ $# -lt 2 ]] && MODULE_NAME="$MODULE" || MODULE_NAME="$2"
  218. local IS_DISABLED=`cat /etc/modules-load.d/$MODULE_NAME.conf | grep $MODULE &> /dev/null`
  219. [[ -z $IS_DISABLED ]] && echo "$MODULE" >> /etc/modules-load.d/$MODULE_NAME.conf
  220. start_module "$MODULE"
  221. done
  222. } #}}}
  223. add_repository() { #{{{
  224. REPO=${1}
  225. URL=${2}
  226. [[ -n ${3} ]] && SIGLEVEL="\nSigLevel = ${3}" || SIGLEVEL=""
  227.  
  228. CHECK_REPO=`grep -F "${REPO}" /etc/pacman.conf`
  229. if [[ -z $CHECK_REPO ]]; then
  230. echo -e "\n[${REPO}]${SIGLEVEL}\nServer = ${URL}" >> /etc/pacman.conf
  231. system_update
  232. fi
  233. } #}}}
  234. check_multilib(){ #{{{
  235. # this option will avoid any problem with packages install
  236. if [[ $ARCHI == x86_64 ]]; then
  237. local HAS_MULTILIB=`grep -n "\[multilib\]" /etc/pacman.conf | cut -f1 -d:`
  238. if [[ -z $HAS_MULTILIB ]]; then
  239. echo -e "\n[multilib]\nInclude = /etc/pacman.d/mirrorlist" >> /etc/pacman.conf
  240. echo -e '\nMultilib repository added into pacman.conf file'
  241. else
  242. sed -i "${HAS_MULTILIB}s/^#//" /etc/pacman.conf
  243. local HAS_MULTILIB=$(( $HAS_MULTILIB + 1 ))
  244. sed -i "${HAS_MULTILIB}s/^#//" /etc/pacman.conf
  245. fi
  246. fi
  247. } #}}}
  248. add_key() { #{{{
  249. pacman-key -r $1
  250. pacman-key --lsign-key $1
  251. } #}}}
  252. pacman_key(){ #{{{
  253. if [[ ! -d /etc/pacman.d/gnupg ]]; then
  254. print_title "PACMAN KEY - https://wiki.archlinux.org/index.php/pacman-key"
  255. print_info "Pacman uses GnuPG keys in a web of trust model to determine if packages are authentic."
  256. package_install "haveged"
  257. haveged -w 1024
  258. pacman-key --init
  259. pacman-key --populate archlinux
  260. pkill haveged
  261. package_remove "haveged"
  262. fi
  263. } #}}}
  264. add_line() { #{{{
  265. ADD_LINE=${1}
  266. FILEPATH=${2}
  267.  
  268. CHECK_LINE=`grep -F "${ADD_LINE}" ${FILEPATH} &> /dev/null`
  269. [[ -z $CHECK_LINE ]] && echo "${ADD_LINE}" >> ${FILEPATH}
  270. } #}}}
  271. replace_line() { #{{{
  272. SEARCH=${1}
  273. REPLACE=${2}
  274. FILEPATH=${3}
  275. FILEBASE=`basename ${3}`
  276.  
  277. sed -e "s/${SEARCH}/${REPLACE}/" ${FILEPATH} > /tmp/${FILEBASE} 2>"$LOG"
  278. if [[ ${?} -eq 0 ]]; then
  279. mv /tmp/${FILEBASE} ${FILEPATH}
  280. else
  281. cecho "failed: ${SEARCH} - ${FILEPATH}"
  282. fi
  283. } #}}}
  284. update_early_modules() { #{{{
  285. local NEW_MODULE=${1}
  286. local OLD_ARRAY=`egrep ^MODULES= /etc/mkinitcpio.conf`
  287.  
  288. if [[ -n ${NEW_MODULE} ]]; then
  289. # Determine if the new module is already listed.
  290. _EXISTS=`echo ${OLD_ARRAY} | grep ${NEW_MODULE}`
  291. if [ $? -eq 1 ]; then
  292.  
  293. source /etc/mkinitcpio.conf
  294. if [[ -z ${MODULES} ]]; then
  295. NEW_MODULES="${NEW_MODULE}"
  296. else
  297. NEW_MODULES="${MODULES} ${NEW_MODULE}"
  298. fi
  299. replace_line "MODULES=\"${MODULES}\"" "MODULES=\"${NEW_MODULES}\"" /etc/mkinitcpio.conf
  300. ncecho " ${BBlue}[${Reset}${Bold}X${BBlue}]${Reset} Rebuilding init "
  301. mkinitcpio -p linux >>"$LOG" 2>&1 &
  302. pid=$!;progress $pid
  303. fi
  304. fi
  305. } #}}}
  306. is_package_installed() { #{{{
  307. #check if a package is already installed
  308. for PKG in $1; do
  309. pacman -Q $PKG &> /dev/null && return 0;
  310. done
  311. return 1
  312. } #}}}
  313. checkbox() { #{{{
  314. #display [X] or [ ]
  315. [[ "$1" -eq 1 ]] && echo -e "${BBlue}[${Reset}${Bold}X${BBlue}]${Reset}" || echo -e "${BBlue}[ ${BBlue}]${Reset}";
  316. } #}}}
  317. checkbox_package() { #{{{
  318. #check if [X] or [ ]
  319. is_package_installed "$1" && checkbox 1 || checkbox 0
  320. } #}}}
  321. aui_download_packages() { #{{{
  322. for PKG in $1; do
  323. #exec command as user instead of root
  324. su - ${username} -c "
  325. [[ ! -d aui_packages ]] && mkdir aui_packages
  326. cd aui_packages
  327. curl -o $PKG.tar.gz https://aur.archlinux.org/packages/${PKG:0:2}/$PKG/$PKG.tar.gz
  328. tar zxvf $PKG.tar.gz
  329. rm $PKG.tar.gz
  330. cd $PKG
  331. makepkg -csi --noconfirm
  332. "
  333. done
  334. } #}}}
  335. aur_package_install() { #{{{
  336. su - ${username} -c "sudo -v"
  337. #install package from aur
  338. for PKG in $1; do
  339. if ! is_package_installed "${PKG}" ; then
  340. if [[ $AUTOMATIC_MODE -eq 1 ]]; then
  341. ncecho " ${BBlue}[${Reset}${Bold}X${BBlue}]${Reset} Installing ${AUR} ${Bold}${PKG}${Reset} "
  342. su - ${username} -c "${AUR_PKG_MANAGER} --noconfirm -S ${PKG}" >>"$LOG" 2>&1 &
  343. pid=$!;progress $pid
  344. else
  345. su - ${username} -c "${AUR_PKG_MANAGER} -S ${PKG}"
  346. fi
  347. else
  348. if [[ $VERBOSE_MODE -eq 0 ]]; then
  349. cecho " ${BBlue}[${Reset}${Bold}X${BBlue}]${Reset} Installing ${AUR} ${Bold}${PKG}${Reset} success"
  350. else
  351. echo -e "Warning: ${PKG} is up to date --skipping"
  352. fi
  353. fi
  354. done
  355. } #}}}
  356. package_install() { #{{{
  357. #install packages using pacman
  358. if [[ $AUTOMATIC_MODE -eq 1 || $VERBOSE_MODE -eq 0 ]]; then
  359. for PKG in ${1}; do
  360. PKG_REPO=`pacman -Sp --print-format %r ${PKG} | uniq | sed '1!d'`
  361. case $PKG_REPO in
  362. "core")
  363. PKG_REPO="${BRed}${PKG_REPO}${Reset}"
  364. ;;
  365. "extra")
  366. PKG_REPO="${BYellow}${PKG_REPO}${Reset}"
  367. ;;
  368. "community")
  369. PKG_REPO="${BGreen}${PKG_REPO}${Reset}"
  370. ;;
  371. "multilib")
  372. PKG_REPO="${BCyan}${PKG_REPO}${Reset}"
  373. ;;
  374. esac
  375. if ! is_package_installed "${PKG}" ; then
  376. ncecho " ${BBlue}[${Reset}${Bold}X${BBlue}]${Reset} Installing (${PKG_REPO}) ${Bold}${PKG}${Reset} "
  377. pacman -S --noconfirm --needed ${PKG} >>"$LOG" 2>&1 &
  378. pid=$!;progress $pid
  379. else
  380. cecho " ${BBlue}[${Reset}${Bold}X${BBlue}]${Reset} Installing (${PKG_REPO}) ${Bold}${PKG}${Reset} exists "
  381. fi
  382. done
  383. else
  384. pacman -S --needed ${1}
  385. fi
  386. } #}}}
  387. package_remove() { #{{{
  388. #remove package
  389. for PKG in ${1}; do
  390. if is_package_installed "${PKG}" ; then
  391. if [[ $AUTOMATIC_MODE -eq 1 || $VERBOSE_MODE -eq 0 ]]; then
  392. ncecho " ${BBlue}[${Reset}${Bold}X${BBlue}]${Reset} Removing ${Bold}${PKG}${Reset} "
  393. pacman -Rcsn --noconfirm ${PKG} >>"$LOG" 2>&1 &
  394. pid=$!;progress $pid
  395. else
  396. pacman -Rcsn ${PKG}
  397. fi
  398. fi
  399. done
  400. } #}}}
  401. system_update() { #{{{
  402. pacman -Syy
  403. } #}}}
  404. npm_install() { #{{{
  405. #install packages using pacman
  406. npm install -g $1
  407. } #}}}
  408. gem_install() { #{{{
  409. #install packages using pacman
  410. for PKG in ${1}; do
  411. sudo -u ${username} gem install -V $PKG
  412. done
  413. } #}}}
  414. contains_element() { #{{{
  415. #check if an element exist in a string
  416. for e in "${@:2}"; do [[ $e == $1 ]] && break; done;
  417. } #}}}
  418. config_xinitrc() { #{{{
  419. #create a xinitrc file in home user directory
  420. cp -fv /etc/skel/.xinitrc /home/${username}/
  421. echo -e "exec $1" >> /home/${username}/.xinitrc
  422. chown -R ${username}:users /home/${username}/.xinitrc
  423. } #}}}
  424. invalid_option() { #{{{
  425. print_line
  426. echo "Invalid option. Try another one."
  427. pause_function
  428. } #}}}
  429. pause_function() { #{{{
  430. print_line
  431. if [[ $AUTOMATIC_MODE -eq 0 ]]; then
  432. read -e -sn 1 -p "Press enter to continue..."
  433. fi
  434. } #}}}
  435. menu_item() { #{{{
  436. #check if the number of arguments is less then 2
  437. [[ $# -lt 2 ]] && PACKAGE_NAME="$1" || PACKAGE_NAME="$2";
  438. #list of chars to remove from the package name
  439. CHARS_TO_REMOVE=("Ttf-" "-bzr" "-hg" "-svn" "-git" "-stable" "-icon-theme" "Gnome-shell-theme-" "Gnome-shell-extension-");
  440. #remove chars from package name
  441. for CHARS in ${CHARS_TO_REMOVE[@]}; do PACKAGE_NAME=`echo ${PACKAGE_NAME^} | sed 's/'$CHARS'//'`; done
  442. #display checkbox and package name
  443. echo -e "$(checkbox_package "$1") ${Bold}$PACKAGE_NAME${Reset}"
  444. } #}}}
  445. mainmenu_item() { #{{{
  446. echo -e "$(checkbox "$1") ${Bold}$2${Reset}"
  447. } #}}}
  448. elihw() { #{{{
  449. [[ $OPT == b || $OPT == d ]] && break;
  450. } #}}}
  451. add_user_to_group() { #{{{
  452. local _USER=${1}
  453. local _GROUP=${2}
  454.  
  455. if [[ -z ${_GROUP} ]]; then
  456. error_msg "ERROR! 'add_user_to_group' was not given enough parameters."
  457. fi
  458.  
  459. ncecho " ${BBlue}[${Reset}${Bold}X${BBlue}]${Reset} Adding ${Bold}${_USER}${Reset} to ${Bold}${_GROUP}${Reset} "
  460. gpasswd -a ${_USER} ${_GROUP} >>"$LOG" 2>&1 &
  461. pid=$!;progress $pid
  462. } #}}}
  463. system_ctl() { #{{{
  464. local ACTION=${1}
  465. local OBJECT=${2}
  466. ncecho " ${BBlue}[${Reset}${Bold}X${BBlue}]${Reset} systemctl ${ACTION} ${OBJECT} "
  467. systemctl ${ACTION} ${OBJECT} >> "$LOG" 2>&1
  468. pid=$!;progress $pid
  469. }
  470. #}}}
  471. arch_chroot() { #{{{
  472. arch-chroot $MOUNTPOINT /bin/bash "${1}"
  473. }
  474. #}}}
  475. getkeymap() { #{{{
  476. local keymaps=(`localectl list-keymaps`)
  477. PS3="(shift+pgup/pgdown) $prompt1"
  478. echo "Select keymap:"
  479. select KEYMAP in "${keymaps[@]}"; do
  480. if contains_element "$KEYMAP" "${keymaps[@]}"; then
  481. break
  482. else
  483. invalid_option
  484. fi
  485. done
  486. }
  487. #}}}
  488. setlocale() { #{{{
  489. local locale_list=(`cat /etc/locale.gen | grep UTF-8 | sed 's/\..*$//' | sed '/@/d' | awk '{print $1}' | uniq | sed 's/#//g'`);
  490. PS3="$prompt1"
  491. echo "Select locale:"
  492. select LOCALE in "${locale_list[@]}"; do
  493. if contains_element "$LOCALE" "${locale_list[@]}"; then
  494. LOCALE_UTF8="${LOCALE}.UTF-8"
  495. break
  496. else
  497. invalid_option
  498. fi
  499. done
  500. }
  501. #}}}
  502. settimezone() { #{{{
  503. local zone=(`timedatectl list-timezones | sed 's/\/.*$//' | uniq`);
  504. PS3="$prompt1"
  505. echo "Select zone:"
  506. select ZONE in "${zone[@]}"; do
  507. if contains_element "$ZONE" "${zone[@]}"; then
  508. local subzone=(`timedatectl list-timezones | grep ${ZONE} | sed 's/^.*\///'`)
  509. PS3="$prompt1"
  510. echo "Select subzone:"
  511. select SUBZONE in "${subzone[@]}"; do
  512. if contains_element "$SUBZONE" "${subzone[@]}"; then
  513. break
  514. else
  515. invalid_option
  516. fi
  517. done
  518. break
  519. else
  520. invalid_option
  521. fi
  522. done
  523. } #}}}
  524.  
  525. error_msg() { #{{{
  526. local MSG="${1}"
  527. echo -e "${MSG}"
  528. exit 1
  529. } #}}}
  530. cecho() { #{{{
  531. echo -e "$1"
  532. echo -e "$1" >>"$LOG"
  533. tput sgr0;
  534. } #}}}
  535. ncecho() { #{{{
  536. echo -ne "$1"
  537. echo -ne "$1" >>"$LOG"
  538. tput sgr0
  539. } #}}}
  540. spinny() { #{{{
  541. echo -ne "\b${SPIN:i++%${#SPIN}:1}"
  542. } #}}}
  543. progress() { #{{{
  544. ncecho " ";
  545. while true; do
  546. kill -0 $pid &> /dev/null;
  547. if [[ $? == 0 ]]; then
  548. spinny
  549. sleep 0.25
  550. else
  551. ncecho "\b\b";
  552. wait $pid
  553. retcode=$?
  554. echo -ne "$pid's retcode: $retcode" >> $LOG
  555. if [[ $retcode == 0 ]] || [[ $retcode == 255 ]]; then
  556. cecho success
  557. else
  558. cecho failed
  559. echo -e "$PKG" >> $PKG_FAIL
  560. tail -n 15 $LOG
  561. read -p "ERROR! Continue install [y/N]?" OPTION
  562. [[ $OPTION != y ]] && exit 1
  563. fi
  564. break
  565. fi
  566. done
  567. } #}}}
  568. check_boot_system() { # {{{
  569. if [[ "$(cat /sys/class/dmi/id/sys_vendor)" == 'Apple Inc.' ]] || [[ "$(cat /sys/class/dmi/id/sys_vendor)" == 'Apple Computer, Inc.' ]]; then
  570. modprobe -r -q efivars || true # if MAC
  571. else
  572. modprobe -q efivarfs # all others
  573. fi
  574. if [[ -d "/sys/firmware/efi/" ]]; then
  575. ## Mount efivarfs if it is not already mounted
  576. if [[ -z $(mount | grep /sys/firmware/efi/efivars) ]]; then
  577. mount -t efivarfs efivarfs /sys/firmware/efi/efivars
  578. fi
  579. UEFI=1
  580. echo "UEFI Mode detected"
  581. else
  582. UEFI=0
  583. echo "BIOS Mode detected"
  584. fi
  585. }
  586. #}}}
  587. check_root() { #{{{
  588. if [[ "$(id -u)" != "0" ]]; then
  589. error_msg "ERROR! You must execute the script as the 'root' user."
  590. fi
  591. } #}}}
  592. check_user() { #{{{
  593. if [[ "$(id -u)" == "0" ]]; then
  594. error_msg "ERROR! You must execute the script as a normal user."
  595. fi
  596. } #}}}
  597. check_archlinux() { #{{{
  598. if [[ ! -e /etc/arch-release ]]; then
  599. error_msg "ERROR! You must execute the script on Arch Linux."
  600. fi
  601. } #}}}
  602. check_hostname() { #{{{
  603. if [[ `echo ${HOSTNAME} | sed 's/ //g'` == "" ]]; then
  604. error_msg "ERROR! Hostname is not configured."
  605. fi
  606. } #}}}
  607. check_pacman_blocked() { #{{{
  608. if [[ -f /var/lib/pacman/db.lck ]]; then
  609. error_msg "ERROR! Pacman is blocked. \nIf not running remove /var/lib/pacman/db.lck."
  610. fi
  611. } #}}}
  612. check_domainname() { #{{{
  613. DOMAINNAME=`echo ${HOSTNAME} | cut -d'.' -f2- | sed 's/ //g'`
  614.  
  615. # Hmm, still no domain name. Keep looking...
  616. if [[ "${DOMAINNAME}" == "" ]]; then
  617. DOMAINNAME=`grep domain /etc/resolv.conf | sed 's/domain //g' | sed 's/ //g'`
  618. fi
  619.  
  620. # OK, give up.
  621. if [[ "${DOMAINNAME}" == "" ]]; then
  622. error_msg "ERROR! Domain name is not configured."
  623. fi
  624. } #}}}
  625. check_connection(){ #{{{
  626. XPINGS=$(( $XPINGS + 1 ))
  627. connection_test() {
  628. ping -q -w 1 -c 1 `ip r | grep default | awk 'NR==1 {print $3}'` &> /dev/null && return 1 || return 0
  629. }
  630. WIRED_DEV=`ip link | grep enp | awk '{print $2}'| sed 's/://' | sed '1!d'`
  631. WIRELESS_DEV=`ip link | grep wlp | awk '{print $2}'| sed 's/://' | sed '1!d'`
  632. if connection_test; then
  633. print_warning "ERROR! Connection not Found."
  634. print_info "Network Setup"
  635. conn_type_list=("Wired Automatic" "Wired Manual" "Wireless" "Configure Proxy" "Skip")
  636. PS3="$prompt1"
  637. select CONNECTION_TYPE in "${conn_type_list[@]}"; do
  638. case "$REPLY" in
  639. 1)
  640. systemctl start dhcpcd@${WIRED_DEV}.service
  641. break
  642. ;;
  643. 2)
  644. systemctl stop dhcpcd@${WIRED_DEV}.service
  645. read -p "IP Address: " IP_ADDR
  646. read -p "Submask: " SUBMASK
  647. read -p "Gateway: " GATEWAY
  648. ip link set ${WIRED_DEV} up
  649. ip addr add ${IP_ADDR}/${SUBMASK} dev ${WIRED_DEV}
  650. ip route add default via ${GATEWAY}
  651. $EDITOR /etc/resolv.conf
  652. break
  653. ;;
  654. 3)
  655. ip link set ${WIRELESS_DEV} up
  656. wifi-menu ${WIRELESS_DEV}
  657. break
  658. ;;
  659. 4)
  660. read -p "Enter your proxy e.g. protocol://adress:port: " OPTION
  661. export http_proxy=$OPTION
  662. export https_proxy=$OPTION
  663. export ftp_proxy=$OPTION
  664. echo "proxy = $OPTION" > ~/.curlrc
  665. break
  666. ;;
  667. 5)
  668. break
  669. ;;
  670. *)
  671. invalid_option
  672. ;;
  673. esac
  674. done
  675. if [[ $XPINGS -gt 2 ]]; then
  676. print_warning "Can't establish connection. exiting..."
  677. exit 1
  678. fi
  679. [[ $REPLY -ne 5 ]] && check_connection
  680. fi
  681. } #}}}
  682. check_vga() { #{{{
  683. # Determine video chipset - only Intel, ATI and nvidia are supported by this script
  684. ncecho " ${BBlue}[${Reset}${Bold}X${BBlue}]${Reset} Detecting video chipset "
  685. local VGA=`lspci | grep VGA | tr "[:upper:]" "[:lower:]"`
  686. local VGA_NUMBER=`lspci | grep VGA | wc -l`
  687.  
  688. if [[ -n $(dmidecode --type 1 | grep VirtualBox) ]]; then
  689. cecho Virtualbox
  690. VIDEO_DRIVER="virtualbox"
  691. elif [[ $VGA_NUMBER -eq 2 ]] && [[ -n $(echo ${VGA} | grep "nvidia") || -f /sys/kernel/debug/dri/0/vbios.rom ]]; then
  692. cecho Bumblebee
  693. VIDEO_DRIVER="bumblebee"
  694. elif [[ -n $(echo ${VGA} | grep "nvidia") || -f /sys/kernel/debug/dri/0/vbios.rom ]]; then
  695. cecho Nvidia
  696. read_input_text "Install NVIDIA proprietary driver" $PROPRIETARY_DRIVER
  697. if [[ $OPTION == y ]]; then
  698. VIDEO_DRIVER="nvidia"
  699. else
  700. VIDEO_DRIVER="nouveau"
  701. fi
  702. elif [[ -n $(echo ${VGA} | grep "advanced micro devices") || -f /sys/kernel/debug/dri/0/radeon_pm_info || -f /sys/kernel/debug/dri/0/radeon_sa_info ]]; then
  703. cecho AMD/ATI
  704. read_input_text "Install ATI proprietary driver" $PROPRIETARY_DRIVER
  705. if [[ $OPTION == y ]]; then
  706. VIDEO_DRIVER="catalyst"
  707. else
  708. VIDEO_DRIVER="ati"
  709. fi
  710. elif [[ -n $(echo ${VGA} | grep "intel corporation") || -f /sys/kernel/debug/dri/0/i915_capabilities ]]; then
  711. cecho Intel
  712. VIDEO_DRIVER="intel"
  713. else
  714. cecho VESA
  715. VIDEO_DRIVER="vesa"
  716. fi
  717. OPTION="y"
  718. [[ $VIDEO_DRIVER == intel || $VIDEO_DRIVER == vesa ]] && read -p "Confirm video driver: $VIDEO_DRIVER [Y/n]" OPTION
  719. if [[ $OPTION == n ]]; then
  720. read -p "Type your video driver [ex: sis, fbdev, modesetting]: " VIDEO_DRIVER
  721. fi
  722. } #}}}
  723. read_input() { #{{{
  724. if [[ $AUTOMATIC_MODE -eq 1 ]]; then
  725. OPTION=$1
  726. else
  727. read -p "$prompt1" OPTION
  728. fi
  729. } #}}}
  730. read_input_text() { #{{{
  731. if [[ $AUTOMATIC_MODE -eq 1 ]]; then
  732. OPTION=$2
  733. else
  734. read -p "$1 [y/N]: " OPTION
  735. echo ""
  736. fi
  737. OPTION=`echo "$OPTION" | tr '[:upper:]' '[:lower:]'`
  738. } #}}}
  739. read_input_options() { #{{{
  740. local line
  741. local packages
  742. if [[ $AUTOMATIC_MODE -eq 1 ]]; then
  743. array=("$1")
  744. else
  745. read -p "$prompt2" OPTION
  746. array=("$OPTION")
  747. fi
  748. for line in ${array[@]/,/ }; do
  749. if [[ ${line/-/} != $line ]]; then
  750. for ((i=${line%-*}; i<=${line#*-}; i++)); do
  751. packages+=($i);
  752. done
  753. else
  754. packages+=($line)
  755. fi
  756. done
  757. OPTIONS=("${packages[@]}")
  758. } #}}}
  759.  
  760.  
  761. dfspace() { #{{{{
  762. print_title_nocls "** Display Mounted Filesystems **"
  763. df -Th -t ext4 -t ext3 -t ext2 -t vfat -t reiserfs |sed '1d' > $DFOUT
  764. printf "%-10s \t %-10s \t %-5s \t %-5s \t %-5s\n" Device FS-Type Total Avail 'Mount Dir'
  765. print_dbline
  766. awk '{printf "%-10s \t %-10s \t %-5s \t %-5s \t %-5s\n", $1, $2, $3, $5, $7 }' $DFOUT
  767. rm $DFOUT
  768. pause_function
  769.  
  770.  
  771.  
  772. } #}}}
Advertisement
Add Comment
Please, Sign In to add comment