-
Notifications
You must be signed in to change notification settings - Fork 3
/
deploy.sh
87 lines (67 loc) · 2.08 KB
/
deploy.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
#!/bin/bash
git_repo="https://github.com/s0lst1ce/Botanist.git"
name="Botanist"
#home_url="https://github.com/s0lst1ce/Botanist"
helpFunction(){
echo ""
echo "Usage: $0 TOKEN"
echo " -h shows this help message"
echo " -n name of the bot. Default is Botanist"
echo " -u home url for the bot"
echo " -p set the prefix the bot should listen to"
exit 0
}
[ $# -eq 0 ] && helpFunction
#parsing options
while getopts ":hn:u:p:" option; do
case $option in
h | help )
helpFunction;;
n | name )
name=$OPTARG;;
u )
home_url=$OPTARG;;
p )
prefix=$OPTARG;;
\? )
echo "Invalid option -$OPTARG"
helpFunction;;
\: ) echo "Missing argument for -$OPTARG"
helpFunction;;
\- ) echo "Long options are not yet supported!";;
esac
#shift
done
#installing the bot
echo "Downloading bot into $name."
git clone $git_repo $name &> /dev/null
#setting TOKEN as env var
token=$1
if [[ ! -z $DISCORD_TOKEN ]]; then
echo "Environement variable DISCORD_TOKEN already exists! Please clear it before proceeding to installation of the bot."
exit 1
fi
echo -e "DISCORD_TOKEN=$token\n" >> ~/bashrc_testing
#configuring the bot
echo "Applying configuration."
base_path="$name/src/"
settings_path="$name/src/settings.py"
if [[ ! -z $prefix ]]; then
echo "yup"
sed -i "s/PREFIX\(.*\)/PREFIX = '$prefix'/" $settings_path #-i is not standard POSIX, merely GNU sed
fi
if [[ ! -z $home_url ]]; then
sed -i "s/WEBSITE\(.*\)/WEBSITE = '$home_url'/" $settings_path
fi
if ! command -v python3 &> /dev/null; then
echo "Python3 is a required dependency of the bot. If you are sure you have it make sure it points to python3"
exit 1
fi
echo "Making python dpy virtual environement."
python3 -m venv $name/dpy
source $name/dpy/bin/activate
echo "Installing dependencies."
python3 -m pip install -r $base_path/requirements.txt
deactivate
echo "Finished installing $name. To start it run: source $name/dpy/bin/activate && python3 $base_path/main.py"
exit 0