-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathset-banners.sh
75 lines (57 loc) · 3.19 KB
/
set-banners.sh
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
#!/usr/bin/env bash
# Add startup script to set a banner to be displayed on the login screen communicating connection options:
sudo tee /etc/rc.d/rc.local > /dev/null <<'EOF'
#!/usr/bin/env bash
sleep 3 # Wait for DHCP
msg=""
host=$(hostname -s)
ips=($(hostname -I))
main_ip="${ips[0]}"
msg+=$'\\S\n'
msg+=$'Kernel \\r on an \\m (\\l)\n'
msg+=$'\n'
msg+="─────────────────────────────────────────────────────────────────────────────────────────"$'\n'
msg+=" » $host"$'\n'
msg+=$'\n'
if [ -f /etc/rc.d/prevrun ]; then
msg+=" Connect to this VM via:"$'\n'
msg+=$'\n'
msg+=" 1) SSH : From a remote machine, run \`ssh user@$main_ip\`."$'\n'
msg+=$'\n'
msg+=" 2) VS Code : Click the blue ›‹ icon in the bottom-left corner of an open window."$'\n'
msg+=" Choose the \"Connect to Host... (Remote-SSH)\" option."$'\n'
msg+=" At the prompt, type \"user@$main_ip\" and press Enter."$'\n'
else
msg+=" Connect to this VM via SSH by running \`ssh user@$main_ip\` from a remote machine."$'\n'
fi
msg+="═════════════════════════════════════════════════════════════════════════════════════════"$'\n'
msg+=$'\n'
echo "$msg" > /etc/issue
touch /etc/rc.d/prevrun
exit 0
EOF
sudo chmod 755 /etc/rc.d/rc.local
# Add a login script to display a banner after successful authentication:
sudo tee /etc/profile.d/01_display-login-banner.sh > /dev/null <<'EOF'
#!/usr/bin/env bash
username=$(whoami)
host=$(hostname -s)
ips=($(hostname -I))
main_ip="${ips[0]}"
if [ -n "$SSH_CLIENT" ]; then
echo
echo "──ℹ️─────────────────────────────────────────────────────────────────────────────────────"
echo " Welcome $username to $host"
echo
echo " You can also connect to this VM from VS Code:"
echo " 1. Click the blue ›‹ icon in the bottom-left corner of an open window."
echo " 2. Choose the \"Connect to Host... (Remote-SSH)\" option."
echo " 3. At the prompt, type \"$username@$main_ip\" and press Enter."
else
echo "─────────────────────────────────────────────────────────────────────────────────────────"
echo " » Welcome $username to $host"
fi
echo "═════════════════════════════════════════════════════════════════════════════════════════"
echo
EOF
sudo chmod 755 /etc/profile.d/01_display-login-banner.sh