Skip to content

Commit 58e5215

Browse files
author
BuildTools
committed
Update
1 parent 2edb78f commit 58e5215

File tree

5 files changed

+70
-14
lines changed

5 files changed

+70
-14
lines changed

install.sh

+28-5
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,40 @@ basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')");
55
cd "$basedir";
66

77
# Install package dependencies
8-
echo >&2 "[SETUP] Installing package dependencies ...";
8+
echo "[SETUP] Installing package dependencies ...";
99
npm install;
1010

1111
# Copy the _config.ts file and rename it to config.ts if it does not exist
1212
if [ ! -f "config.ts" ] ; then
13-
echo >&2 "[SETUP] Config file not found! Copying ...";
14-
cp _config.ts config.ts;
13+
echo "[SETUP] Config file not found! Copying ...";
14+
cp template/_config.ts config.ts;
1515
fi
1616

1717
# Compile source code
18-
echo >&2 "[SETUP] Compiling source code ...";
18+
echo "[SETUP] Compiling source code ...";
1919
./node_modules/.bin/tsc;
2020

21-
echo >&2 "[SETUP] Done!";
21+
# Check if the bot already has a name
22+
if [ ! -f "bot.name" ]
23+
then
24+
# Name of the bot
25+
echo "";
26+
echo "In case you want to run more than one bot, you need to enter a unique name for each!";
27+
echo "If you are already running a different bot, make sure you give this one another name!";
28+
echo "";
29+
echo -n "How do you want to call this bot: ";
30+
read -r name;
31+
32+
# Make sure the name is valid
33+
while [ ! ${#name} -ge 1 ]
34+
do
35+
echo "Name invalid, try again: ";
36+
read -r name;
37+
done
38+
39+
# Safe the name in a file
40+
echo "[SETUP] Saving name ...";
41+
echo "$name" > bot.name;
42+
fi
43+
44+
echo "[SETUP] Done!";

restart.sh

+14-3
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,26 @@
44
basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')");
55
cd "$basedir";
66

7+
# Make sure the name file exists
8+
if [ ! -f "bot.name" ]
9+
then
10+
echo "[SETUP] Name file not found! Try running install.sh ...";
11+
exit;
12+
fi
13+
14+
# Get the name of the bot
15+
read -r name < bot.name;
16+
717
# Check if the bot is in the process list
8-
if ! pm2 list | grep MCRBot >/dev/null 2>&1 ; then
18+
if ! pm2 list | grep "$name" >/dev/null 2>&1
19+
then
920
sh start.sh
1021
else
1122
# Compile the typescript files to javascript
1223
./node_modules/.bin/tsc;
1324

1425
# Restart the bot
15-
pm2 restart MCRBot;
26+
pm2 restart "$name";
1627

17-
echo >&2 "[OK] MCRBot restarted!";
28+
echo >&2 "[OK] $name restarted!";
1829
fi

start.sh

+14-3
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,26 @@
44
basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')");
55
cd "$basedir";
66

7+
# Make sure the name file exists
8+
if [ ! -f "bot.name" ]
9+
then
10+
echo "[SETUP] Name file not found! Try running install.sh ...";
11+
exit;
12+
fi
13+
14+
# Get the name of the bot
15+
read -r name < bot.name;
16+
717
# Check if the bot is in the process list
8-
if pm2 list | grep MCRBot >/dev/null 2>&1 ; then
18+
if pm2 list | grep "$name" >/dev/null 2>&1
19+
then
920
sh restart.sh
1021
else
1122
# Compile the typescript files to javascript
1223
./node_modules/.bin/tsc;
1324

1425
# Start the bot
15-
pm2 start index.js --name MCRBot --time;
26+
pm2 start index.js --name "$name" --time;
1627

17-
echo >&2 "[OK] MCRBot started!";
28+
echo >&2 "[OK] "$name" started!";
1829
fi

stop.sh

+14-3
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,21 @@
44
basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')");
55
cd "$basedir";
66

7+
# Make sure the name file exists
8+
if [ ! -f "bot.name" ]
9+
then
10+
echo "[SETUP] Name file not found! Try running install.sh ...";
11+
exit;
12+
fi
13+
14+
# Get the name of the bot
15+
read -r name < bot.name;
16+
717
# Check if the bot is in the process list
8-
if pm2 list | grep MCRBot >/dev/null 2>&1 ; then
18+
if pm2 list | grep "$name" >/dev/null 2>&1
19+
then
920
# Stop the bot
10-
pm2 stop MCRBot;
21+
pm2 stop "$name";
1122

12-
echo >&2 "[OK] MCRBot stopped!";
23+
echo >&2 "[OK] "$name" stopped!";
1324
fi

_config.ts template/_config.ts

File renamed without changes.

0 commit comments

Comments
 (0)