#!/bin/bash # Sets up an antiX laptop for the classroom: # 1. removes Firefox ESR and the other small browsers antiX ships with (first, to free space), # 2. installs Chromium, # 3. signs in automatically and opens ZeroAI Studio full screen at start-up, # 4. reopens Studio if it is closed, # 5. Shift+Alt+K leaves Studio for the normal browser, after the admin password; # Shift+Alt+Z goes back into Studio. # Run it with: wget -qO- b.zeroaitech.tech | sudo bash # Safe to run again: it only changes what is not already set up. set -uo pipefail STUDIO_URL="https://studio.zeroaitech.tech" if [ "$(id -u)" -ne 0 ]; then echo "This needs admin rights. Run: wget -qO- b.zeroaitech.tech | sudo bash" exit 1 fi export DEBIAN_FRONTEND=noninteractive # The person who ran sudo is the account the laptop signs in to and sets up. USER_NAME="${SUDO_USER:-}" if [ -z "$USER_NAME" ] || [ "$USER_NAME" = root ]; then USER_NAME=$(getent passwd | awk -F: '$3 >= 1000 && $3 < 60000 {print $1; exit}') fi if [ -z "$USER_NAME" ]; then echo "Could not find the laptop's user account. Run this from that account with sudo." exit 1 fi USER_HOME=$(getent passwd "$USER_NAME" | cut -d: -f6) echo "==> Setting up the account: $USER_NAME ($USER_HOME)" # --- 1. Remove Firefox ESR and other browsers first ------------------------------------------------- echo "==> Removing Firefox ESR and other browsers" REMOVE="" for pattern in 'firefox-esr*' 'firefox' 'dillo' 'links' 'links2' 'elinks' 'netsurf*' 'seamonkey*' 'palemoon*' 'midori' 'qutebrowser' 'falkon' 'epiphany-browser' 'luakit' 'surf' 'konqueror'; do found=$(dpkg-query -W -f='${binary:Package} ${Status}\n' "$pattern" 2>/dev/null | awk '/ installed$/ {print $1}') [ -n "$found" ] && REMOVE="$REMOVE $found" done if [ -n "$REMOVE" ]; then echo " Removing:$REMOVE" apt-get purge -y $REMOVE apt-get autoremove -y apt-get clean else echo " No other browsers installed" fi # --- 2. Install Chromium (and yad, for the password box) ------------------------------------------------ echo "==> Installing Chromium" apt-get update apt-get install -y chromium yad if ! command -v chromium >/dev/null; then echo "Chromium did not install. Check the internet connection and run this again." exit 1 fi for link in x-www-browser gnome-www-browser; do update-alternatives --set "$link" /usr/bin/chromium 2>/dev/null || true done # --- 3. The Studio launcher, the way out, and the way back ------------------------------------------------ echo "==> Installing the Studio launcher" cat > /usr/local/bin/studio-kiosk <"/tmp/studio-kiosk-lock-\$(id -u)" flock -n 9 || exit 0 while [ ! -e "\$OFF" ]; do chromium --kiosk --no-first-run --noerrdialogs --disable-session-crashed-bubble \\ --disable-infobars --password-store=basic --user-data-dir="\$HOME/.config/studio-kiosk" \\ "$STUDIO_URL" [ -e "\$OFF" ] && break sleep 3 done EOF cat > /usr/local/bin/studio-exit <<'EOF' #!/bin/bash # Shift+Alt+K: leave Studio for the normal browser, after the admin (sudo) password. pass=$(yad --entry --hide-text --center --on-top --width=360 --title="Leave ZeroAI Studio" \ --text="Enter the admin password to leave ZeroAI Studio." --button=Cancel:1 --button=OK:0) || exit 0 if printf '%s\n' "$pass" | sudo -S -k -p '' true 2>/dev/null; then touch "/tmp/studio-kiosk-off-$(id -u)" pkill -u "$(id -u)" -f 'user-data-dir=.*studio-kiosk' 2>/dev/null sleep 1 chromium >/dev/null 2>&1 & else yad --error --center --on-top --title="Leave ZeroAI Studio" --text="That password is not right." --button=OK:0 fi EOF cat > /usr/local/bin/studio-return <<'EOF' #!/bin/bash # Shift+Alt+Z: back into ZeroAI Studio full screen. setsid /usr/local/bin/studio-kiosk >/dev/null 2>&1 & EOF chmod 755 /usr/local/bin/studio-kiosk /usr/local/bin/studio-exit /usr/local/bin/studio-return # --- 4. Start Studio when the desktop starts, and add the keys --------------------------------------------- echo "==> Starting Studio with the desktop" as_user() { sudo -u "$USER_NAME" "$@"; } add_line() { # file, line: adds the line once, creating the file if needed as_user mkdir -p "$(dirname "$1")" as_user touch "$1" grep -qxF "$2" "$1" || printf '%s\n' "$2" | as_user tee -a "$1" >/dev/null } # antiX runs ~/.desktop-session/startup for every desktop (Fluxbox, IceWM, JWM). add_line "$USER_HOME/.desktop-session/startup" "/usr/local/bin/studio-kiosk &" as_user chmod +x "$USER_HOME/.desktop-session/startup" # Fluxbox's own start file too, before its last line, in case the one above is not used. FB_START="$USER_HOME/.fluxbox/startup" if [ -f "$FB_START" ] && ! grep -q studio-kiosk "$FB_START"; then if grep -q '^exec ' "$FB_START"; then sed -i '0,/^exec /s//\/usr\/local\/bin\/studio-kiosk \&\nexec /' "$FB_START" else printf '%s\n' "/usr/local/bin/studio-kiosk &" >> "$FB_START" fi fi echo "==> Adding Shift+Alt+K (leave Studio) and Shift+Alt+Z (back to Studio)" add_line "$USER_HOME/.fluxbox/keys" "Shift Mod1 k :Exec /usr/local/bin/studio-exit" add_line "$USER_HOME/.fluxbox/keys" "Shift Mod1 z :Exec /usr/local/bin/studio-return" add_line "$USER_HOME/.icewm/keys" 'key "Shift+Alt+k" /usr/local/bin/studio-exit' add_line "$USER_HOME/.icewm/keys" 'key "Shift+Alt+z" /usr/local/bin/studio-return' JWM_KEYS="$USER_HOME/.jwm/keys" if [ -f "$JWM_KEYS" ] && ! grep -q studio-exit "$JWM_KEYS"; then sed -i 's## exec:/usr/local/bin/studio-exit\n exec:/usr/local/bin/studio-return\n#' "$JWM_KEYS" fi # --- 5. Sign in automatically ----------------------------------------------------------------------- echo "==> Signing in automatically as $USER_NAME" AUTO="" # antiX's own login screen. Its settings must start at the first character of a line, and the last # matching line wins, so old ones are removed and the new ones added in both of its files. if [ -f /etc/slimski.conf ]; then for CONF in /etc/slimski.conf /etc/slimski.local.conf; do [ -f "$CONF" ] || continue sed -i '/^default_user\([[:space:]]\|$\)/d; /^autologin_enabled\([[:space:]]\|$\)/d' "$CONF" printf 'default_user %s\nautologin_enabled true\n' "$USER_NAME" >> "$CONF" done AUTO="slimski" fi if [ -f /etc/slim.conf ]; then sed -i '/^[[:space:]]*default_user[[:space:]]/d; /^[[:space:]]*auto_login[[:space:]]/d' /etc/slim.conf printf 'default_user %s\nauto_login yes\n' "$USER_NAME" >> /etc/slim.conf AUTO="${AUTO:+$AUTO, }slim" fi if [ -d /etc/lightdm ]; then mkdir -p /etc/lightdm/lightdm.conf.d printf '[Seat:*]\nautologin-user=%s\nautologin-user-timeout=0\n' "$USER_NAME" > /etc/lightdm/lightdm.conf.d/50-studio-autologin.conf AUTO="${AUTO:+$AUTO, }lightdm" fi [ -n "$AUTO" ] && echo " Set for: $AUTO" || echo " No known login screen found; automatic sign-in was NOT set" echo echo "Done. $(chromium --version 2>/dev/null)." echo "Restart the laptop: it should sign in by itself and open ZeroAI Studio." echo "Shift+Alt+K leaves Studio (admin password). Shift+Alt+Z goes back."