-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgoogle-authenticator.sh
52 lines (47 loc) · 1.84 KB
/
google-authenticator.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
#!/bin/bash
apt-get update
apt-get install -y libpam-google-authenticator
# Define the paths for the files to be modified or created
PAM_FILE="/etc/pam.d/rstudio"
RSTUDIO_CONF="/etc/rstudio/rserver.conf"
# Create the /etc/pam.d/rstudio file if it does not exist and add the necessary lines
if [ ! -f "$PAM_FILE" ]; then
echo "Creating $PAM_FILE"
{
echo "auth required pam_google_authenticator.so"
echo "@include common-account"
echo "@include common-session"
} > "$PAM_FILE"
else
echo "Modifying $PAM_FILE"
if ! grep -q "auth required pam_google_authenticator.so" "$PAM_FILE"; then
echo "Adding auth required pam_google_authenticator.so to $PAM_FILE"
echo "auth required pam_google_authenticator.so" >> "$PAM_FILE"
fi
if ! grep -q "@include common-account" "$PAM_FILE"; then
echo "Adding @include common-account to $PAM_FILE"
echo "@include common-account" >> "$PAM_FILE"
fi
if ! grep -q "@include common-session" "$PAM_FILE"; then
echo "Adding @include common-session to $PAM_FILE"
echo "@include common-session" >> "$PAM_FILE"
fi
fi
# Create the /etc/rstudio/rserver.conf file if it does not exist and add the necessary lines
if [ ! -f "$RSTUDIO_CONF" ]; then
echo "Creating $RSTUDIO_CONF"
{
echo "# Server Configuration File"
echo "auth-pam-require-password-prompt=0"
} > "$RSTUDIO_CONF"
else
echo "Modifying $RSTUDIO_CONF"
if ! grep -q "# Server Configuration File" "$RSTUDIO_CONF"; then
echo "# Server Configuration File" >> "$RSTUDIO_CONF"
fi
if ! grep -q "auth-pam-require-password-prompt=0" "$RSTUDIO_CONF"; then
echo "Adding auth-pam-require-password-prompt=0 to $RSTUDIO_CONF"
echo "auth-pam-require-password-prompt=0" >> "$RSTUDIO_CONF"
fi
fi
echo "Configuration completed successfully."