forked from datacats/ckan-multisite
-
Notifications
You must be signed in to change notification settings - Fork 0
/
manage.sh
executable file
·59 lines (52 loc) · 1.6 KB
/
manage.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
#!/bin/bash
ProgName=$(basename $0)
sub_help(){
echo "Usage: $ProgName <subcommand> [options]\n"
echo "Subcommands:"
echo " regenerate Regenerate the configuration files for nginx"
echo " changepw Changes the password for the ckan-multisite admin."
echo ""
}
sub_regenerate() {
python -c "from ckan_multisite.router import nginx;nginx.regenerate_config()"
}
sub_changepw() {
password=""
password_confirm="n"
while [ "$password" != "$password_confirm" ]; do
read -s -p "Please enter the admin user password you wish to use: " password
echo
read -s -p "Please confirm the password: " password_confirm
echo
done
pw_hash=$(python -c "from ckan_multisite.pw import encrypt; print encrypt('$password')" | sed -e 's/[\/&]/\\&/g')
if [ $? != 0 ]; then
echo 'Python failed. See above output. Could not change pw.'
exit 1
fi
sed -i "s/.*ADMIN_PW.*/ADMIN_PW= '$pw_hash'/gw changes.txt" ckan_multisite/config.py
if [ -s changes.txt ]; then
echo 'Password changed successfully.'
rm changes.txt
else
echo 'Pattern not found. Cannot change.'
rm changes.txt
exit 1
fi
}
source virtualenv/bin/activate
subcommand=$1
case $subcommand in
"" | "-h" | "--help")
sub_help
;;
*)
shift
sub_${subcommand} $@
if [ $? = 127 ]; then
echo "Error: '$subcommand' is not a known subcommand." >&2
echo " Run '$ProgName --help' for a list of known subcommands." >&2
exit 1
fi
;;
esac