-
Notifications
You must be signed in to change notification settings - Fork 0
/
generate_web_yml.sh
50 lines (46 loc) · 1.01 KB
/
generate_web_yml.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
#!/usr/bin/env bash
set -Eeuo pipefail
echo "Generation web.yml for Prometheus basic authentication."
echo "Enter username:"
read htpasswd_username
echo "Run htpasswd generator..."
htpasswd_string=$(htpasswd -nBC 12 "" | tr -d ':\n')
echo "Creating web.yml..."
if [ -f "web.yml" ]
then
read -p "Do you want recreate web.yml? (y/n)" choice
case "$choice" in
y|Y )
echo "yes"
echo "basic_auth_users:" > web.yml
echo " $htpasswd_username: $htpasswd_string" >> web.yml
;;
n|N )
echo "no";
read -p "Do you want add htpasswd username:password to the end of the web.yml file? (y/n)" choice
case "$choice" in
y|Y )
echo "yes"
echo " $htpasswd_username: $htpasswd_string" >> web.yml
;;
n|N )
echo "no";
echo "Bye!"
exit
;;
* )
echo "invalid"
;;
esac
;;
* )
echo "invalid"
;;
esac
else
echo "basic_auth_users:" > web.yml
echo " $htpasswd_username: $htpasswd_string" >> web.yml
fi
echo "=============================="
echo "web.yml file content:"
cat web.yml