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')"
bold="$(printf '\033[1m')"
red="$(printf '\033[31m')"
green="$(printf '\033[32m')"
yellow="$(printf '\033[33m')"
blue="$(printf '\033[34m')"
else
sgr0=''
bold=''
red=''
green=''
yellow=''
blue=''
fi
@ -55,6 +57,10 @@ error() {
exit 1
}
info() {
printf "${green}->${sgr0} %s\n" "$1"
}
title() {
echo "${blue}${bold}=> ${1}${sgr0}"
}
@ -66,7 +72,10 @@ skipped() {
apt_install() {
title "Install APT packages"
info "Updating package database"
${APT} update
info "Installing APT packages"
${APT} install -y \
apt-file \
ascii \
@ -81,11 +90,13 @@ apt_install() {
git \
git-crypt \
gnupg \
help2man \
htop \
jq \
make \
man-db \
nodejs \
pandoc \
pkg-config \
psmisc \
python3 \
@ -99,6 +110,8 @@ apt_install() {
tmux \
unzip \
zsh
info "Updating apt-file database"
${APT_FILE} update
}
@ -123,17 +136,19 @@ ensure_usr_bin_fd() {
ensure_usr_local_man_manN() {
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() {
title "Setup user: $1"
if user_exists "$1"; then
echo "User $1 exists. Updating..."
info "User $1 exists. Updating..."
user_update "$1"
else
echo "Creating user $1..."
info "Creating user $1"
user_new "$1"
fi
@ -162,13 +177,21 @@ user_new() {
# Add user $1 to the `staff` group...
# ...and change shell to `zsh` and get rid of bash files.
user_update() {
info "Adding $1 to group staff"
${USERMOD} -aG staff "$1"
info "Changing login shell to zsh"
${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.
user_allow_sudo_nopasswd() {
info "Enabling sudo without password for ${1}"
contents="$1 ALL=(ALL:ALL) NOPASSWD:ALL"
sudoers_file="/etc/sudoers.d/${1}_nopasswd"
if is_dry_run; then
@ -186,8 +209,10 @@ deploy_dotfiles() {
if [ -d "${dotfiles_dir}" ]; then
skipped "${dotfiles_dir} exists"
else
info "Cloning dotfiles"
${SU} "$1" -c "git clone $2 ${dotfiles_dir}"
(
info "Installing dotfiles"
${CD} "${dotfiles_dir}"
${SU} "$1" -c "./install.sh -y"
)