blob: 195e7ee014c0224277859d758628ed087d46f318 [file] [log] [blame]
Helmuth Saatkamp7d3a37f2013-04-24 10:51:46 -03001#!/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 {{{
Helmuth Saatkamp0fdd7fa2013-04-29 22:07:07 -030024 Bold=$(tput bold)
Helmuth Saatkamp4bb9b7e2013-04-29 22:11:41 -030025 Underline=$(tput sgr 0 1)
26 Reset=$(tput sgr0)
Helmuth Saatkamp7d3a37f2013-04-24 10:51:46 -030027 # Regular Colors
Helmuth Saatkamp0fdd7fa2013-04-29 22:07:07 -030028 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)
Helmuth Saatkamp7d3a37f2013-04-24 10:51:46 -030035 # Bold
Helmuth Saatkamp0fdd7fa2013-04-29 22:07:07 -030036 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)
Helmuth Saatkamp7d3a37f2013-04-24 10:51:46 -030043 #}}}
44 # PROMPT {{{
45 prompt1="Enter your option: "
46 prompt2="Enter n° of options (ex: 1 2 3 or 1-3): "
Helmuth Saatkamp0fdd7fa2013-04-29 22:07:07 -030047 prompt3="You have to manual enter the following commands, then press ${BYellow}ctrl+d${Reset} or type ${BYellow}exit${Reset}:"
Helmuth Saatkamp7d3a37f2013-04-24 10:51:46 -030048 #}}}
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 # AUR PACKAGE
Helmuth222679e2013-08-14 10:43:39 -030065 AUR=`echo -e "(${BPurple}aur${Reset})"`
Helmuth Saatkamp7d3a37f2013-04-24 10:51:46 -030066 #CURRENT DIRECTORY
67 AUI_DIR=`pwd`
68 MOUNTPOINT="/mnt"
69 # VERBOSE MODE
70 [[ $1 == -v || $1 == --verbose ]] && VERBOSE_MODE=1 || VERBOSE_MODE=0
71 # LOG FILE
72 LOG="${AUI_DIR}/`basename ${0}`_error.log"
73 [[ -f $LOG ]] && rm -f $LOG
Helmuth2f259c52013-07-18 15:47:19 -030074 PKG_MANAGER="pacman"
75 PKG=""
Helmuth Saatkamp7d3a37f2013-04-24 10:51:46 -030076 PKG_FAIL="${AUI_DIR}/`basename ${0}`_pkg_fail_list.log"
77 [[ -f $PKG_FAIL ]] && rm -f $PKG_FAIL
78 # CONNECTION CHECK
79 XPINGS=0
80 #MISC
81 SPIN="/-\|"
Helmuth Saatkamp7d3a37f2013-04-24 10:51:46 -030082 AUTOMATIC_MODE=0
83#}}}
84#COMMON FUNCTIONS {{{
85 error_msg() { #{{{
86 local MSG="${1}"
Helmuth4a58c282013-08-14 11:30:01 -030087 echo -e "${MSG}"
Helmuth Saatkamp7d3a37f2013-04-24 10:51:46 -030088 exit 1
89 } #}}}
90 cecho() { #{{{
91 echo -e "$1"
92 echo -e "$1" >>"$LOG"
93 tput sgr0;
94 } #}}}
95 ncecho() { #{{{
96 echo -ne "$1"
97 echo -ne "$1" >>"$LOG"
98 tput sgr0
99 } #}}}
100 spinny() { #{{{
101 echo -ne "\b${SPIN:i++%${#SPIN}:1}"
102 } #}}}
103 progress() { #{{{
104 ncecho " ";
105 while true; do
106 kill -0 $pid 2> /dev/null;
107 if [[ $? == 0 ]]; then
108 spinny
109 sleep 0.25
110 else
111 ncecho "\b\b";
112 wait $pid
113 retcode=$?
Helmuth Saatkamp35f48622013-05-06 23:55:19 -0300114 echo -ne "$pid's retcode: $retcode" >> $LOG
Helmuth Saatkamp7d3a37f2013-04-24 10:51:46 -0300115 if [[ $retcode == 0 ]] || [[ $retcode == 255 ]]; then
116 cecho success
117 else
118 cecho failed
Helmuth222679e2013-08-14 10:43:39 -0300119 echo -e "$PKG" >> $PKG_FAIL
Helmuth6633a432013-08-20 15:07:18 -0300120 tail -n 15 $LOG
121 read -p "ERROR! Continue install [y/N]?" OPTION
122 [[ $OPTION != y ]] && exit 1
Helmuth Saatkamp7d3a37f2013-04-24 10:51:46 -0300123 fi
124 break
125 fi
126 done
127 } #}}}
Helmuth19c9e392013-08-30 15:08:47 -0300128 check_boot_system() { # {{{
129 if [[ "$(cat /sys/class/dmi/id/sys_vendor)" == 'Apple Inc.' ]] || [[ "$(cat /sys/class/dmi/id/sys_vendor)" == 'Apple Computer, Inc.' ]]; then
130 modprobe -r -q efivars || true # if MAC
131 else
132 modprobe -q efivars # all others
133 fi
134 if [[ -d "/sys/firmware/efi/vars/" ]]; then
135 UEFI=1
136 echo "UEFI Mode detected"
137 else
138 UEFI=0
139 echo "BIOS Mode detected"
140 fi
141 }
142 #}}}
Helmuth Saatkamp7d3a37f2013-04-24 10:51:46 -0300143 check_root() { #{{{
Helmuth9c43ed42013-08-14 11:43:53 -0300144 if [[ "$(id -u)" != "0" ]]; then
Helmuth Saatkamp7d3a37f2013-04-24 10:51:46 -0300145 error_msg "ERROR! You must execute the script as the 'root' user."
146 fi
147 } #}}}
148 check_user() { #{{{
Helmuth9c43ed42013-08-14 11:43:53 -0300149 if [[ "$(id -u)" == "0" ]]; then
Helmuth Saatkamp7d3a37f2013-04-24 10:51:46 -0300150 error_msg "ERROR! You must execute the script as a normal user."
151 fi
152 } #}}}
153 check_archlinux() { #{{{
Helmuth9c43ed42013-08-14 11:43:53 -0300154 if [[ ! -e /etc/arch-release ]]; then
Helmuth Saatkamp7d3a37f2013-04-24 10:51:46 -0300155 error_msg "ERROR! You must execute the script on Arch Linux."
156 fi
157 } #}}}
158 check_hostname() { #{{{
Helmuth9c43ed42013-08-14 11:43:53 -0300159 if [[ `echo ${HOSTNAME} | sed 's/ //g'` == "" ]]; then
Helmuth Saatkamp7d3a37f2013-04-24 10:51:46 -0300160 error_msg "ERROR! Hostname is not configured."
161 fi
162 } #}}}
Helmuth4a58c282013-08-14 11:30:01 -0300163 check_pacman_blocked() { #{{{
Helmuth9c43ed42013-08-14 11:43:53 -0300164 if [[ -f /var/lib/pacman/db.lck ]]; then
Helmuth6633a432013-08-20 15:07:18 -0300165 error_msg "ERROR! Pacman is blocked. \nIf not running remove /var/lib/pacman/db.lck."
Helmuth4a58c282013-08-14 11:30:01 -0300166 fi
167 } #}}}
Helmuth Saatkamp7d3a37f2013-04-24 10:51:46 -0300168 check_domainname() { #{{{
169 DOMAINNAME=`echo ${HOSTNAME} | cut -d'.' -f2- | sed 's/ //g'`
170
171 # Hmm, still no domain name. Keep looking...
172 if [[ "${DOMAINNAME}" == "" ]]; then
173 DOMAINNAME=`grep domain /etc/resolv.conf | sed 's/domain //g' | sed 's/ //g'`
174 fi
175
176 # OK, give up.
177 if [[ "${DOMAINNAME}" == "" ]]; then
178 error_msg "ERROR! Domain name is not configured."
179 fi
180 } #}}}
Helmuth4a58c282013-08-14 11:30:01 -0300181 check_connection(){ #{{{
Helmuth Saatkamp7d3a37f2013-04-24 10:51:46 -0300182 XPINGS=$(( $XPINGS + 1 ))
Helmuth39b52542013-08-09 12:18:52 -0300183 ping_gw() {
Helmuth2307e5d2013-08-09 12:23:42 -0300184 IP_ADDR=`ip r | grep default | cut -d ' ' -f 3`
185 [[ -z $IP_ADDR ]] && IP_ADDR="8.8.8.8"
186 ping -q -w 1 -c 1 ${IP_ADDR} > /dev/null && return 1 || return 0
Helmuth39b52542013-08-09 12:18:52 -0300187 }
Helmuth Saatkamp65b9afe2013-05-30 11:28:47 -0300188 WIRED_DEV=`ip link | grep enp | awk '{print $2}'| sed 's/://'`
Helmuth39b52542013-08-09 12:18:52 -0300189 WIRELESS_DEV=`ip link | grep wlp | awk '{print $2}'| sed 's/://'`
190 if ping_gw; then
191 print_warning "ERROR! Connection not Found."
192 print_info "Network Setup"
193 conn_type_list=("Wired Automatic" "Wired Manual" "Wireless")
194 PS3="$prompt1"
195 select CONNECTION_TYPE in "${conn_type_list[@]}"; do
196 case "$REPLY" in
197 1)
198 systemctl start dhcpcd@${WIRED_DEV}.service
199 break
200 ;;
201 2)
202 systemctl stop dhcpcd@${WIRED_DEV}.service
203 read -p "IP Address: " IP_ADDR
204 read -p "Submask: " SUBMASK
205 read -p "Gateway: " GATEWAY
206 ip link set ${WIRED_DEV} up
207 ip addr add ${IP_ADDR}/${SUBMASK} dev ${WIRED_DEV}
208 ip route add default via ${GATEWAY}
209 $EDITOR /etc/resolv.conf
210 break
211 ;;
212 3)
213 ip link set ${WIRELESS_DEV} up
214 wifi-menu ${WIRELESS_DEV}
215 break
216 ;;
217 *)
218 invalid_option
219 ;;
220 esac
221 done
222 if [[ $XPINGS -gt 2 ]]; then
223 print_warning "Can't establish connection. exiting..."
224 exit 1
Helmuth Saatkamp7d3a37f2013-04-24 10:51:46 -0300225 fi
Helmuth Saatkamp7d3a37f2013-04-24 10:51:46 -0300226 check_connection
227 fi
228 } #}}}
229 check_vga() { #{{{
230 # Determine video chipset - only Intel, ATI and nvidia are supported by this script"
Helmuth Saatkamp0fdd7fa2013-04-29 22:07:07 -0300231 ncecho " ${BBlue}[${Reset}${Bold}X${BBlue}]${Reset} Detecting video chipset "
Helmuth Saatkamp7d3a37f2013-04-24 10:51:46 -0300232 if [[ -n $(dmidecode --type 1 | grep VirtualBox) ]]; then
233 cecho Virtualbox
234 VIDEO_DRIVER="virtualbox"
Helmuthd5f02092013-09-24 09:42:23 -0300235 elif [[ -f /sys/kernel/debug/dri/0/vbios.rom ]]; then
Helmuth Saatkamp7d3a37f2013-04-24 10:51:46 -0300236 cecho Nvidia
237 read_input_text "Install NVIDIA proprietary driver" $PROPRIETARY_DRIVER
238 if [[ $OPTION == y ]]; then
239 VIDEO_DRIVER="nvidia"
240 else
241 VIDEO_DRIVER="nouveau"
242 fi
Helmuthd5f02092013-09-24 09:42:23 -0300243 elif [[ -f /sys/kernel/debug/dri/0/i915_capabilities ]]; then
Helmuth Saatkamp7d3a37f2013-04-24 10:51:46 -0300244 cecho Intel
245 VIDEO_DRIVER="intel"
Helmuthd5f02092013-09-24 09:42:23 -0300246 elif [[ -f /sys/kernel/debug/dri/0/radeon_pm_info || -f /sys/kernel/debug/dri/0/radeon_sa_info ]]; then
Helmuth Saatkamp7d3a37f2013-04-24 10:51:46 -0300247 cecho AMD/ATI
248 read_input_text "Install ATI proprietary driver" $PROPRIETARY_DRIVER
249 if [[ $OPTION == y ]]; then
250 VIDEO_DRIVER="catalyst"
251 else
252 VIDEO_DRIVER="ati"
253 fi
254 else
255 cecho VESA
256 VIDEO_DRIVER="vesa"
257 fi
258 OPTION="y"
259 [[ $VIDEO_DRIVER == intel || $VIDEO_DRIVER == vesa ]] && read -p "Confirm video driver: $VIDEO_DRIVER [Y/n]" OPTION
260 if [[ $OPTION == n ]]; then
261 read -p "Type your video driver [ex: sis, fbdev, modesetting]: " VIDEO_DRIVER
262 fi
263 } #}}}
Helmuth4a58c282013-08-14 11:30:01 -0300264 read_input() { #{{{
Helmuth Saatkamp7d3a37f2013-04-24 10:51:46 -0300265 if [[ $AUTOMATIC_MODE -eq 1 ]]; then
266 OPTION=$1
267 else
268 read -p "$prompt1" OPTION
269 fi
270 } #}}}
Helmuth4a58c282013-08-14 11:30:01 -0300271 read_input_text() { #{{{
Helmuth Saatkamp7d3a37f2013-04-24 10:51:46 -0300272 if [[ $AUTOMATIC_MODE -eq 1 ]]; then
273 OPTION=$2
274 else
275 read -p "$1 [y/N]: " OPTION
276 echo ""
277 fi
278 OPTION=`echo "$OPTION" | tr '[:upper:]' '[:lower:]'`
279 } #}}}
Helmuth4a58c282013-08-14 11:30:01 -0300280 read_input_options() { #{{{
Helmuth Saatkamp7d3a37f2013-04-24 10:51:46 -0300281 local line
282 local packages
283 if [[ $AUTOMATIC_MODE -eq 1 ]]; then
284 array=("$1")
285 else
286 read -p "$prompt2" OPTION
287 array=("$OPTION")
288 fi
289 for line in ${array[@]/,/ }; do
290 if [[ ${line/-/} != $line ]]; then
291 for ((i=${line%-*}; i<=${line#*-}; i++)); do
292 packages+=($i);
293 done
294 else
295 packages+=($line)
296 fi
297 done
298 OPTIONS=("${packages[@]}")
299 } #}}}
Helmuth4a58c282013-08-14 11:30:01 -0300300 print_line() { #{{{
Helmuth Saatkamp7d3a37f2013-04-24 10:51:46 -0300301 printf "%$(tput cols)s\n"|tr ' ' '-'
302 } #}}}
Helmuth4a58c282013-08-14 11:30:01 -0300303 print_title() { #{{{
Helmuth Saatkamp7d3a37f2013-04-24 10:51:46 -0300304 clear
305 print_line
Helmuth Saatkamp0fdd7fa2013-04-29 22:07:07 -0300306 echo -e "# ${Bold}$1${Reset}"
Helmuth Saatkamp7d3a37f2013-04-24 10:51:46 -0300307 print_line
308 echo ""
309 } #}}}
Helmuth4a58c282013-08-14 11:30:01 -0300310 print_info() { #{{{
Helmuth Saatkamp7d3a37f2013-04-24 10:51:46 -0300311 #Console width number
312 T_COLS=`tput cols`
Helmuth Saatkamp0fdd7fa2013-04-29 22:07:07 -0300313 echo -e "${Bold}$1${Reset}\n" | fold -sw $(( $T_COLS - 18 )) | sed 's/^/\t/'
Helmuth Saatkamp7d3a37f2013-04-24 10:51:46 -0300314 } #}}}
Helmuth4a58c282013-08-14 11:30:01 -0300315 print_warning() { #{{{
Helmuth Saatkamp7d3a37f2013-04-24 10:51:46 -0300316 #Console width number
317 T_COLS=`tput cols`
Helmuth Saatkamp0fdd7fa2013-04-29 22:07:07 -0300318 echo -e "${BRed}$1${Reset}\n" | fold -sw $(( $T_COLS - 1 ))
Helmuth Saatkamp7d3a37f2013-04-24 10:51:46 -0300319 } #}}}
Helmuth4a58c282013-08-14 11:30:01 -0300320 start_module() { #{{{
Helmuth Saatkamp7d3a37f2013-04-24 10:51:46 -0300321 modprobe $1
322 } #}}}
Helmuthd5f02092013-09-24 09:42:23 -0300323 add_module() { #{{{
324 #check if the number of arguments is less then 2
325 for MODULE in $1; do
326 [[ $# -lt 2 ]] && MODULE_NAME="$MODULE" || MODULE_NAME="$2";
327 echo "$MODULE" >> /etc/modules-load.d/$MODULE_NAME.conf
328 start_module "$MODULE"
329 done
330 } #}}}
331 add_repository() { #{{{
332 REPO=${1}
333 URL=${2}
334
335 CHECK_REPO=`grep -F "${REPO}" /etc/pacman.conf`
336 if [[ -z $CHECK_REPO ]]; then
337 echo -e "\n[${REPO}]\nSigLevel = Optional TrustAll\nServer = ${URL}" >> /etc/pacman.conf
338 system_update
339 fi
340 } #}}}
341 add_line() { #{{{
342 ADD_LINE=${1}
343 FILEPATH=${2}
344
345 CHECK_LINE=`grep -F "${ADD_LINE}" ${FILEPATH}`
346 [[ -z $CHECK_LINE ]] && echo "${ADD_LINE}" >> ${FILEPATH}
347 } #}}}
348 replace_line() { #{{{
Helmuth Saatkamp7d3a37f2013-04-24 10:51:46 -0300349 SEARCH=${1}
350 REPLACE=${2}
351 FILEPATH=${3}
352 FILEBASE=`basename ${3}`
353
354 sed -e "s/${SEARCH}/${REPLACE}/" ${FILEPATH} > /tmp/${FILEBASE} 2>"$LOG"
355 if [[ ${?} -eq 0 ]]; then
356 mv /tmp/${FILEBASE} ${FILEPATH}
357 else
358 cecho "failed: ${SEARCH} - ${FILEPATH}"
359 fi
360 } #}}}
Helmuth Saatkamp7d3a37f2013-04-24 10:51:46 -0300361 update_early_modules() { #{{{
362 local NEW_MODULE=${1}
363 local OLD_ARRAY=`egrep ^MODULES= /etc/mkinitcpio.conf`
364
365 if [[ -n ${NEW_MODULE} ]]; then
366 # Determine if the new module is already listed.
367 _EXISTS=`echo ${OLD_ARRAY} | grep ${NEW_MODULE}`
368 if [ $? -eq 1 ]; then
369
370 source /etc/mkinitcpio.conf
371 if [[ -z ${MODULES} ]]; then
372 NEW_MODULES="${NEW_MODULE}"
373 else
374 NEW_MODULES="${MODULES} ${NEW_MODULE}"
375 fi
Helmuthd5f02092013-09-24 09:42:23 -0300376 replace_line "MODULES=\"${MODULES}\"" "MODULES=\"${NEW_MODULES}\"" /etc/mkinitcpio.conf
Helmuth Saatkamp0fdd7fa2013-04-29 22:07:07 -0300377 ncecho " ${BBlue}[${Reset}${Bold}X${BBlue}]${Reset} Rebuilding init "
Helmuth Saatkamp7d3a37f2013-04-24 10:51:46 -0300378 mkinitcpio -p linux >>"$LOG" 2>&1 &
379 pid=$!;progress $pid
380 fi
381 fi
382 } #}}}
Helmuth4a58c282013-08-14 11:30:01 -0300383 is_package_installed() { #{{{
Helmuth Saatkamp7d3a37f2013-04-24 10:51:46 -0300384 #check if a package is already installed
385 for PKG in $1; do
386 pacman -Q $PKG &> /dev/null && return 0;
387 done
388 return 1
389 } #}}}
Helmuth4a58c282013-08-14 11:30:01 -0300390 checkbox() { #{{{
Helmuth Saatkamp7d3a37f2013-04-24 10:51:46 -0300391 #display [X] or [ ]
Helmuth Saatkamp0fdd7fa2013-04-29 22:07:07 -0300392 [[ "$1" -eq 1 ]] && echo -e "${BBlue}[${Reset}${Bold}X${BBlue}]${Reset}" || echo -e "${BBlue}[ ${BBlue}]${Reset}";
Helmuth Saatkamp7d3a37f2013-04-24 10:51:46 -0300393 } #}}}
Helmuth4a58c282013-08-14 11:30:01 -0300394 checkbox_package() { #{{{
Helmuth Saatkamp7d3a37f2013-04-24 10:51:46 -0300395 #check if [X] or [ ]
396 is_package_installed "$1" && checkbox 1 || checkbox 0
397 } #}}}
Helmuth4a58c282013-08-14 11:30:01 -0300398 aui_download_packages() { #{{{
Helmuth Saatkamp7d3a37f2013-04-24 10:51:46 -0300399 for PKG in $1; do
400 #exec command as user instead of root
401 su - ${USER_NAME} -c "
402 [[ ! -d aui_packages ]] && mkdir aui_packages
403 cd aui_packages
404 curl -o $PKG.tar.gz https://aur.archlinux.org/packages/${PKG:0:2}/$PKG/$PKG.tar.gz
405 tar zxvf $PKG.tar.gz
406 rm $PKG.tar.gz
407 cd $PKG
Helmuth4a58c282013-08-14 11:30:01 -0300408 makepkg -csi --noconfirm
Helmuth Saatkamp7d3a37f2013-04-24 10:51:46 -0300409 "
410 done
411 } #}}}
Helmuth4a58c282013-08-14 11:30:01 -0300412 aur_package_install() { #{{{
Helmuth1712c342013-09-19 11:22:46 -0300413 su - ${USER_NAME} -c "sudo -v"
Helmuth Saatkamp7d3a37f2013-04-24 10:51:46 -0300414 #install package from aur
415 for PKG in $1; do
416 if ! is_package_installed "${PKG}" ; then
417 if [[ $AUTOMATIC_MODE -eq 1 ]]; then
Helmuth Saatkamp0fdd7fa2013-04-29 22:07:07 -0300418 ncecho " ${BBlue}[${Reset}${Bold}X${BBlue}]${Reset} Installing ${AUR} ${Bold}${PKG}${Reset} "
Helmuth2f259c52013-07-18 15:47:19 -0300419 su - ${USER_NAME} -c "${AUR_PKG_MANAGER} --noconfirm -S ${PKG}" >>"$LOG" 2>&1 &
Helmuth Saatkamp7d3a37f2013-04-24 10:51:46 -0300420 pid=$!;progress $pid
421 else
Helmuth2f259c52013-07-18 15:47:19 -0300422 su - ${USER_NAME} -c "${AUR_PKG_MANAGER} -S ${PKG}"
Helmuth Saatkamp7d3a37f2013-04-24 10:51:46 -0300423 fi
424 else
425 if [[ $VERBOSE_MODE -eq 0 ]]; then
Helmuth Saatkamp0fdd7fa2013-04-29 22:07:07 -0300426 cecho " ${BBlue}[${Reset}${Bold}X${BBlue}]${Reset} Installing ${AUR} ${Bold}${PKG}${Reset} success"
Helmuth Saatkamp7d3a37f2013-04-24 10:51:46 -0300427 else
428 echo -e "Warning: ${PKG} is up to date --skipping"
429 fi
430 fi
431 done
432 } #}}}
Helmuth4a58c282013-08-14 11:30:01 -0300433 package_install() { #{{{
Helmuth Saatkamp7d3a37f2013-04-24 10:51:46 -0300434 #install packages using pacman
435 if [[ $AUTOMATIC_MODE -eq 1 || $VERBOSE_MODE -eq 0 ]]; then
436 for PKG in ${1}; do
437 PKG_REPO=`pacman -Sp --print-format %r ${PKG} | uniq | sed '1!d'`
438 case $PKG_REPO in
439 "core")
Helmuth Saatkamp0fdd7fa2013-04-29 22:07:07 -0300440 PKG_REPO="${BRed}${PKG_REPO}${Reset}"
Helmuth Saatkamp7d3a37f2013-04-24 10:51:46 -0300441 ;;
442 "extra")
Helmuth Saatkamp0fdd7fa2013-04-29 22:07:07 -0300443 PKG_REPO="${BYellow}${PKG_REPO}${Reset}"
Helmuth Saatkamp7d3a37f2013-04-24 10:51:46 -0300444 ;;
445 "community")
Helmuth Saatkamp0fdd7fa2013-04-29 22:07:07 -0300446 PKG_REPO="${BGreen}${PKG_REPO}${Reset}"
Helmuth Saatkamp7d3a37f2013-04-24 10:51:46 -0300447 ;;
448 "multilib")
Helmuth Saatkamp0fdd7fa2013-04-29 22:07:07 -0300449 PKG_REPO="${BCyan}${PKG_REPO}${Reset}"
Helmuth Saatkamp7d3a37f2013-04-24 10:51:46 -0300450 ;;
451 esac
Helmuth03e10fa2013-09-19 14:12:27 -0300452 if ! is_package_installed "${PKG}" ; then
Helmuth Saatkamp0fdd7fa2013-04-29 22:07:07 -0300453 ncecho " ${BBlue}[${Reset}${Bold}X${BBlue}]${Reset} Installing (${PKG_REPO}) ${Bold}${PKG}${Reset} "
Helmuth2f259c52013-07-18 15:47:19 -0300454 $PKG_MANAGER -S --noconfirm --needed ${PKG} >>"$LOG" 2>&1 &
Helmuth Saatkamp7d3a37f2013-04-24 10:51:46 -0300455 pid=$!;progress $pid
456 else
Helmuth Saatkamp0fdd7fa2013-04-29 22:07:07 -0300457 cecho " ${BBlue}[${Reset}${Bold}X${BBlue}]${Reset} Installing (${PKG_REPO}) ${Bold}${PKG}${Reset} exists "
Helmuth Saatkamp7d3a37f2013-04-24 10:51:46 -0300458 fi
459 done
460 else
Helmuth9c8b80f2013-09-19 08:50:41 -0300461 $PKG_MANAGER -S --needed ${1}
Helmuth Saatkamp7d3a37f2013-04-24 10:51:46 -0300462 fi
463 } #}}}
Helmuth4a58c282013-08-14 11:30:01 -0300464 package_remove() { #{{{
Helmuth Saatkamp7d3a37f2013-04-24 10:51:46 -0300465 #remove package
466 for PKG in ${1}; do
467 if is_package_installed "${PKG}" ; then
468 if [[ $AUTOMATIC_MODE -eq 1 || $VERBOSE_MODE -eq 0 ]]; then
Helmuth Saatkamp0fdd7fa2013-04-29 22:07:07 -0300469 ncecho " ${BBlue}[${Reset}${Bold}X${BBlue}]${Reset} Removing ${Bold}${PKG}${Reset} "
Helmuth Saatkamp7d3a37f2013-04-24 10:51:46 -0300470 pacman -Rcsn --noconfirm ${PKG} >>"$LOG" 2>&1 &
471 pid=$!;progress $pid
472 else
473 pacman -Rcsn ${PKG}
474 fi
475 fi
476 done
477 } #}}}
Helmuth4a58c282013-08-14 11:30:01 -0300478 system_upgrade() { #{{{
Helmuth1d4e6712013-08-14 11:04:23 -0300479 local MODIFY=`stat /var/lib/pacman/sync | egrep ^Modify | cut -d':' -f2 | cut -d' ' -f2`
480 local TODAY=`date +%Y-%m-%d`
Helmuth6633a432013-08-20 15:07:18 -0300481 if [[ ${MODIFY} != ${TODAY} ]]; then
482 pacman -Syu ${1}
Helmuth1d4e6712013-08-14 11:04:23 -0300483 fi
Helmuth Saatkamp7d3a37f2013-04-24 10:51:46 -0300484 } #}}}
Helmuth4a58c282013-08-14 11:30:01 -0300485 system_update() { #{{{
Helmuthdf52c6e2013-08-15 14:06:49 -0300486 if [[ $VERBOSE_MODE -eq 0 ]]; then
487 ncecho " ${BBlue}[${Reset}${Bold}X${BBlue}]${Reset} Updating packages "
Helmuthd5f02092013-09-24 09:42:23 -0300488 $PKG_MANAGER -Syy >>"$LOG" 2>&1 &
Helmuthdf52c6e2013-08-15 14:06:49 -0300489 pid=$!;progress $pid
490 else
Helmuthd5f02092013-09-24 09:42:23 -0300491 $PKG_MANAGER -Syy $1
Helmuth Saatkamp7d3a37f2013-04-24 10:51:46 -0300492 fi
493 } #}}}
Helmuth4a58c282013-08-14 11:30:01 -0300494 npm_install() { #{{{
Helmuthfdff0cb2013-08-12 14:41:31 -0300495 #install packages using pacman
496 npm install -g $1
497 } #}}}
Helmuth4a58c282013-08-14 11:30:01 -0300498 contains_element() { #{{{
Helmuth Saatkamp7d3a37f2013-04-24 10:51:46 -0300499 #check if an element exist in a string
500 for e in "${@:2}"; do [[ $e == $1 ]] && break; done;
501 } #}}}
Helmuth4a58c282013-08-14 11:30:01 -0300502 config_xinitrc() { #{{{
Helmuth Saatkamp7d3a37f2013-04-24 10:51:46 -0300503 #create a xinitrc file in home user directory
504 cp -fv /etc/skel/.xinitrc /home/${USER_NAME}/
505 echo -e "exec $1" >> /home/${USER_NAME}/.xinitrc
506 chown -R ${USER_NAME}:users /home/${USER_NAME}/.xinitrc
507 } #}}}
Helmuth4a58c282013-08-14 11:30:01 -0300508 invalid_option() { #{{{
Helmuth Saatkamp7d3a37f2013-04-24 10:51:46 -0300509 print_line
510 echo "Invalid option. Try another one."
511 pause_function
512 } #}}}
Helmuth4a58c282013-08-14 11:30:01 -0300513 pause_function() { #{{{
Helmuth Saatkamp7d3a37f2013-04-24 10:51:46 -0300514 print_line
515 if [[ $AUTOMATIC_MODE -eq 0 ]]; then
516 read -e -sn 1 -p "Press any key to continue..."
517 fi
518 } #}}}
Helmuth4a58c282013-08-14 11:30:01 -0300519 menu_item() { #{{{
Helmuth Saatkamp7d3a37f2013-04-24 10:51:46 -0300520 #check if the number of arguments is less then 2
521 [[ $# -lt 2 ]] && PACKAGE_NAME="$1" || PACKAGE_NAME="$2";
522 #list of chars to remove from the package name
523 CHARS_TO_REMOVE=("Ttf-" "-bzr" "-hg" "-svn" "-git" "-stable" "-icon-theme" "Gnome-shell-theme-" "Gnome-shell-extension-");
524 #remove chars from package name
525 for CHARS in ${CHARS_TO_REMOVE[@]}; do PACKAGE_NAME=`echo ${PACKAGE_NAME^} | sed 's/'$CHARS'//'`; done
526 #display checkbox and package name
Helmuth Saatkamp0fdd7fa2013-04-29 22:07:07 -0300527 echo -e "$(checkbox_package "$1") ${Bold}$PACKAGE_NAME${Reset}"
Helmuth Saatkamp7d3a37f2013-04-24 10:51:46 -0300528 } #}}}
Helmuth4a58c282013-08-14 11:30:01 -0300529 mainmenu_item() { #{{{
Helmuth Saatkamp0fdd7fa2013-04-29 22:07:07 -0300530 echo -e "$(checkbox "$1") ${Bold}$2${Reset}"
Helmuth Saatkamp7d3a37f2013-04-24 10:51:46 -0300531 } #}}}
532 elihw() { #{{{
533 [[ $OPT == b || $OPT == d ]] && break;
534 } #}}}
535 add_user_to_group() { #{{{
536 local _USER=${1}
537 local _GROUP=${2}
538
539 if [[ -z ${_GROUP} ]]; then
540 error_msg "ERROR! 'add_user_to_group' was not given enough parameters."
541 fi
542
Helmuth Saatkamp0fdd7fa2013-04-29 22:07:07 -0300543 ncecho " ${BBlue}[${Reset}${Bold}X${BBlue}]${Reset} Adding ${Bold}${_USER}${Reset} to ${Bold}${_GROUP}${Reset} "
Helmuth Saatkamp7d3a37f2013-04-24 10:51:46 -0300544 gpasswd -a ${_USER} ${_GROUP} >>"$LOG" 2>&1 &
545 pid=$!;progress $pid
546 } #}}}
Helmuth4a58c282013-08-14 11:30:01 -0300547 system_ctl() { #{{{
Helmuth1d4e6712013-08-14 11:04:23 -0300548 local ACTION=${1}
549 local OBJECT=${2}
550 ncecho " ${BBlue}[${Reset}${Bold}X${BBlue}]${Reset} systemctl ${ACTION} ${OBJECT} "
551 systemctl ${ACTION} ${OBJECT} >> "$LOG" 2>&1
552 pid=$!;progress $pid
553 }
554 #}}}
Helmuth4a58c282013-08-14 11:30:01 -0300555 arch_chroot() { #{{{
Helmuth Saatkamp7d3a37f2013-04-24 10:51:46 -0300556 arch-chroot $MOUNTPOINT /bin/bash -c "${1}"
557 }
558 #}}}
Helmuth4a58c282013-08-14 11:30:01 -0300559 setkeymap() { #{{{
Helmuth Saatkamp7d3a37f2013-04-24 10:51:46 -0300560 local keymaps=(`localectl list-keymaps`)
561 PS3="(shift+pgup/pgdown) $prompt1"
562 echo "Select keymap:"
563 select KEYMAP in "${keymaps[@]}"; do
564 if contains_element "$KEYMAP" "${keymaps[@]}"; then
Helmuth Saatkamp93305182013-06-03 15:13:45 -0300565 break
Helmuth Saatkamp7d3a37f2013-04-24 10:51:46 -0300566 else
567 invalid_option
568 fi
Helmuth Saatkamp7d3a37f2013-04-24 10:51:46 -0300569 done
570 }
571 #}}}
Helmuth4a58c282013-08-14 11:30:01 -0300572 setlocale() { #{{{
Helmuth Saatkamp7d3a37f2013-04-24 10:51:46 -0300573 local locale_list=(`cat /etc/locale.gen | grep _ | sed 's/\..*$//' | sed '/@/d' | awk '{print $1}' | uniq | sed 's/#//g'`);
574 PS3="$prompt1"
575 echo "Select locale:"
576 select LOCALE in "${locale_list[@]}"; do
577 if contains_element "$LOCALE" "${locale_list[@]}"; then
578 LOCALE_8859="${LOCALE} ISO-8859"
579 LOCALE_UTF8="${LOCALE}.UTF-8"
580 break
581 else
582 invalid_option
583 fi
584 done
585 }
586 #}}}
Helmuth4a58c282013-08-14 11:30:01 -0300587 settimezone() { #{{{
Helmuth Saatkamp7d3a37f2013-04-24 10:51:46 -0300588 local zone=(`timedatectl list-timezones | sed 's/\/.*$//' | uniq`);
589 PS3="$prompt1"
590 echo "Select zone:"
591 select ZONE in "${zone[@]}"; do
592 if contains_element "$ZONE" "${zone[@]}"; then
593 local subzone=(`timedatectl list-timezones | grep ${ZONE} | sed 's/^.*\///'`)
594 PS3="$prompt1"
595 echo "Select subzone:"
596 select SUBZONE in "${subzone[@]}"; do
597 if contains_element "$SUBZONE" "${subzone[@]}"; then
598 break
599 else
600 invalid_option
601 fi
602 done
603 break
604 else
605 invalid_option
606 fi
607 done
608 } #}}}
609#}}}