logging, local installs, fix scrolling
This commit is contained in:
parent
5132ce6902
commit
67aeae126a
|
@ -0,0 +1 @@
|
||||||
|
bootstrapper.log
|
2
TODO.md
2
TODO.md
|
@ -7,3 +7,5 @@
|
||||||
## Alternatives
|
## Alternatives
|
||||||
|
|
||||||
- [ ] `xbps-alternatives pinentry -s pinentry-gnome`
|
- [ ] `xbps-alternatives pinentry -s pinentry-gnome`
|
||||||
|
- [ ] `xdg-mime default firefox.desktop x-scheme-handler/http x-scheme-handler/https text/html`
|
||||||
|
- [ ] `env -u BROWSER xdg-settings set default-web-browser firefox.desktop`
|
||||||
|
|
76
bootstrap.sh
76
bootstrap.sh
|
@ -7,6 +7,7 @@ DOTS_BRANCH="main"
|
||||||
STOW_DIR=".local/share/stow"
|
STOW_DIR=".local/share/stow"
|
||||||
DOTS_PACKAGE="dots"
|
DOTS_PACKAGE="dots"
|
||||||
CONFIG_FILE="./config.yml"
|
CONFIG_FILE="./config.yml"
|
||||||
|
LOG_FILE="bootstrap.log"
|
||||||
|
|
||||||
USER_GROUPS="wheel,floppy,audio,video,cdrom,optical,kvm,xbuilder,users,docker" # Comma separated list
|
USER_GROUPS="wheel,floppy,audio,video,cdrom,optical,kvm,xbuilder,users,docker" # Comma separated list
|
||||||
SCRIPT_DIR="$(dirname "$(readlink -f "$0")")"
|
SCRIPT_DIR="$(dirname "$(readlink -f "$0")")"
|
||||||
|
@ -20,6 +21,7 @@ RESET="$(tput sgr0)"
|
||||||
|
|
||||||
error() {
|
error() {
|
||||||
printf "%b\n" "${RED}${BOLD}${1}${RESET}" >&2
|
printf "%b\n" "${RED}${BOLD}${1}${RESET}" >&2
|
||||||
|
echo "$1" >>"$LOG_FILE"
|
||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -33,30 +35,36 @@ prompt() {
|
||||||
}
|
}
|
||||||
|
|
||||||
emphasize() {
|
emphasize() {
|
||||||
printf "%b\n" "${GREEN}${BOLD}${1}${RESET}"
|
message=$1
|
||||||
|
printf "%-$(tput cols)b\n" "${GREEN}${BOLD}${message}${RESET}"
|
||||||
|
echo "$1" >>"$LOG_FILE"
|
||||||
}
|
}
|
||||||
|
|
||||||
info() {
|
info() {
|
||||||
printf "%b\n" "${1}"
|
message=$1
|
||||||
|
printf "%-$(tput cols)b\n" "${message}"
|
||||||
|
echo "$1" >>"$LOG_FILE"
|
||||||
}
|
}
|
||||||
|
|
||||||
warn() {
|
warn() {
|
||||||
printf "%b\n" "${YELLOW}${BOLD}${1}${RESET}"
|
message=$1
|
||||||
|
printf "%-$(tput cols)b\n" "${YELLOW}${BOLD}${message}${RESET}"
|
||||||
|
echo "$1" >>"$LOG_FILE"
|
||||||
}
|
}
|
||||||
|
|
||||||
print_buffer() {
|
print_buffer() {
|
||||||
buffer_size=$1
|
buffer_size=$1
|
||||||
line_length=$2
|
trim=${2:-y} # 'y' | 'n'
|
||||||
|
line_length=$(tput cols)
|
||||||
|
|
||||||
for i in $(seq 1 "$((buffer_size))"); do
|
for i in $(seq 1 "$((buffer_size))"); do
|
||||||
# shellcheck disable=SC2016
|
|
||||||
if [ "$trim" = "y" ]; then
|
if [ "$trim" = "y" ]; then
|
||||||
template='%-${line_length}s\n'
|
template="%-${line_length}s\n"
|
||||||
else
|
else
|
||||||
template='%-${line_length}.${line_length}s\n'
|
template="%-${line_length}.${line_length}s\n"
|
||||||
fi
|
fi
|
||||||
# shellcheck disable=SC2086
|
|
||||||
eval '[ -z "${buffer'"$i"':-}" ] || {
|
eval '[ -z "${buffer'"$i"':-}" ] || {
|
||||||
printf "'"$template"'" "${buffer'$i'}"
|
printf "'"$template"'" "${buffer'"$i"'}"
|
||||||
}'
|
}'
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
@ -74,24 +82,25 @@ push_buffer() {
|
||||||
scroll() {
|
scroll() {
|
||||||
buffer_size=$1 # int
|
buffer_size=$1 # int
|
||||||
trim=${2:-y} # 'y' | 'n'
|
trim=${2:-y} # 'y' | 'n'
|
||||||
line_length=$(tput cols)
|
|
||||||
trap 'line_length=$(tput cols)' WINCH
|
|
||||||
|
|
||||||
tput civis
|
tput civis
|
||||||
while read -r line; do
|
while read -r line; do
|
||||||
push_buffer "$line" "$buffer_size"
|
push_buffer "$line" "$buffer_size"
|
||||||
|
echo "$line" >>"$LOG_FILE"
|
||||||
|
|
||||||
tput sc
|
tput sc
|
||||||
print_buffer "$buffer_size" "$line_length"
|
print_buffer "$buffer_size" "$trim"
|
||||||
tput rc
|
tput rc
|
||||||
done
|
done
|
||||||
tput cnorm
|
tput cnorm
|
||||||
|
|
||||||
|
tput sc
|
||||||
for i in $(seq 1 $((buffer_size))); do
|
for i in $(seq 1 $((buffer_size))); do
|
||||||
|
printf "%-$(tput cols)s" ""
|
||||||
eval "unset buffer$i"
|
eval "unset buffer$i"
|
||||||
done
|
done
|
||||||
print_buffer "$buffer_size" "$line_length"
|
tput rc
|
||||||
trap - WINCH
|
print_buffer "$buffer_size" "$trim"
|
||||||
}
|
}
|
||||||
|
|
||||||
check_root() {
|
check_root() {
|
||||||
|
@ -121,15 +130,24 @@ setup() {
|
||||||
install_packages() {
|
install_packages() {
|
||||||
IFS='
|
IFS='
|
||||||
'
|
'
|
||||||
|
set +e
|
||||||
for p in $(yq -c '.packages.[]' <config.yml); do
|
for p in $(yq -c '.packages.[]' <config.yml); do
|
||||||
flags=$(echo "$p" | yq -r '.command[1:].[]')
|
flags=$(echo "$p" | yq -r '.command[1:].[]')
|
||||||
packages=$(echo "$p" | yq -r '.list[]')
|
packages=$(echo "$p" | yq -r '.list[]')
|
||||||
# shellcheck disable=SC2086
|
# shellcheck disable=SC2086,2015
|
||||||
[ -n "${packages}" ] && echo $flags $packages |
|
case $(echo "$p" | yq -r '.local') in
|
||||||
xargs "$(echo "$p" | yq -r '.command[0]')"
|
true) [ -n "${packages}" ] && echo "$flags" "$packages" | sudo -i -u "$username" xargs "$(echo "$p" | yq -r '.command[0]')" || touch /tmp/bootstrapper-failed ;;
|
||||||
done | scroll 7
|
false) [ -n "${packages}" ] && echo "$flags" "$packages" | xargs "$(echo "$p" | yq -r '.command[0]')" || touch /tmp/bootstrapper-failed ;;
|
||||||
|
esac
|
||||||
|
done 2>&1 | scroll 7
|
||||||
|
set -e
|
||||||
|
|
||||||
|
if [ -f /tmp/bootstrapper-failed ]; then
|
||||||
|
warn "Failures during package installation, check logs."
|
||||||
|
rm /tmp/bootstrapper-failed
|
||||||
|
else
|
||||||
info "Done!"
|
info "Done!"
|
||||||
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
install_files() {
|
install_files() {
|
||||||
|
@ -176,7 +194,7 @@ create_user() {
|
||||||
|
|
||||||
create_directories() {
|
create_directories() {
|
||||||
#shellcheck disable=SC2016
|
#shellcheck disable=SC2016
|
||||||
directories=$(yq -c '[].directories' <${CONFIG_FILE})
|
directories=$(yq -c '.directories.[]' <${CONFIG_FILE})
|
||||||
counter=1
|
counter=1
|
||||||
num_dirs=$(echo "$directories" | wc -l)
|
num_dirs=$(echo "$directories" | wc -l)
|
||||||
|
|
||||||
|
@ -189,7 +207,7 @@ create_directories() {
|
||||||
[ -d "${user_home}/${path}" ] || sudo -u "$username" mkdir -m "${mode}" -p "${user_home}/${path}"
|
[ -d "${user_home}/${path}" ] || sudo -u "$username" mkdir -m "${mode}" -p "${user_home}/${path}"
|
||||||
|
|
||||||
counter=$((counter + 1))
|
counter=$((counter + 1))
|
||||||
done
|
done 2>&1 | scroll 7
|
||||||
|
|
||||||
info "Done!"
|
info "Done!"
|
||||||
}
|
}
|
||||||
|
@ -231,7 +249,7 @@ enable_services() {
|
||||||
for service in $services; do
|
for service in $services; do
|
||||||
info "Enabling service ${counter} of ${num_services}: ${service}"
|
info "Enabling service ${counter} of ${num_services}: ${service}"
|
||||||
[ ! -L "/var/service/${service}" ] && ln -s "/etc/sv/${service}" "/var/service/"
|
[ ! -L "/var/service/${service}" ] && ln -s "/etc/sv/${service}" "/var/service/"
|
||||||
done
|
done 2>&1 | scroll 7
|
||||||
|
|
||||||
info "Done!"
|
info "Done!"
|
||||||
}
|
}
|
||||||
|
@ -240,7 +258,7 @@ finalize() {
|
||||||
gid=$(getent passwd "$username" | cut -d ':' -f 4)
|
gid=$(getent passwd "$username" | cut -d ':' -f 4)
|
||||||
groupname=$(getent group "$gid" | cut -d ':' -f 1)
|
groupname=$(getent group "$gid" | cut -d ':' -f 1)
|
||||||
info "Setting ownership of home directories..."
|
info "Setting ownership of home directories..."
|
||||||
chown -v "$username:$groupname" -R "$user_home" 2>&1 | scroll 7
|
chown "$username:$groupname" -R "$user_home"
|
||||||
info "Done!"
|
info "Done!"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -248,6 +266,8 @@ finalize() {
|
||||||
|
|
||||||
trap 'tput cnorm; tput sgr0; exit' INT TERM EXIT
|
trap 'tput cnorm; tput sgr0; exit' INT TERM EXIT
|
||||||
|
|
||||||
|
echo >"$LOG_FILE"
|
||||||
|
|
||||||
check_root
|
check_root
|
||||||
|
|
||||||
emphasize "-- Copying Files --"
|
emphasize "-- Copying Files --"
|
||||||
|
@ -259,9 +279,6 @@ install_files
|
||||||
emphasize "-- Preparing Installation --"
|
emphasize "-- Preparing Installation --"
|
||||||
setup
|
setup
|
||||||
|
|
||||||
emphasize "-- Installing Packages --"
|
|
||||||
install_packages
|
|
||||||
|
|
||||||
username="$SUDO_USER"
|
username="$SUDO_USER"
|
||||||
if [ -z "$username" ]; then
|
if [ -z "$username" ]; then
|
||||||
emphasize "-- Creating User Account --"
|
emphasize "-- Creating User Account --"
|
||||||
|
@ -270,13 +287,16 @@ else
|
||||||
user_home=$(getent passwd "$username" | cut -d ':' -f 6)
|
user_home=$(getent passwd "$username" | cut -d ':' -f 6)
|
||||||
fi
|
fi
|
||||||
|
|
||||||
emphasize "-- Creating Standard Home Directories --"
|
|
||||||
create_directories
|
|
||||||
|
|
||||||
emphasize "-- Installing Dotfiles --"
|
emphasize "-- Installing Dotfiles --"
|
||||||
install_dotfiles
|
install_dotfiles
|
||||||
select_keymap
|
select_keymap
|
||||||
|
|
||||||
|
emphasize "-- Creating Standard Home Directories --"
|
||||||
|
create_directories
|
||||||
|
|
||||||
|
emphasize "-- Installing Packages --"
|
||||||
|
install_packages
|
||||||
|
|
||||||
emphasize "-- Enabling Services --"
|
emphasize "-- Enabling Services --"
|
||||||
enable_services
|
enable_services
|
||||||
|
|
||||||
|
|
23
config.yml
23
config.yml
|
@ -35,11 +35,9 @@ directories:
|
||||||
|
|
||||||
packages:
|
packages:
|
||||||
- command: ["xbps-install", "-y"]
|
- command: ["xbps-install", "-y"]
|
||||||
|
local: False
|
||||||
list:
|
list:
|
||||||
- 7zip
|
- 7zip
|
||||||
- ImageMagick
|
|
||||||
- NetworkManager
|
|
||||||
- Signal-Desktop
|
|
||||||
- ansible
|
- ansible
|
||||||
- apache-htpasswd
|
- apache-htpasswd
|
||||||
- arandr
|
- arandr
|
||||||
|
@ -50,8 +48,6 @@ packages:
|
||||||
- bat
|
- bat
|
||||||
- bind-utils
|
- bind-utils
|
||||||
- binutils
|
- binutils
|
||||||
- blueman
|
|
||||||
- bluez
|
|
||||||
- bottom
|
- bottom
|
||||||
- breeze-icons
|
- breeze-icons
|
||||||
- cargo
|
- cargo
|
||||||
|
@ -93,6 +89,7 @@ packages:
|
||||||
- gnupg2-scdaemon
|
- gnupg2-scdaemon
|
||||||
- gpgme
|
- gpgme
|
||||||
- htop
|
- htop
|
||||||
|
- ImageMagick
|
||||||
- jq
|
- jq
|
||||||
- just
|
- just
|
||||||
- k9s
|
- k9s
|
||||||
|
@ -115,6 +112,8 @@ packages:
|
||||||
- ncpamixer
|
- ncpamixer
|
||||||
- neofetch
|
- neofetch
|
||||||
- neovim
|
- neovim
|
||||||
|
- NetworkManager
|
||||||
|
- ngetty
|
||||||
- nmap
|
- nmap
|
||||||
- noto-fonts-cjk
|
- noto-fonts-cjk
|
||||||
- noto-fonts-emoji
|
- noto-fonts-emoji
|
||||||
|
@ -147,7 +146,8 @@ packages:
|
||||||
- ripgrep
|
- ripgrep
|
||||||
- rlwrap
|
- rlwrap
|
||||||
- rsync
|
- rsync
|
||||||
- ruby-asciidoctor
|
- ruby
|
||||||
|
- ruby-devel
|
||||||
- rust
|
- rust
|
||||||
- rust-analyzer
|
- rust-analyzer
|
||||||
- rust-src
|
- rust-src
|
||||||
|
@ -155,6 +155,7 @@ packages:
|
||||||
- seahorse
|
- seahorse
|
||||||
- shellcheck
|
- shellcheck
|
||||||
- shfmt
|
- shfmt
|
||||||
|
- Signal-Desktop
|
||||||
- simple-mtpfs
|
- simple-mtpfs
|
||||||
- smbclient
|
- smbclient
|
||||||
- socat
|
- socat
|
||||||
|
@ -209,25 +210,31 @@ packages:
|
||||||
- zsh-autosuggestions
|
- zsh-autosuggestions
|
||||||
- zsh-completions
|
- zsh-completions
|
||||||
- zsh-syntax-highlighting
|
- zsh-syntax-highlighting
|
||||||
- command: ["pnpm", "install", "-g"]
|
- command: ["pnpm", "add", "-g"]
|
||||||
|
pre: ["pnpm setup"]
|
||||||
|
local: True
|
||||||
list:
|
list:
|
||||||
- "neovim"
|
- "neovim"
|
||||||
- command: ["cargo", "install", "-j", "-2"]
|
- command: ["cargo", "install", "-j", "-2"]
|
||||||
|
local: True
|
||||||
list:
|
list:
|
||||||
- "oatmeal"
|
- "oatmeal"
|
||||||
- "gpg-tui"
|
- "gpg-tui"
|
||||||
- command: ["composer", "global", "require"]
|
- command: ["composer", "global", "require"]
|
||||||
|
local: True
|
||||||
list: []
|
list: []
|
||||||
- command: ["gem", "install"]
|
- command: ["gem", "install"]
|
||||||
|
local: False
|
||||||
list:
|
list:
|
||||||
- asciidoctor
|
- asciidoctor
|
||||||
- asciidoctor-pdf
|
- asciidoctor-pdf
|
||||||
- asciidoctor
|
|
||||||
- asciidoctor-diagram
|
- asciidoctor-diagram
|
||||||
- pygments.rb
|
- pygments.rb
|
||||||
- neovim
|
- neovim
|
||||||
- command: ["cpanm"]
|
- command: ["cpanm"]
|
||||||
|
local: False
|
||||||
list:
|
list:
|
||||||
- Neovim::Ext
|
- Neovim::Ext
|
||||||
- command: ["pipx", "--global", "install"]
|
- command: ["pipx", "--global", "install"]
|
||||||
|
local: False
|
||||||
list: []
|
list: []
|
||||||
|
|
Loading…
Reference in New Issue