Advertisement
BSDG33KCLUB

sharedfuncs

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