#!/usr/bin/bash # vim:ft=sh:fdm=marker:fmr={,} # archlabs installer library script file # this file is not meant to be run directly # sourcing this file in a non bash shell is not advised # shellcheck disable=2154,2034 chrun() { # run a shell command in the chroot dir $MNT arch-chroot $MNT /bin/bash -c "$1" } json() { # get a value from http://api.ipstack.com in json format using my API key # this includes: ip, geolocation, country name curl -s "http://api.ipstack.com/$2" | python3 -c "import sys, json; print(json.load(sys.stdin)['$1'])" } src() { # source a file ($1), if it fails we die with an error message . "$1" 2>/dev/null || { printf "\nFailed to source file %s\n" "$1"; die 1; } } ssd() { # returns 0 (true) when the device passed ($1) is NOT a rotational device local dev=$1 dev=${dev#/dev/} if [[ $dev =~ nvme ]]; then dev=${dev%p[0-9]*} else dev=${dev%[0-9]*} fi local i i=$(cat /sys/block/$dev/queue/rotational 2>/dev/null) [[ $i && $i -eq 0 ]] || return 1 } die() { if (( $# >= 1 )); then local exitcode=$1 else local exitcode=0 fi # reset SIGINT trap - INT tput cnorm if [[ -d $MNT ]] && command cd /; then umount_dir $MNT if (( exitcode == 127 )); then umount -l /run/archiso/bootmnt systemctl -i reboot fi fi rm -fv /tmp/.ai_* exit $exitcode } sigint() { # used to trap SIGINT and cleanly exit the program printf "\nCTRL-C caught\nCleaning up...\n" die 1 } print4() { # takes an arbitrary number of input fields and prints them out in fourths on separate lines local str="$*" if [[ ${#str} -gt $(( ${COLUMNS:-$(tput cols)} / 2 )) ]]; then q=$(awk '{print int(NF / 4)}' <<< "$str") str="$(awk '{ pkgs1=pkgs2=pkgs3=pkgs4="" for (i=1;i<'"$q"';i++) { if (i == 1) { pkgs1=$i } else { pkgs1=pkgs1" "$i } } for (i='"$q"';i<'"$((q * 2))"';i++) { pkgs2=pkgs2" "$i } for (i='"$((q * 2))"';i<'"$((q * 3))"';i++) { pkgs3=pkgs3" "$i } for (i='"$((q * 3))"';i/dev/null 2>&1 rmmod wl >/dev/null 2>&1 modprobe wl >/dev/null 2>&1 BROADCOM_WL=true printf "\nLoading wifi kernel modules please wait...\n" sleep 2 fi if ! curl -s --head 'https://www.archlinux.org/mirrorlist/all/' | sed '1q' | grep -qw '200'; then if [[ $(systemctl is-active NetworkManager) == "active" ]] && hash nmtui >/dev/null 2>&1; then tput civis nmtui-connect if ! curl -s --head 'https://www.archlinux.org/mirrorlist/all/' | sed '1q' | grep -qw '200'; then infobox "$_ErrTitle" "$_NoNetwork" 3 die 1 fi fi fi return 0 } preinstall_checks() { if ! [[ $(lsblk -o MOUNTPOINT) =~ $MNT ]]; then msgbox "$_ErrTitle" "$_ErrNoMount" SELECTED=4 return 1 elif [[ $# -eq 1 && $CONFIG_DONE != true ]]; then msgbox "$_ErrTitle" "$_ErrNoConfig" SELECTED=5 return 1 fi return 0 } echeck() { local last_exit_code=$? if (( last_exit_code == 0 )); then return 0 fi local err err="$(sed 's/[^[:print:]]//g; s/\[[0-9\;:]*\?m//g; s/==> //g; s/] ERROR:/]\nERROR:/g' "$ERR")" if [[ $err != "" ]]; then msgbox "$_ErrTitle" "\nThe command exited abnormally: $1\n\nWith the following error message:\n\n$err" else msgbox "$_ErrTitle" "\nThe command exited abnormally: $1\n\nWith the no error message.\n" fi if [[ -e $DBG && $TERM == 'linux' ]]; then more $DBG fi die 1 } debug() { set -x exec 3>| $DBG BASH_XTRACEFD=3 DEBUG=true } umount_dir() { swapoff -a if [[ -d $1 ]]; then umount -R $1 >/dev/null 2>&1 fi return 0 }