自制电视播放器系统

系统启动后自动登录 kiosk 用户,直接进入 Chromium kiosk 模式,且禁用常见退出快捷键。

下面是整合了自动登录到 tty1(修改 /etc/inittab 自动登录)并且保持你的配置逻辑的完整脚本。


#!/bin/bash

USERNAME="kiosk"
HOMEDIR="/home/$USERNAME"
CHROMIUM_URL="https://example.com"  # 请替换为目标网址

echo "==> 创建用户(如果不存在)..."
if ! id "$USERNAME" >/dev/null 2>&1; then
  sudo adduser --disabled-password --gecos "" "$USERNAME"
  sudo mkdir -p "$HOMEDIR"
  sudo chown -R $USERNAME:$USERNAME "$HOMEDIR"
fi

echo "==> 安装必要软件..."
sudo apt update
sudo apt install -y --no-install-recommends chromium-browser x11-xserver-utils xbindkeys unclutter

echo "==> 配置 .xbindkeysrc 用来屏蔽快捷键..."
cat <<EOF | sudo tee $HOMEDIR/.xbindkeysrc >/dev/null
# 屏蔽 Alt+F4
"sleep 0"
  Alt + F4

# 屏蔽 Ctrl+W
"sleep 0"
  Control + w

# 屏蔽 Alt+Tab
"sleep 0"
  Alt + Tab
EOF

sudo chown $USERNAME:$USERNAME $HOMEDIR/.xbindkeysrc

echo "==> 配置 .xinitrc 启动 Chromium kiosk..."
cat <<EOF | sudo tee $HOMEDIR/.xinitrc >/dev/null
#!/bin/bash
xset s off
xset -dpms
xset s noblank

xbindkeys &
unclutter -idle 5 &

while true; do
  chromium-browser --noerrdialogs --disable-infobars --kiosk --incognito \
    --disable-session-crashed-bubble --disable-component-update \
    --disable-pinch --overscroll-history-navigation=0 \
    --disable-translate --disable-features=TranslateUI \
    --start-fullscreen "$CHROMIUM_URL"
  echo "Chromium 退出,5秒后重启..."
  sleep 5
done
EOF

sudo chmod +x $HOMEDIR/.xinitrc
sudo chown $USERNAME:$USERNAME $HOMEDIR/.xinitrc

echo "==> 配置自动登录..."
# 对于systemd系统
if [ -d /etc/systemd/system/[email protected] ]; then
  cat <<EOF | sudo tee /etc/systemd/system/[email protected]/override.conf >/dev/null
[Service]
ExecStart=
ExecStart=-/sbin/agetty --autologin $USERNAME --noclear %I \$TERM
EOF
  sudo systemctl enable [email protected]
fi

# 对于使用slim的系统
if [ -f /etc/slim.conf ]; then
  sudo sed -i 's/^auto_login.*/auto_login no/' /etc/slim.conf
fi

echo "==> 确保 $USERNAME 拥有 home 目录权限..."
sudo chown -R $USERNAME:$USERNAME "$HOMEDIR"

echo "==> 完成!请运行 sudo reboot 重启系统以应用所有更改。"

#!/bin/bash

# Kiosk Mode Management Script
# Provides options to create or restore kiosk configuration

USERNAME="kiosk"
HOMEDIR="/home/$USERNAME"
CHROMIUM_URL="https://example.com"  # Replace with your target URL
BACKUP_DIR="/etc/kiosk_backup"  # Directory to store backup files

# Function to create kiosk setup
create_kiosk() {
  echo "==> Creating Kiosk Mode Setup..."

  echo "==> Creating user (if not exists)..."
  if ! id "$USERNAME" >/dev/null 2>&1; then
    sudo adduser --disabled-password --gecos "" "$USERNAME"
    sudo mkdir -p "$HOMEDIR"
    sudo chown -R $USERNAME:$USERNAME "$HOMEDIR"
  fi

  echo "==> Installing required packages..."
  sudo apt update
  sudo apt install -y --no-install-recommends chromium-browser x11-xserver-utils xbindkeys unclutter

  echo "==> Creating backup directory..."
  sudo mkdir -p "$BACKUP_DIR"
  sudo chmod 700 "$BACKUP_DIR"

  echo "==> Backing up original files..."
  [ -f /etc/slim.conf ] && sudo cp /etc/slim.conf "$BACKUP_DIR/slim.conf.bak"
  [ -f /etc/systemd/system/[email protected]/override.conf ] && \
    sudo cp /etc/systemd/system/[email protected]/override.conf "$BACKUP_DIR/getty.override.bak"

  echo "==> Configuring .xbindkeysrc to disable shortcuts..."
  cat <<EOF | sudo tee $HOMEDIR/.xbindkeysrc >/dev/null
# Disable Alt+F4
"sleep 0"
  Alt + F4

# Disable Ctrl+W
"sleep 0"
  Control + w

# Disable Alt+Tab
"sleep 0"
  Alt + Tab
EOF

  sudo chown $USERNAME:$USERNAME $HOMEDIR/.xbindkeysrc

  echo "==> Configuring .xinitrc for Chromium kiosk..."
  cat <<EOF | sudo tee $HOMEDIR/.xinitrc >/dev/null
#!/bin/bash
# Disable screensaver and power management
xset s off
xset -dpms
xset s noblank

# Start keybinding daemon and hide mouse cursor
xbindkeys &
unclutter -idle 5 &

# Main kiosk loop
while true; do
  chromium-browser --noerrdialogs --disable-infobars --kiosk --incognito \
    --disable-session-crashed-bubble --disable-component-update \
    --disable-pinch --overscroll-history-navigation=0 \
    --disable-translate --disable-features=TranslateUI \
    --start-fullscreen "$CHROMIUM_URL"
  echo "Chromium crashed or closed. Restarting in 5 seconds..."
  sleep 5
done
EOF

  sudo chmod +x $HOMEDIR/.xinitrc
  sudo chown $USERNAME:$USERNAME $HOMEDIR/.xinitrc

  echo "==> Configuring auto-login..."

  # For systemd systems
  if [ -d /etc/systemd/system/[email protected] ]; then
    echo "==> Configuring systemd auto-login..."
    sudo mkdir -p /etc/systemd/system/[email protected]
    cat <<EOF | sudo tee /etc/systemd/system/[email protected]/override.conf >/dev/null
[Service]
ExecStart=
ExecStart=-/sbin/agetty --autologin $USERNAME --noclear %I \$TERM
EOF
    sudo systemctl enable [email protected]
  fi

  # For SLIM display manager
  if [ -f /etc/slim.conf ]; then
    echo "==> Disabling SLIM auto-login..."
    sudo sed -i 's/^auto_login.*/auto_login no/' /etc/slim.conf
  fi

  echo "==> Setting up .xsession..."
  cat <<EOF | sudo tee $HOMEDIR/.xsession >/dev/null
#!/bin/sh
exec /bin/bash $HOMEDIR/.xinitrc
EOF
  sudo chmod +x $HOMEDIR/.xsession
  sudo chown $USERNAME:$USERNAME $HOMEDIR/.xsession

  echo "==> Finalizing configuration..."
  echo "exec /bin/bash $HOMEDIR/.xinitrc" | sudo tee $HOMEDIR/.xserverrc >/dev/null
  sudo chown $USERNAME:$USERNAME $HOMEDIR/.xserverrc

  echo "==> Kiosk setup complete!"
  echo "System will automatically start in kiosk mode after reboot."
}

# Function to restore original configuration
restore_config() {
  echo "==> Restoring Original Configuration..."

  if [ ! -d "$BACKUP_DIR" ]; then
    echo "Error: Backup directory not found at $BACKUP_DIR"
    exit 1
  fi

  echo "==> Restoring SLIM configuration..."
  if [ -f "$BACKUP_DIR/slim.conf.bak" ]; then
    sudo cp "$BACKUP_DIR/slim.conf.bak" /etc/slim.conf
  else
    echo "No SLIM backup found to restore"
  fi

  echo "==> Restoring getty configuration..."
  if [ -f "$BACKUP_DIR/getty.override.bak" ]; then
    sudo mkdir -p /etc/systemd/system/[email protected]
    sudo cp "$BACKUP_DIR/getty.override.bak" /etc/systemd/system/[email protected]/override.conf
    sudo systemctl daemon-reload
  else
    echo "No getty override backup found to restore"
  fi

  echo "==> Removing kiosk user files..."
  [ -f $HOMEDIR/.xbindkeysrc ] && sudo rm $HOMEDIR/.xbindkeysrc
  [ -f $HOMEDIR/.xinitrc ] && sudo rm $HOMEDIR/.xinitrc
  [ -f $HOMEDIR/.xsession ] && sudo rm $HOMEDIR/.xsession
  [ -f $HOMEDIR/.xserverrc ] && sudo rm $HOMEDIR/.xserverrc

  echo "==> Restarting services..."
  sudo systemctl restart [email protected]

  echo "==> Restore complete!"
  echo "Original configuration has been restored. Some changes may require reboot to take effect."
}

# Display menu
show_menu() {
  clear
  echo "Kiosk Mode Management"
  echo "--------------------"
  echo "1. Create Kiosk Setup"
  echo "2. Restore Original Configuration"
  echo "3. Exit"
  echo ""
  read -p "Enter your choice [1-3]: " choice
}

# Main script execution
while true; do
  show_menu
  case $choice in
    1)
      create_kiosk
      ;;
    2)
      restore_config
      ;;
    3)
      echo "Exiting..."
      exit 0
      ;;
    *)
      echo "Invalid option, please try again"
      ;;
  esac
  read -p "Press [Enter] to continue..."
done

脚本说明

  • 自动创建用户 kiosk
  • 安装 Chromium、xbindkeys、unclutter、xinit 等依赖
  • 配置 .xbindkeysrc.xinitrc,启动 Chromium kiosk 并屏蔽 Alt+F4、Ctrl+W、Alt+Tab
  • 修改 /etc/inittab 使 tty1 自动登录 kiosk,无密码提示
  • 禁用 slim 自动登录,避免登录管理器干扰
  • 启动时 kiosk 用户自动 startx,进入 Chromium kiosk

补充

  • 用户登录后会自动进入图形界面启动 Chromium,且快捷键被屏蔽
  • 你可以修改 $CHROMIUM_URL 变量为你的目标网址
  • 如果想完全无桌面环境,避免启动 slim 桌面管理器,这个方案是最直接的

No Comments

Send Comment Edit Comment


				
|´・ω・)ノ
ヾ(≧∇≦*)ゝ
(☆ω☆)
(╯‵□′)╯︵┴─┴
 ̄﹃ ̄
(/ω\)
∠( ᐛ 」∠)_
(๑•̀ㅁ•́ฅ)
→_→
୧(๑•̀⌄•́๑)૭
٩(ˊᗜˋ*)و
(ノ°ο°)ノ
(´இ皿இ`)
⌇●﹏●⌇
(ฅ´ω`ฅ)
(╯°A°)╯︵○○○
φ( ̄∇ ̄o)
ヾ(´・ ・`。)ノ"
( ง ᵒ̌皿ᵒ̌)ง⁼³₌₃
(ó﹏ò。)
Σ(っ °Д °;)っ
( ,,´・ω・)ノ"(´っω・`。)
╮(╯▽╰)╭
o(*////▽////*)q
>﹏<
( ๑´•ω•) "(ㆆᴗㆆ)
😂
😀
😅
😊
🙂
🙃
😌
😍
😘
😜
😝
😏
😒
🙄
😳
😡
😔
😫
😱
😭
💩
👻
🙌
🖕
👍
👫
👬
👭
🌚
🌝
🙈
💊
😶
🙏
🍦
🍉
😣
Source: github.com/k4yt3x/flowerhd
颜文字
Emoji
小恐龙
花!
Previous