debian: Add info output (and be more verbose)

This makes it easier to follow what is happening while the script is
running.
This commit is contained in:
Fernando Schauenburg 2024-03-20 22:44:18 +01:00
parent ceffaf3737
commit 5e57c1351e

View file

@ -13,12 +13,14 @@ setup_colors() {
sgr0="$(printf '\033[0m')" sgr0="$(printf '\033[0m')"
bold="$(printf '\033[1m')" bold="$(printf '\033[1m')"
red="$(printf '\033[31m')" red="$(printf '\033[31m')"
green="$(printf '\033[32m')"
yellow="$(printf '\033[33m')" yellow="$(printf '\033[33m')"
blue="$(printf '\033[34m')" blue="$(printf '\033[34m')"
else else
sgr0='' sgr0=''
bold='' bold=''
red='' red=''
green=''
yellow='' yellow=''
blue='' blue=''
fi fi
@ -55,6 +57,10 @@ error() {
exit 1 exit 1
} }
info() {
printf "${green}->${sgr0} %s\n" "$1"
}
title() { title() {
echo "${blue}${bold}=> ${1}${sgr0}" echo "${blue}${bold}=> ${1}${sgr0}"
} }
@ -66,7 +72,10 @@ skipped() {
apt_install() { apt_install() {
title "Install APT packages" title "Install APT packages"
info "Updating package database"
${APT} update ${APT} update
info "Installing APT packages"
${APT} install -y \ ${APT} install -y \
apt-file \ apt-file \
ascii \ ascii \
@ -81,11 +90,13 @@ apt_install() {
git \ git \
git-crypt \ git-crypt \
gnupg \ gnupg \
help2man \
htop \ htop \
jq \ jq \
make \ make \
man-db \ man-db \
nodejs \ nodejs \
pandoc \
pkg-config \ pkg-config \
psmisc \ psmisc \
python3 \ python3 \
@ -99,6 +110,8 @@ apt_install() {
tmux \ tmux \
unzip \ unzip \
zsh zsh
info "Updating apt-file database"
${APT_FILE} update ${APT_FILE} update
} }
@ -123,17 +136,19 @@ ensure_usr_bin_fd() {
ensure_usr_local_man_manN() { ensure_usr_local_man_manN() {
title "Make sure we have directories for all man page sections" title "Make sure we have directories for all man page sections"
${MKDIR} -vp $(seq -f '/usr/local/man/man%.0f' 9) for dir in $(seq -f '/usr/local/man/man%.0f' 9); do
${MKDIR} -vp "${dir}"
done
} }
user_setup() { user_setup() {
title "Setup user: $1" title "Setup user: $1"
if user_exists "$1"; then if user_exists "$1"; then
echo "User $1 exists. Updating..." info "User $1 exists. Updating..."
user_update "$1" user_update "$1"
else else
echo "Creating user $1..." info "Creating user $1"
user_new "$1" user_new "$1"
fi fi
@ -162,13 +177,21 @@ user_new() {
# Add user $1 to the `staff` group... # Add user $1 to the `staff` group...
# ...and change shell to `zsh` and get rid of bash files. # ...and change shell to `zsh` and get rid of bash files.
user_update() { user_update() {
info "Adding $1 to group staff"
${USERMOD} -aG staff "$1" ${USERMOD} -aG staff "$1"
info "Changing login shell to zsh"
${CHSH} -s /bin/zsh "$1" ${CHSH} -s /bin/zsh "$1"
${RM} -vf "$(printf "/home/$1/%s " .bash_history .bash_logout .bashrc .profile)"
info "Removing bash leftover files"
for f in .bash_history .bash_logout .bashrc .profile; do
${RM} -vf "/home/${1}/${f}"
done
} }
# Allow `sudo` without password for user $1. # Allow `sudo` without password for user $1.
user_allow_sudo_nopasswd() { user_allow_sudo_nopasswd() {
info "Enabling sudo without password for ${1}"
contents="$1 ALL=(ALL:ALL) NOPASSWD:ALL" contents="$1 ALL=(ALL:ALL) NOPASSWD:ALL"
sudoers_file="/etc/sudoers.d/${1}_nopasswd" sudoers_file="/etc/sudoers.d/${1}_nopasswd"
if is_dry_run; then if is_dry_run; then
@ -186,8 +209,10 @@ deploy_dotfiles() {
if [ -d "${dotfiles_dir}" ]; then if [ -d "${dotfiles_dir}" ]; then
skipped "${dotfiles_dir} exists" skipped "${dotfiles_dir} exists"
else else
info "Cloning dotfiles"
${SU} "$1" -c "git clone $2 ${dotfiles_dir}" ${SU} "$1" -c "git clone $2 ${dotfiles_dir}"
( (
info "Installing dotfiles"
${CD} "${dotfiles_dir}" ${CD} "${dotfiles_dir}"
${SU} "$1" -c "./install.sh -y" ${SU} "$1" -c "./install.sh -y"
) )