Skip to content

Instantly share code, notes, and snippets.

@that4chanwolf
Created May 10, 2012 13:25
Show Gist options
  • Save that4chanwolf/2652973 to your computer and use it in GitHub Desktop.
Save that4chanwolf/2652973 to your computer and use it in GitHub Desktop.
Another script for linux-shimeji
#!/bin/bash
# A script meant for controlling linux-shimeji
# Made by that4chanwolf
shimdir="/opt/linux-shimeji"
shimfilename="Shimeji.jar"
shimjar="${shimdir}/${shimfilename}"
extra="/tmp/linux-shimeji"
debugfile="${extra}/debug.txt"
shimpid="$(ps aux | grep -v grep | grep "${shimfilename}" | awk '{ print $2 }')"
comptonpid="$(ps aux | grep -v grep | grep compton | awk '{ print $2 }')"
currenttime=" $(date | awk '{print $4 ", on " $1 ", " $2 " " $3 ", " $6}')"
if [ ! -d "${extra}" ]; then
mkdir "${extra}"
fi
if [ ! -f "${debugfile}" ]; then
touch "${debugfile}"
fi
_testpid() {
if [ -z "${shimpid}" ]; then
echo 'Error: Shimeji not running, unable to kill proccess.'
echo 'Please start the script normally.'
echo 'Aborting...'
exit 1
fi
if [ -z "${comptonpid}" ]; then
echo 'Error: Compton not running, unable to kill proccess...'
echo 'Please run the script normally, or start compton seperately.'
echo 'Aborting...'
exit 1
fi
}
_start() {
echo 'Starting linux-shimeji...'
# Shimeji
java -jar "${shimjar}" >> "${debugfile}" & >/dev/null
echo "Starting linux-shimeji with a PID of $(ps aux | grep -v grep | grep ${shimfilename} | awk '{ print $2 }') : ${currenttime}" >> "${debugfile}" &
# Compton
compton >> "${debugfile}" & >/dev/null
echo "Starting compton with a PID of $(ps aux | grep -v grep | grep 'compton' | awk '{ print $2 }') : ${currenttime}" >> "${debugfile}" &
}
_stop() {
# First off, are the programs running?
_testpid
echo 'Stopping linux-shimeji...'
# Shimeji
kill "${shimpid}" >> "${debugfile}" & >/dev/null
# Compton
kill "${comptonpid}" >> "${debugfile}" & >/dev/null
}
_forcekill() {
echo 'Forcably killing linux-shimeji...'
killall java compton >> "${debugfile}" & >/dev/null
echo "linux-shimeji was forcably killed! : ${currenttime}" >> "${debugfile}" & >/dev/null
}
_restart() {
echo 'Restarting linux-shimeji...'
# Shimeji
kill "${shimpid}" >> "${debugfile}" & >/dev/null
java -jar "${shimjar}" >> "${debugfile}" & >/dev/null
# Compton
kill "${comptonpid}" >> "${debugfile}" & >/dev/null
compton >> "${debugfile}" & >/dev/null
}
_status() {
if [ -n "${shimpid}" ]; then
echo "Shimeji is currently running with a PID of ${shimpid}."
else
echo 'Shimeji is not currently running.'
fi
}
_usage() {
echo 'linux-shimeji by that4chanwolf'
echo 'Meant for quickly starting and stopping linux-shimeji'
echo 'Usage: linux-shimeji.sh (start|stop|restart|status|forcekill)'
}
_shimeji() {
case "$1" in
start)
_start;;
stop)
_stop;;
restart)
_restart;;
status)
_status;;
forcekill|force|kill|fk)
_forcekill;;
*)
_usage;;
esac
}
_shimeji "$@"
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment