aboutsummaryrefslogtreecommitdiff
path: root/configure.sh
blob: 1cc55e29c448ee052bcff3e6a60ec99a4e06ec36 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#!/bin/bash

# Function to display the menu
show_menu() {
    DIALOG_RESULT=$(dialog --title "Configuration Menu" --menu "Choose an option:" 15 50 3 \
      1 "Change Scaling, Kiosk Type, and Websites" \
      2 "Change VNC Password" \
      3 "Exit" \
      3>&1 1>&2 2>&3 3>&-)
    echo $DIALOG_RESULT
}

# Function to configure start.sh
configure_start_sh() {
    SCALE_FACTOR=$(dialog --title "Display Scaling Factor" --inputbox "Enter the display scaling factor (e.g., 1 for 1080p, 2 for 4K):" 8 50 "1" 3>&1 1>&2 2>&3 3>&-)

    DIALOG_RESULT=$(dialog --title "start.sh Configuration" --menu "Choose the script example:" 15 50 2 \
      1 "Simple website script" \
      2 "Two or more tabs alternating every 30 seconds" \
      3>&1 1>&2 2>&3 3>&-)

    if [ "$DIALOG_RESULT" = "1" ]; then
        WEBSITE=$(dialog --title "Enter Website URL" --inputbox "Please enter the URL for the simple website:" 8 50 "https://www.example.com" 3>&1 1>&2 2>&3 3>&-)
        set_start_script_single $SCALE_FACTOR $WEBSITE
    elif [ "$DIALOG_RESULT" = "2" ]; then
        TAB_COUNT=$(dialog --title "Number of Tabs" --inputbox "Enter number of tabs:" 8 50 "3" 3>&1 1>&2 2>&3 3>&-)
        local tab_urls=()
        for (( i=1; i<=TAB_COUNT; i++ )); do
            URL=$(dialog --title "Enter URL for Tab $i" --inputbox "Enter URL:" 8 50 "http://example$i.com" 3>&1 1>&2 2>&3 3>&-)
            tab_urls+=("$URL")
        done
        configure_tabs $SCALE_FACTOR "${tab_urls[@]}"
    fi
}

# Helper function to configure start.sh for a single website
set_start_script_single() {
    # Write the script with properly formatted commands
    cat > /home/kiosk/start.sh <<EOF
#!/bin/bash
/usr/bin/chromium --no-first-run --disable-translate --no-default-browser-check --disable-cache --kiosk $2
EOF
    chmod a+x /home/kiosk/start.sh
}

# Helper function to configure start.sh for multiple tabs
configure_tabs() {
    local scaling_factor=$1
    shift  # Remove the first argument (scaling factor) to loop over URLs
    local tab_urls=""
    for url in "$@"; do
        tab_urls+="'$url' "  # Ensure URLs are properly quoted
    done

    # Write the script with properly formatted commands
    cat > /home/kiosk/start.sh <<EOF
#!/bin/bash
/usr/bin/chromium --incognito --force-device-scale-factor=$scaling_factor --temp-profile --disable-profiles --no-first-run --disable-translate --no-default-browser-check --disable-cache --kiosk $tab_urls &
sleep 10  # Allow time for Chromium to launch

# Function definitions should be placed before they are called
switch_tabs() {
    WINDOW_ID=\$(xdotool search --onlyvisible --class chromium | head -n 1)
    xdotool windowactivate --sync \$WINDOW_ID
    xdotool key --window \$WINDOW_ID ctrl+Tab
}

is_vnc_active() {
    netstat -an | grep ':5901' | grep -q 'ESTABLISHED'
    return \$?
}

# Main loop to handle tab switching
while true; do
    if is_vnc_active; then
        echo "VNC session active, pausing tab switch..."
        sleep 5
    else
        echo "VNC session inactive, switching tabs..."
        switch_tabs
        sleep 30
    fi
done
EOF
    chmod a+x /home/kiosk/start.sh
}

# Function to change VNC password
change_vnc_password() {
    VNC_PASSWORD=$(dialog --title "VNC Password" --inputbox "Please enter the new VNC password:" 8 50 "" 3>&1 1>&2 2>&3 3>&-)
    mkdir -p /home/kiosk/.vnc
    rm -f /home/kiosk/.vnc/passwd  # Remove existing password file if it exists
    echo "$VNC_PASSWORD" | vncpasswd -f > /home/kiosk/.vnc/passwd
    chmod 600 /home/kiosk/.vnc/passwd
    echo "VNC password changed"
}

# Main loop
while true; do
    choice=$(show_menu)
    case $choice in
        1) configure_start_sh ;;
        2) change_vnc_password ;;
        3) exit 0 ;;
        *) echo "Invalid option, please try again" ;;
    esac
done