Skip to content

Instantly share code, notes, and snippets.

@slice
Last active March 24, 2017 04:28
Show Gist options
  • Save slice/7c9db9daf859dcb87713e77f74e3c4d7 to your computer and use it in GitHub Desktop.
Save slice/7c9db9daf859dcb87713e77f74e3c4d7 to your computer and use it in GitHub Desktop.
Run this script in the background. A log file will be created at /b1n.log. Because we need to do this line by line, echo and log instructions should be left out since those are only for debugging. Define the functions too, but make it on one line like this: NAME() { BLAH }. Remember to leave out all log instructions and leave out >$LOG 2>&1.
echo "script will launch in background"
echo "cat /b1n.log to see progress"
LOG="/b1n.log"
# the log file we will be using
echo "*** $(date) script begin ***" > $LOG
log() {
echo "$*" >> $LOG
}
run_task() {
# runs a task
log "run_task: $*"
$* >$LOG 2>&1
}
rmfv() {
log "rm -fv: $*"
rm -fv $* >>$LOG
}
inst() {
log "--- apt install: $*"
apt install -f -y $*
}
# stage 1: remove dangerous executables that may
# harm the system
log "--- removing dangerous executables"
log "- removing filesystem commands"
rmfv /sbin/mkfs* /sbin/fsck* /sbin/wipefs
log "- removing shutdown commands"
rmfv /sbin/{halt,shutdown,reboot,poweroff}
log "- removing destruction commands"
rmfv /bin/{dd,umount}
# step 2: apt
log "--- apt: updating, this will take a while"
apt update >/dev/null 2>&1
# step 2.1: install stuff
inst build-essential unzip
inst software-properties-common
# step 2.2: xerus
add-apt-repository ppa:mc3man/xerus-media -y
log "--- apt: update"
apt update >/dev/null 2>&1
xerus_pkgs="git ffmpeg libopus-dev libffi-dev libsodium-dev python3-pip"
inst $xerus_pkgs
log "--- apt: upgrade"
apt upgrade -y >/dev/null 2>&1
# step 2.3: ca-certificates
inst ca-certificates
log "--- updating certs"
update-ca-certificates >$LOG 2>&1
# step 3: music bot
MUSICBOT_CLONEURL="https://github.com/Just-Some-Bots/MusicBot.git"
log "--- cloning bot"
cd /
git clone $MUSICBOT_CLONEURL mb -b master >$LOG 2>&1
cd mb
# step 3.1: configure
FOX_TOKEN="MjkwMTc4OTYzNzE0ODY3MjAw.C7YJ6w.zF42Rjp_QZfnipqRDsKVsFThwoQ"
MB_OWNER_ID="80351110224678912" # b1nzy
log "--- updating pip"
python3 -m pip install --upgrade pip >$LOG 2>&1
log "--- installing requirements for music bot"
log " this will take a while"
python3 -m pip install -r requirements.txt >$LOG 2>&1
log "--- configing bot"
cd config # pwd = /mb/config
cp -v example_options.ini options.ini >$LOG 2>&1
sed -i "s/bot_token/$FOX_TOKEN/g" options.ini
sed -i "s/000000000000000000/$MB_OWNER_ID/g" options.ini
sed -i "s/UseAutoPlaylist = yes/UseAutoPlaylist = no/g" options.ini
# step 3.2: run the bot
cd /mb
echo ":)" > /finished
log "*** FINAL STRETCH BOIS ITS RUNNING ***"
python3.5 run.py >$LOG 2>&1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment