Skip to content

Commit

Permalink
Merge pull request #14 from aurumbot/development
Browse files Browse the repository at this point in the history
Merge Development to Master for v1.1.0
  • Loading branch information
Whitman Huntley authored Sep 28, 2018
2 parents 04b06eb + e165b21 commit e92b169
Showing 1 changed file with 80 additions and 15 deletions.
95 changes: 80 additions & 15 deletions goaurum
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,14 @@

# a 300+ line bodge.

# The one line of code that gets updated.
au_latestversion="v1.0.1"

_start() {
if [ -z `grep "NAME=\"$1\"" $HOME/.aurumfile` ] ; then echo "$1 not found." ; exit 1 ; fi
pid=`ps -eo "pid,ucomm" | grep "[0-9]\s.$1" | perl -pe 's/^[\s]+//g' | perl -pe 's/[\s].+//g'`
if [ ! -z $pid ] ; then echo "$1 appears to be already running at $pid." ; exit 0 ; fi
path=`grep "NAME=\"$1\"" $HOME/.aurumfile | perl -pe "s/^NAME=\"$1\":PATH=\"|\"$//g"`
cd $path
nohup ./.$1 &
rm './dat/logs/nohup.out' >> /dev/null 2>&1
nohup ./.$1 >./dat/logs/nohup.out 2>&1 &
if [ $? -ne 0 ] ; then echo "Failed to start up $1" ; else echo "Started up $1." ; fi
cd -
}
Expand Down Expand Up @@ -50,6 +48,61 @@ _remove() {
echo "Successfully removed $1 from the database."
}

_update() {
mkdir $HOME/.autmp
cd $HOME/.autmp
if [ ! -z "$2" ] ; then
git clone --branch $2 https://github.com/aurumbot/core.git
else
git clone https://github.com/aurumbot/core.git
fi
if [ "$1" = "--goaurum" ] ; then
touch auupdate ; chmod +x auupdate
cat > auupdate << EOF
#!/bin/bash
sleep 5
rm /usr/local/bin/goaurum
mv ./core/goaurum /usr/local/bin/
chmod +x /usr/local/bin/goaurum
/usr/local/bin/goaurum goaurumupdatefinalize
EOF
echo "Preparing to update goaurum. Note that this may take a bit"
echo "It also appears to stop the updater, this is normal. Please wait for"
echo "a short while (30 seconds?) for it to update, then try goaurum again."
./auupdate & >> /dev/null 2>&1
exit 0
fi
path=`grep "NAME=\"$1\"" $HOME/.aurumfile | perl -pe "s/^NAME=\"$1\":PATH=\"|\"$//g"`
if [ -z "$path" ] ; then
echo "$1 not found."
exit 1
fi
_stop $1 > /dev/null 2>&1
rm $path/.$1
env CGO_ENABLED=1 GO111MODULE=on go build -o $path/.$1 ./main.go
if [ "$?" -ne "0" ] ; then exit 1 ; else echo "Successfully updated $1." ; fi
}

_goaurumupdatefinalize() {
rm -rf $HOME/.autmp > /dev/null 2>&1
echo "Updates installed! (I hope)"
}

_installplugin() {
cd $2
path=`grep "NAME=\"$1\"" $HOME/.aurumfile | perl -pe "s/^NAME=\"$1\":PATH=\"|\"$//g"`
./build
if [ $? -ne 0 ] ; then exit 1 ; fi
pluginname=`ls ./bin | perl -pe "s/\.so$//g"`
mv ./bin/* $path/plugins/
if [ -d ./json ] ; then
mkdir $path/dat/cfg/$pluginname
mv ./json/* $path/dat/cfg/$pluginname
fi
echo "Compiled and installed plugin to $1."
cd - >> /dev/null
}

_list() {
name=`grep "^NAME=\".*\"" $HOME/.aurumfile | perl -pe "s/^NAME=\"|\":PATH=\".*\"$//g" ; printf "\n"`
echo $name
Expand Down Expand Up @@ -223,7 +276,7 @@ _install() {
echo "$au_name has been compiled. Finishing up."
# I'm sorry.

cat > ./dat/cfg/aurum/preferences.json << JsonEnd
cat > ./dat/cfg/aurum/preferences.json << EOF
{
"clientID": "$au_cid",
"secret": "$au_sec",
Expand All @@ -239,7 +292,7 @@ _install() {
""
]
}
JsonEnd
EOF
# ok its over.
rm -rf ./handler
rm go.mod
Expand All @@ -257,25 +310,37 @@ _help() {
printf "\033[1;31mUsage: \033[1;33mgoaurum <option>
\033[0mThe config tool and managment tool for aurum discord bots.
\n\033[1;31mOptions:
\033[1;32minit \033[0mfetch system dependancies (golang, perl)
\033[1;32minstall \033[0mcreate an instance of aurum
\033[1;32mstart <name> \033[0mstart the aurum bot called <name>
\033[1;32mstop <name> \033[0mstop the aurum bot called <name>
\033[1;32mlist \033[0mlist all aurum instances
\033[1;32mremove <name> \033[0mremove the bot <name> from the database
\033[1;32mindex <name> <path> \033[0madd a pre-existing instance of aurum to
the manager. Also used to fix broken paths.\n"
\033[1;32minit \033[0mfetch system dependancies (golang, perl)
\033[1;32minstall \033[0mcreate an instance of aurum
\033[1;32mstart <name> \033[0mstart the aurum bot called <name>
\033[1;32mstop <name> \033[0mstop the aurum bot called <name>
\033[1;32minstallplugin <name> <path> \033[0minstall a plugin at <path> to the <name> bot.
\033[1;32mlist \033[0mlist all aurum instances
\033[1;32mremove <name> \033[0mremove the bot <name> from the database
\033[1;32mindex <name> <path> \033[0madd a pre-existing instance of aurum to
the manager. Also used to fix broken paths.
\033[1;32mupdate <bot> [version] \033[0mupdate the <bot> to version [version].
use --goaurum to update goaurum, leave [version]
blank for the most recent version.\n"
}

#---------------------------------

touch $HOME/.aurumfile

if [ 0 -ne `ls -l /usr/local/bin/goaurum > /dev/null 2>&1 ; echo $?` ] ; then
echo "goaurum needs to be in /usr/local/bin. Move it there and try again."
exit 1
fi

case "$1" in
"init") _init ;;
"install") _install ;;
"start") _start $2 ;;
"stop") _stop $2 ;;
"list") _list ;;
"index") _index $2 $3 ;;
"update") _update $2 $3 ;;
"installplugin") _installplugin $2 $3 ;;
"goaurumupdatefinalize") _goaurumupdatefinalize ;;
*) _help ;;
esac

0 comments on commit e92b169

Please sign in to comment.