-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup_code_server_users.sh
More file actions
executable file
·45 lines (37 loc) · 1.26 KB
/
setup_code_server_users.sh
File metadata and controls
executable file
·45 lines (37 loc) · 1.26 KB
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
#!/bin/bash
# Define users and starting port
START_PORT=9001
USERS=(user31 user32 user33 user34 user35)
echo "Updating code-server configs and restarting services..."
# Loop through each user
for i in "${!USERS[@]}"; do
USER=${USERS[$i]}
PORT=$((START_PORT + i))
echo "Configuring $USER on port $PORT"
# Create config directory if it doesn't exist
sudo -u $USER mkdir -p /home/$USER/.config/code-server
# Write config.yaml
sudo tee /home/$USER/.config/code-server/config.yaml > /dev/null <<EOF
bind-addr: 0.0.0.0:$PORT
auth: password
password: "DevPassword2026!"
cert: false
EOF
# Restart the user's code-server service
sudo systemctl restart code-server@$USER
done
echo
echo "All services restarted."
echo
echo "===== Nginx snippet for users 31-35 ====="
for i in "${!USERS[@]}"; do
USER=${USERS[$i]}
PORT=$((START_PORT + i))
echo ""
echo "# $USER"
echo "location = /$USER { return 301 /$USER/; }"
echo "location /$USER/ { proxy_pass http://127.0.0.1:$PORT/; proxy_set_header Host \$host; proxy_set_header Upgrade \$http_upgrade; proxy_set_header Connection upgrade; proxy_set_header Accept-Encoding gzip; }"
done
echo
echo "Copy the above snippet into your Nginx config and reload Nginx:"
echo "sudo systemctl reload nginx"