Skip to content

Instantly share code, notes, and snippets.

@glagola
Created May 31, 2012 11:01
Show Gist options
  • Save glagola/2842667 to your computer and use it in GitHub Desktop.
Save glagola/2842667 to your computer and use it in GitHub Desktop.
google-chrome-optimizer
#! /bin/sh
### BEGIN INIT INFO
# Provides: skeleton
# Required-Start: $remote_fs $syslog
# Required-Stop: $remote_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Example initscript
# Description: This file should be used to construct scripts to be
# placed in /etc/init.d.
### END INIT INFO
# Author: Foo Bar <[email protected]>
#
# Please remove the "Author" lines above and replace them
# with your own name if you copy and modify this script.
# Do NOT "set -e"
# PATH should only include /usr/* if it runs after the mountnfs.sh script
PATH=/sbin:/usr/sbin:/bin:/usr/bin
DESC="google chrome speed optimizer"
NAME="google-chrome"
DAEMON=/usr/bin/$NAME
SCRIPT=google-chrome-speed-optimizer
SCRIPTNAME=/etc/init.d/$SCRIPT
SCRIPT_FOLDER=/tmp/$SCRIPT
TMP_CONFIG=/tmp/$SCRIPT/config/$NAME
TMP_CACHE=/tmp/$SCRIPT/cache/$NAME
USER_HOME=/home/ziv
CONFIG=$USER_HOME/.config/$NAME
CACHE=$USER_HOME/.cache/$NAME
# Exit if the package is not installed
[ -x "$DAEMON" ] || exit 0
[ -d "$CONFIG" ] || exit 0
[ -d "$CACHE" ] || exit 0
# Load the VERBOSE setting and other rcS variables
. /lib/init/vars.sh
clean_up()
{
umount $TMP_CONFIG
umount $TMP_CACHE
if [ -f $SCRIPT_FOLDER/done ]; then
if [ -d $TMP_CONFIG ]; then
cp -r $TMP_CONFIG $CONFIG
fi
if [ -d $TMP_CACHE ]; then
cp -r $TMP_CACHE $CACHE
fi
fi
rm -rf $SCRIPT_FOLDER
}
#
# Function that starts the daemon/service
#
do_start()
{
[ -d $TMP_CONFIG ] && return 1
[ -d $TMP_CACHE ] && return 1
mkdir -p $TMP_CONFIG
mkdir -p $TMP_CACHE
cp -r $CONFIG $TMP_CONFIG
cp -r $CACHE $TMP_CACHE
mount --bind $CONFIG $TMP_CONFIG
mount --bind $CACHE $TMP_CACHE
chown -R ziv:ziv $SCRIPT_FOLDER
if [ $? -ne 0 ]; then
clean_up
return 2
fi
# Return
# 0 if daemon has been started
# 1 if daemon was already running
# 2 if daemon could not be started
touch "$SCRIPT_FOLDER/done"
return 0
}
#
# Function that stops the daemon/service
#
do_stop()
{
clean_up
# Return
# 0 if daemon has been stopped
# 1 if daemon was already stopped
# 2 if daemon could not be stopped
return 0
}
case "$1" in
start)
[ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$SCRIPT"
do_start
case "$?" in
0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
esac
;;
stop)
[ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$SCRIPT"
do_stop
case "$?" in
0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
esac
;;
*)
echo "Usage: $SCRIPTNAME {start|stop}" >&2
exit 3
;;
esac
:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment