Refactor setup script to implement step logging for better clarity during execution

This commit is contained in:
FallingLights 2025-05-07 20:01:34 +02:00
parent b94f80eee7
commit 684b51d7c2

View file

@ -20,14 +20,21 @@ KIOSK_URL="https://example.com"
SIGNAGE_USER="signage"
# WayVNC Configuration
# The script will create a ~/.profile for the SIGNAGE_USER
# where this variable can be set.
# For better security, leave it blank here and edit ~/.profile manually after setup.
WAYVNC_PASSWORD_TO_SET="" # Example: "your_secure_password"
WAYVNC_LISTEN_ADDRESS="0.0.0.0" # Listen on all interfaces
WAYVNC_PORT="5900" # Default VNC port
# --- End Configuration ---
# --- Step Counter ---
TOTAL_STEPS=13 # Adjust this if you add/remove major steps
CURRENT_STEP=0
log_step_message() {
CURRENT_STEP=$((CURRENT_STEP + 1))
echo -e "${BLU}[Step $CURRENT_STEP/$TOTAL_STEPS] $1...${DEF}"
}
# --- End Step Counter ---
echo -e "${BLU}Starting Alpine Linux Signage Setup (Using Sway, greetd, WayVNC)...${DEF}"
echo -e "${BLU}Target URL: ${GRN}$KIOSK_URL${DEF}"
echo -e "${BLU}Signage User: ${GRN}$SIGNAGE_USER${DEF}"
@ -43,7 +50,7 @@ fi
# 2. Check for 'nomodeset' kernel parameter (early check)
set +e # Temporarily disable exit-on-error
KERNEL_CMDLINE=$(cat /proc/cmdline)
echo -e "${BLU}[Step 1/13] Checking kernel command line for 'nomodeset'...${DEF}"
log_step_message "Checking kernel command line for 'nomodeset'"
echo "Command line: $KERNEL_CMDLINE"
if echo "$KERNEL_CMDLINE" | grep -q -w 'nomodeset'; then
echo ""
@ -62,19 +69,19 @@ set -e # Re-enable exit-on-error
echo "-------------------------------------"
# 3. Update repositories
echo -e "${BLU}[Step 2/13] Updating package repositories...${DEF}"
log_step_message "Updating package repositories"
apk update
echo "-------------------------------------"
# 4. Setup base Wayland environment (includes enabling community repo)
echo -e "${BLU}[Step 3/13] Setting up base Wayland environment (elogind, eudev)...${DEF}"
log_step_message "Setting up base Wayland environment (elogind, eudev)"
apk add --no-cache alpine-conf
setup-wayland-base # This enables community repository
echo -e "${GRN}Base Wayland environment setup complete.${DEF}"
echo "-------------------------------------"
# 5. Install necessary packages
echo -e "${BLU}[Step 4/13] Installing Sway, Chromium, Mesa, D-Bus, Fonts, Firmware, Greetd, WayVNC, swaybg, open-vm-tools...${DEF}"
log_step_message "Installing Sway, Chromium, Mesa, D-Bus, Fonts, Firmware, Greetd, WayVNC, swaybg, open-vm-tools"
apk add \
sway \
swayidle \
@ -98,7 +105,7 @@ echo -e "${GRN}Required packages installed.${DEF}"
echo "-------------------------------------"
# 6. Enable & Start D-Bus service
echo -e "${BLU}[Step 5/13] Enabling and starting D-Bus service...${DEF}"
log_step_message "Enabling and starting D-Bus service"
if ! rc-service dbus status > /dev/null 2>&1; then
rc-update add dbus default
rc-service dbus start
@ -109,7 +116,7 @@ fi
echo "-------------------------------------"
# 7. Enable & Start open-vm-tools service (if installed)
echo -e "${BLU}[Step 6/13] Enabling and starting open-vm-tools service...${DEF}"
log_step_message "Enabling and starting open-vm-tools service"
if apk info --installed open-vm-tools > /dev/null 2>&1; then
if ! rc-service open-vm-tools status > /dev/null 2>&1; then
echo -e "${BLU}Enabling open-vm-tools service...${DEF}"
@ -126,10 +133,10 @@ fi
echo "-------------------------------------"
# 8. Create the signage user and add to necessary groups
echo -e "${BLU}[Step 7/13] Creating signage user '$SIGNAGE_USER' and configuring groups...${DEF}"
log_step_message "Creating signage user '$SIGNAGE_USER' and configuring groups"
if ! id -u "$SIGNAGE_USER" >/dev/null 2>&1; then
echo -e "${BLU}Creating group '$SIGNAGE_USER' (for primary group)...${DEF}"
addgroup "$SIGNAGE_USER" # Ensure primary group exists
addgroup "$SIGNAGE_USER"
echo -e "${BLU}Creating user '$SIGNAGE_USER' with shell /bin/sh...${DEF}"
adduser -D -G "$SIGNAGE_USER" -s /bin/sh -h "/home/$SIGNAGE_USER" "$SIGNAGE_USER"
@ -184,8 +191,9 @@ echo -e "${GRN}User home directory and local share directory configured.${DEF}"
echo "-------------------------------------"
# 9. Configure user's .profile for WayVNC password and other environment variables
echo -e "${BLU}[Step 8/13] Configuring $SIGNAGE_HOME/.profile for $SIGNAGE_USER...${DEF}"
log_step_message "Configuring $SIGNAGE_HOME/.profile for $SIGNAGE_USER"
SIGNAGE_PROFILE="$SIGNAGE_HOME/.profile"
cat > "$SIGNAGE_PROFILE" << EOF
# Profile for $SIGNAGE_USER executed by /bin/sh on login
@ -213,6 +221,7 @@ cat >> "$SIGNAGE_PROFILE" << EOF
# export SDL_VIDEODRIVER=wayland
# export _JAVA_AWT_WM_NONREPARENTING=1
EOF
chown "$SIGNAGE_USER:$SIGNAGE_USER" "$SIGNAGE_PROFILE"
chmod 600 "$SIGNAGE_PROFILE"
echo -e "${GRN}$SIGNAGE_PROFILE configured.${DEF}"
@ -220,7 +229,7 @@ echo "-------------------------------------"
# 10. Configure Sway
echo -e "${BLU}[Step 9/13] Configuring Sway...${DEF}"
log_step_message "Configuring Sway"
SIGNAGE_CONFIG_DIR="$SIGNAGE_HOME/.config"
SIGNAGE_SWAY_CONFIG_DIR="$SIGNAGE_CONFIG_DIR/sway"
SIGNAGE_SWAY_CONFIG_FILE="$SIGNAGE_SWAY_CONFIG_DIR/config"
@ -232,6 +241,7 @@ chmod 700 "$SIGNAGE_CONFIG_DIR"
chmod 700 "$SIGNAGE_SWAY_CONFIG_DIR"
echo -e "${BLU}Creating $SIGNAGE_SWAY_CONFIG_FILE...${DEF}"
cat > "$SIGNAGE_SWAY_CONFIG_FILE" << EOF
# Sway configuration for Alpine Signage Kiosk
@ -299,19 +309,21 @@ bindsym \$mod+Shift+e exec swaynag -t warning -m 'You pressed the exit shortcut.
focus_follows_mouse no
mouse_warping output
EOF
chown "$SIGNAGE_USER:$SIGNAGE_USER" "$SIGNAGE_SWAY_CONFIG_FILE"
chmod 600 "$SIGNAGE_SWAY_CONFIG_FILE"
echo -e "${GRN}Sway configuration file written to $SIGNAGE_SWAY_CONFIG_FILE.${DEF}"
echo "-------------------------------------"
# 11. Configure greetd for Autologin and Sway Session
echo -e "${BLU}[Step 10/13] Configuring greetd...${DEF}"
log_step_message "Configuring greetd"
GREETD_CONFIG_DIR="/etc/greetd"
GREETD_CONFIG_FILE="$GREETD_CONFIG_DIR/config.toml"
mkdir -p "$GREETD_CONFIG_DIR"
SWAY_LOG_PATH_IN_GREETD="$SIGNAGE_LOCAL_SHARE/sway/sway-greetd.log"
cat > "$GREETD_CONFIG_FILE" << EOF
# Greetd configuration for signage kiosk with Sway
@ -326,13 +338,14 @@ command = "/usr/bin/dbus-run-session /usr/bin/sway -V -d 2> $SWAY_LOG_PATH_IN_GR
# Simpler alternative if log redirection is problematic (logs go to greetd's output):
# command = "/usr/bin/dbus-run-session /usr/bin/sway"
EOF
chmod 644 "$GREETD_CONFIG_FILE"
echo -e "${GRN}greetd config written to $GREETD_CONFIG_FILE.${DEF}"
echo -e "${BLU}Ensure $SIGNAGE_USER can write to $SWAY_LOG_PATH_IN_GREETD.${DEF}"
echo "-------------------------------------"
# 12. Configure inittab to start greetd
echo -e "${BLU}[Step 11/13] Configuring autologin via greetd in /etc/inittab...${DEF}"
log_step_message "Configuring autologin via greetd in /etc/inittab"
if [ -f "/etc/inittab" ]; then
if [ ! -f "/etc/inittab.bak.signage" ]; then
cp /etc/inittab /etc/inittab.bak.signage
@ -359,7 +372,7 @@ fi
echo "-------------------------------------"
# 13. Attempt to Enable elogind PAM module for session management
echo -e "${BLU}[Step 12/13] Attempting to configure PAM for elogind session...${DEF}"
log_step_message "Attempting to configure PAM for elogind session"
PAM_GREETD_FILE="/etc/pam.d/greetd"
PAM_SYSTEM_LOGIN="/etc/pam.d/system-login"
PAM_SYSTEM_AUTH="/etc/pam.d/system-auth"
@ -397,7 +410,7 @@ else
fi
echo "-------------------------------------"
echo -e "${BLU}[Step 13/13] Final checks and information.${DEF}"
log_step_message "Final checks and information"
echo -e "${GRN}-----------------------------------------------------${DEF}"
echo -e "${GRN} Alpine Linux Signage Setup Script Finished! ${DEF}"
echo -e "${GRN}-----------------------------------------------------${DEF}"