optimizations (mostly for consecutive runs)
This commit is contained in:
parent
543072e9e0
commit
706e845456
62
bootstrap.sh
62
bootstrap.sh
|
@ -21,8 +21,7 @@ error() {
|
||||||
|
|
||||||
prompt() {
|
prompt() {
|
||||||
message=$1
|
message=$1
|
||||||
tty=$2
|
printf "%b" "${BLUE}${message}${RESET}" >"$(tty)"
|
||||||
printf "%b" "${BLUE}${message}${RESET}" >"$tty"
|
|
||||||
# shellcheck disable=SC3037,SC2046
|
# shellcheck disable=SC3037,SC2046
|
||||||
read -r x
|
read -r x
|
||||||
echo "$x"
|
echo "$x"
|
||||||
|
@ -70,36 +69,29 @@ check_root() {
|
||||||
setup() {
|
setup() {
|
||||||
tput sc
|
tput sc
|
||||||
info "Synchronizing XBPS index..."
|
info "Synchronizing XBPS index..."
|
||||||
xbps-install -S >/dev/null 2>&1 || error "Failed to synchronize XBPS index! (Try manually running xbps-install -S)"
|
xbps-install -S >/dev/null 2>&1 || error "Failed to synchronize XBPS index! (Try manually running xbps-install -S)"
|
||||||
tput rc
|
tput rc
|
||||||
tput el
|
tput el
|
||||||
|
|
||||||
info "Installing ntp..."
|
if ! xbps-query ntp >/dev/null 2>&1; then
|
||||||
xbps-install -y ntp >/dev/null 2>&1
|
info "Installing ntp..."
|
||||||
tput rc
|
xbps-install -y ntp >/dev/null 2>&1
|
||||||
tput el
|
tput rc
|
||||||
|
tput el
|
||||||
|
|
||||||
info "Synchronizing time..."
|
info "Synchronizing time..."
|
||||||
ntpdate "pool.ntp.org" >/dev/null 2>&1 || warn "Failed to synchronize time!"
|
ntpdate "pool.ntp.org" >/dev/null 2>&1 || warn "Failed to synchronize time!"
|
||||||
tput rc
|
tput rc
|
||||||
tput el
|
tput el
|
||||||
|
fi
|
||||||
|
|
||||||
info "Done!"
|
info "Done!"
|
||||||
}
|
}
|
||||||
|
|
||||||
install_packages() {
|
install_packages() {
|
||||||
failed_packages=""
|
#shellcheck disable=SC2016,SC2046
|
||||||
#shellcheck disable=SC2016
|
xbps-install $(xargs -a "$1") 2>&1 | grep -q "not found in repository pool." && error "Invalid package in packages.txt, run validate.sh"
|
||||||
_loop_wrapper "$1" \
|
info "Done!"
|
||||||
'Installing ${x}' \
|
|
||||||
'xbps-install -y "$x" >/dev/null 2>&1 || failed_packages="${failed_packages} ${x}"'
|
|
||||||
if [ -n "$failed_packages" ]; then
|
|
||||||
tput rc
|
|
||||||
tput el
|
|
||||||
warn "Failed to install:${failed_packages}"
|
|
||||||
else
|
|
||||||
info "Done!"
|
|
||||||
fi
|
|
||||||
command -v git 1>/dev/null 2>&1 || error "git isn't installed even though it should be!"
|
command -v git 1>/dev/null 2>&1 || error "git isn't installed even though it should be!"
|
||||||
command -v stow 1>/dev/null 2>&1 || error "stow isn't installed even though it should be!"
|
command -v stow 1>/dev/null 2>&1 || error "stow isn't installed even though it should be!"
|
||||||
}
|
}
|
||||||
|
@ -116,16 +108,17 @@ create_user() {
|
||||||
tput sc
|
tput sc
|
||||||
|
|
||||||
failed=false
|
failed=false
|
||||||
while ! echo "$username" | grep -q "[a-z_][a-z0-9_-]*$"; do
|
while ! echo "$username" | grep "^[a-z_][a-z0-9_-]*$" | grep -qv "root"; do
|
||||||
$failed && warn "Invalid username, try again!"
|
$failed && warn "Invalid username, try again!"
|
||||||
username=$(prompt "Input Username: " "$(tty)")
|
username=$(prompt "Input Username: ")
|
||||||
failed=true
|
failed=true
|
||||||
tput rc
|
tput rc
|
||||||
tput el
|
tput el
|
||||||
done
|
done
|
||||||
|
|
||||||
if id -u "$username" >/dev/null 2>&1; then
|
if id -u "$username" >/dev/null 2>&1; then
|
||||||
warn "User \"$username\" already exists! Skipping user creation!"
|
warn "User \"$username\" already exists, Skipping user creation!"
|
||||||
|
usermod -aG "$USER_GROUPS" "$username"
|
||||||
else
|
else
|
||||||
info "Creating user \"$username\" with the following groups: \"$USER_GROUPS\"..."
|
info "Creating user \"$username\" with the following groups: \"$USER_GROUPS\"..."
|
||||||
useradd -m -G "$USER_GROUPS" "$username"
|
useradd -m -G "$USER_GROUPS" "$username"
|
||||||
|
@ -134,10 +127,10 @@ create_user() {
|
||||||
$failed && warn "Passwords do not match or are empty, try again!"
|
$failed && warn "Passwords do not match or are empty, try again!"
|
||||||
tput rc
|
tput rc
|
||||||
tput el
|
tput el
|
||||||
pass1=$(prompt "Input Password: " "$(tty)")
|
pass1=$(prompt "Input Password: ")
|
||||||
tput rc
|
tput rc
|
||||||
tput el
|
tput el
|
||||||
pass2=$(prompt "Repeat Password: " "$(tty)")
|
pass2=$(prompt "Repeat Password: ")
|
||||||
tput rc
|
tput rc
|
||||||
tput el
|
tput el
|
||||||
failed=true
|
failed=true
|
||||||
|
@ -190,8 +183,8 @@ install_dotfiles() {
|
||||||
}
|
}
|
||||||
|
|
||||||
select_keymap() {
|
select_keymap() {
|
||||||
|
[ -L "${user_home}/.local/share/xkb/compiled/default" ] && return
|
||||||
map="$(find "${user_home}/.local/share/xkb/compiled" -type f -printf "%f\n" | fzf --header="Select a default keymap:")"
|
map="$(find "${user_home}/.local/share/xkb/compiled" -type f -printf "%f\n" | fzf --header="Select a default keymap:")"
|
||||||
rm "${user_home}/.local/share/xkb/compiled/default"
|
|
||||||
ln -s "$map" "${user_home}/.local/share/xkb/compiled/default"
|
ln -s "$map" "${user_home}/.local/share/xkb/compiled/default"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -199,7 +192,7 @@ enable_services() {
|
||||||
tput sc
|
tput sc
|
||||||
info "Installing user service service..."
|
info "Installing user service service..."
|
||||||
target="/etc/sv/runsvdir-${username}"
|
target="/etc/sv/runsvdir-${username}"
|
||||||
mkdir -p "$(dirname "$target")"
|
mkdir -p "$target"
|
||||||
sed "s/<U>/$username/" "${SCRIPT_DIR}/runsvdir-user" >"$target/run"
|
sed "s/<U>/$username/" "${SCRIPT_DIR}/runsvdir-user" >"$target/run"
|
||||||
[ ! -L "/var/service/$(basename "$target")" ] &&
|
[ ! -L "/var/service/$(basename "$target")" ] &&
|
||||||
ln -s "$target" "/var/service/"
|
ln -s "$target" "/var/service/"
|
||||||
|
@ -233,8 +226,13 @@ setup
|
||||||
emphasize "-- Installing Packages --"
|
emphasize "-- Installing Packages --"
|
||||||
install_packages "${SCRIPT_DIR}/packages.txt"
|
install_packages "${SCRIPT_DIR}/packages.txt"
|
||||||
|
|
||||||
emphasize "-- Creating User Account --"
|
username="$SUDO_USER"
|
||||||
create_user
|
if [ -z "$username" ]; then
|
||||||
|
emphasize "-- Creating User Account --"
|
||||||
|
create_user
|
||||||
|
else
|
||||||
|
user_home=$(getent passwd "$username" | cut -d ':' -f 6)
|
||||||
|
fi
|
||||||
|
|
||||||
emphasize "-- Creating Standard Home Directories --"
|
emphasize "-- Creating Standard Home Directories --"
|
||||||
create_directories "${SCRIPT_DIR}/directories.txt"
|
create_directories "${SCRIPT_DIR}/directories.txt"
|
||||||
|
|
|
@ -0,0 +1,20 @@
|
||||||
|
#!/bin/sh
|
||||||
|
info() {
|
||||||
|
printf "%b\n" "${1}"
|
||||||
|
}
|
||||||
|
|
||||||
|
SCRIPT_DIR="$(dirname "$(readlink -f "$0")")"
|
||||||
|
skip_regex="^(#.*)?$"
|
||||||
|
|
||||||
|
total=$(grep -cvP "$skip_regex" "${SCRIPT_DIR}/packages.txt")
|
||||||
|
tput sc
|
||||||
|
while read -r package; do
|
||||||
|
echo "$package" | grep -qvP "$skip_regex" || continue
|
||||||
|
n=$((n + 1))
|
||||||
|
eval "info \"(${n}/${total}) Validating $package\""
|
||||||
|
xbps-query -R "$package" >/dev/null 2>&1 || failed_packages="${failed_packages} ${package}"
|
||||||
|
tput rc
|
||||||
|
tput el
|
||||||
|
done <"${SCRIPT_DIR}/packages.txt"
|
||||||
|
|
||||||
|
echo "Failed packages:${failed_packages}"
|
Loading…
Reference in New Issue