-
Notifications
You must be signed in to change notification settings - Fork 0
/
test
109 lines (86 loc) · 2.77 KB
/
test
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
108
109
#!/bin/bash
# Functions
generate_random_string() {
tr -dc A-Za-z0-9 </dev/urandom | head -c 8
}
# Set some variables
USR="sandbox1"
NEW_HOSTNAME="sandbox-$(generate_random_string)"
HOME="/home/$USR"
PASS=$(date +%d%m%Y)-$(openssl rand -base64 15 | tr -dc 'a-zA-Z0-9' | head -c 8)
RDP_SESSION_FILE="/etc/xrdp/startwm.sh"
KEY="/var/log/key.txt"
# Check if the script was run with sudo
if [ "$(id -u)" -ne 0 ]; then
echo "Please run the script using the 'sudo' command"
exit 1
fi
touch "$KEY"
# Create the new user with a home directory and set the shell to /bin/false to disable command-line access
echo "Creating user $USR..."
adduser --gecos GECOS --shell=/bin/false "$USR"
echo "$USR:$PASS" | chpasswd
echo "$PASS" > "$KEY"
# Update sources -y automatically says yes to everything
echo "Updating package sources..."
apt-get update -y
# Use apt-get install
echo "Installing necessary packages..."
apt-get install -y --no-install-recommends xrdp xfce4 xfce4-goodies firefox
# Set up Firefox to start in single application mode
echo "Setting up Firefox kiosk mode"
mkdir -p $HOME/.config/autostart
cat <<EOF > $HOME/.config/autostart/firefox.desktop
[Desktop Entry]
Type=Application
Name=Firefox Kiosk
Exec=firefox --kiosk http://www.google.com
EOF
chown -R $USR:$USR $HOME/.config
# Configure xrdp to start Firefox in kiosk mode
echo "Configuring xrdp"
sudo cp $RDP_SESSION_FILE ${RDP_SESSION_FILE}.bak
cat <<EOF | sudo tee $RDP_SESSION_FILE
#!/bin/sh
# Custom kiosk user login setup
if [ "\$USER" = "$USR" ]; then
startxfce4 &
/usr/bin/firefox --kiosk http://www.google.com
else
# Original startwm.sh content
if [ -r /etc/X11/Xsession ]; then
exec /etc/X11/Xsession
fi
if [ -r /etc/x11/xinit/Xsession ]; then
exec /etc/x11/xinit/Xsession
fi
if [ -r /usr/bin/x-session-manager ]; then
exec /usr/bin/x-session-manager
fi
if [ -r /usr/bin/x-window-manager ]; then
exec /usr/bin/x-window-manager
fi
exec xterm
fi
EOF
# Enable multiple sessions per user
echo "Configuring XRDP for multiple sessions per user"
# Update sesman.ini
sed -i '/\[Sessions\]/a MaxSessions=50' /etc/xrdp/sesman.ini
# Update xrdp.ini
sed -i '/\[globals\]/a session_multiple=50' /etc/xrdp/xrdp.ini
# Ensure session type is correctly set for xfce
cat <<EOF | sudo tee -a /etc/xrdp/xrdp.ini
[SessionTypes]
xfce=startxfce4
EOF
# Schedule daily reboot at 02:00 AM
echo "Scheduling daily reboot at 02:00 AM..."
(crontab -l 2>/dev/null; echo "0 2 * * * /sbin/reboot") | crontab -
# Change the hostname
hostnamectl set-hostname "$NEW_HOSTNAME"
# Update /etc/hosts to reflect the new hostname
sed -i "s/127.0.1.1.*/127.0.1.1 $NEW_HOSTNAME/" /etc/hosts
sudo systemctl enable xrdp
sudo systemctl restart xrdp
echo "Setup complete. User: $USR, Password: $(cat $KEY)"