-
Notifications
You must be signed in to change notification settings - Fork 0
/
install.sh
executable file
·129 lines (97 loc) · 2.94 KB
/
install.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
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
echo "Install script v1.0"
echo "Please open your telegram app"
echo "(press enter to continue)"
read junk
clear
echo "Open a DM with https://t.me/BotFather (click or copy and paste the link)"
echo "(press enter to continue)"
read junk
clear
echo "Do \"/start\""
echo "(press enter to continue)"
read junk
clear
echo "Do \"/newbot\""
echo "(press enter to continue)"
read junk
clear
echo "Please enter your API token: "
read token
if [ -z "$token" ]; then
echo "ERROR: You typed in an empty token! Please re-run the program"
exit 1
fi
#dont ask how this works. This took me hours
chat_id=$(curl "https://api.telegram.org/bot$token/getUpdates?limit=1&offset=-1" | sed -n -e 's/^.*chat\"\:{\"id\"\://p' | cut -d',' -f1)
echo "Enable recovery password? (true/false)"
read enable_rec
if [ $enable_rec = "true" ]
then
echo "Enter a recovery password"
read pass
if [ -z "$pass" ]; then
echo "ERROR: Password was empty! Please re-run script"
exit 1
fi
fi
echo "How long to wait before checking for more messages? (recomended is 3 seconds)"
read delay
if [ -z "$delay" ]; then
echo "ERROR: Delay was null! Please re-run script!"
exit 1
fi
echo "If a user is not reconized, should ...\n\t- An admin still get a message for accepting or denying the request? (true)\n\t- Deny any users who are not whitelisted in settings.h (false)\nDEFAULT IS 'true'"
read enable_default_chat
if [ -z "$enable_default_chat" ]; then
echo "No info was given. Defaulting to 'true'"
enable_default_chat="true"
fi
echo "What directory would you like to install the module to? (Default is /usr/local/lib/pam_addons/)"
read exp_dir
if [ -z "$exp_dir" ]; then
exp_dir="/usr/local/lib/pam_addons"
fi
echo "Generating settings.h ..."
echo "" > settings.h
echo "#pragma once\n" >> settings.h
echo "#define CHAT_ID $chat_id\n" >> settings.h
echo "#define API_TOKEN \"$token\"" >> settings.h
echo "#define UPDATE_DELAY $delay" >> settings.h
if [ $enable_rec = "true" ]
then
echo "#define RECOVERY_PASSWORD \"$pass\"" >> settings.h
else
echo "#define PAM_TELEGRAM_NO_RECOVERY" >> settings.h
fi
if [ $enable_default_chat = "true" ]
then
echo "#define DEFAULT_AUTH_USER" >> settings.h
fi
echo "#define USER_GROUPS_SIZE (1)" >> settings.h
echo "const user_group_t USER_GROUPS[USER_GROUPS_SIZE] = {" >> settings.h
echo "\t{$chat_id, \"$(whoami)\"}," >> settings.h
echo "};" >> settings.h
clear
echo "Done generating settings!\n"
echo "Your default editor will now open to ensure that the settings were correct in 10 seconds ..."
sleep 10
$EDITOR settings.h
clear
echo "Please enter sudo for making the PAM directory"
sudo mkdir -p "$exp_dir"
clear
echo "Installing dependancies ..."
make depend
#remove duplicates
FILE=json.hpp
if [ -f "$FILE" ]; then
rm json.hpp.1
fi
clear
echo "Compiling program ...\n"
make compile
clear
echo "Copying program to directory ..."
sudo cp ./build/pam_telegram.so "$exp_dir"
clear
echo "Done! Follow the README.md for further instructions on how to configure PAM"