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,39 +72,46 @@ skipped() {
apt_install() { apt_install() {
title "Install APT packages" title "Install APT packages"
info "Updating package database"
${APT} update ${APT} update
${APT} install -y \
apt-file \ info "Installing APT packages"
ascii \ ${APT} install -y \
build-essential \ apt-file \
ca-certificates \ ascii \
cmake \ build-essential \
cmake-doc \ ca-certificates \
curl \ cmake \
exuberant-ctags \ cmake-doc \
g++ \ curl \
gcc \ exuberant-ctags \
git \ g++ \
git-crypt \ gcc \
gnupg \ git \
htop \ git-crypt \
jq \ gnupg \
make \ help2man \
man-db \ htop \
nodejs \ jq \
pkg-config \ make \
psmisc \ man-db \
python3 \ nodejs \
python3-virtualenv \ pandoc \
ripgrep \ pkg-config \
rsync \ psmisc \
shellcheck \ python3 \
sshpass \ python3-virtualenv \
stow \ ripgrep \
sudo \ rsync \
tmux \ shellcheck \
unzip \ sshpass \
stow \
sudo \
tmux \
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"
) )