#!/bin/sh # Configs BINTARGETFILE="/usr/local/bin/helpim" SHARETARGETPATH="/usr/local/share/HelpIM" CONFTARGETPATH="/etc/HelpIM" LOGPATH="/var/log/HelpIM" HELPIMUSER="helpim" HELPIMGROUP="helpim" WWWUSER="www-data" ADMINGROUP="adm" # Do these automaticly change them if needed SCRIPTTARGETPATH=`python -c "import sys; [(a[:11] == '/usr/local/' and a[-14:] == '/site-packages' and sys.stdout.write(a+'\n')) for a in sys.path]"` SOURCEPATH=`dirname "$0"` # copy python scripts and compile them echo "Copying python scripts to $SCRIPTTARGETPATH" if ! cp -r "$SOURCEPATH/HelpIM" "$SCRIPTTARGETPATH"; then echo "Error while copying python scripts, aborting" exit 1 fi if ! chmod 755 "$SCRIPTTARGETPATH/HelpIM/bot/bot.py"; then echo "Error while setting rights on $SCRIPTTARGETPATH/HelpIM/bot/bot.py, aborting" exit 1 fi echo "Precompiling $SCRIPTTARGETPATH/HelpIM" if ! python -c "import compileall; compileall.compile_dir('$SCRIPTTARGETPATH/HelpIM', force=True, quiet=True)"; then echo "Error while compiling, aborting" exit 1 fi # htdocs to share echo "Copying resources to $SHARETARGETPATH" if [ ! -d "$SHARETARGETPATH" ]; then if ! mkdir "$SHARETARGETPATH"; then echo "Can't find or create $SHARETARGETPATH, aborting" exit 1 fi fi if ! cp -r "$SOURCEPATH/htdocs" "$SHARETARGETPATH"; then echo "Error while copying resources to $SHARETARGETPATH/htdocs, aborting" exit 1 fi # make user helpim if [ -z `id -un $HELPIMUSER` ]; then echo "Creating helpim user: $HELPIMUSER (group: $HELPIMGROUP)" addgroup --system $HELPIMGROUP adduser --system --ingroup $HELPIMGROUP --no-create-home --disabled-password $HELPIMUSER # make apache member of helpim group if ! usermod -a -G $HELPIMGROUP $WWWUSER; then echo "Error while adding $WWWUSER to $HELPIMGROUP, aborting" exit 1 fi fi # config to /etc if [ ! -d "$CONFTARGETPATH" ]; then echo "Creating configs in $CONFTARGETPATH" if ! mkdir "$CONFTARGETPATH"; then echo "Can't find or create $CONFTARGETPATH, aborting" exit 1 fi if ! cp "$SOURCEPATH/config/config.xml" "$CONFTARGETPATH"; then echo "Error while copying config to $CONFTARGETPATH/htdocs, aborting" exit 1 fi if ! cp -r "$SOURCEPATH/config/sites" "$CONFTARGETPATH"; then echo "Can not create $CONFTARGETPATH/sites, aborting" exit 1 fi # set rights to /etc/HelpIM/sites strict: the db passwords are in there if ! chmod 750 "$CONFTARGETPATH/sites"; then echo "Can not set rights of $CONFTARGETPATH/sites, aborting" exit 1 fi if ! chmod 640 "$CONFTARGETPATH/sites/localhost.xml"; then echo "Can not set rights of $CONFTARGETPATH/sites/localhost.xml, aborting" exit 1 fi if ! chown -R root:$HELPIMGROUP "$CONFTARGETPATH/sites"; then echo "Can not change ownership if $CONFTARGETPATH/sites, aborting" exit 1 fi fi # make /var/log/HelpIM if [ ! -d "$LOGPATH" ]; then echo "Creating $LOGPATH" if ! mkdir "$LOGPATH"; then echo "Can't find or create $LOGPATH, aborting" exit 1 fi if ! chown $HELPIMUSER:$ADMINGROUP "$LOGPATH"; then echo "Can not change ownership if $LOGPATH, aborting" exit 1 fi fi # make /usr/local/bin/helpim/HelpIM/bot/bot.py executable if ! chmod +x "$SCRIPTTARGETPATH/HelpIM/bot/bot.py"; then echo "Error while making $SCRIPTTARGETPATH/HelpIM/bot/bot.py executable" exit 1 fi # link /usr/local/bin/helpim to HelpIM/bot/bot.py if [ ! -f "$BINTARGETFILE" ]; then if ! ln -s "$SCRIPTTARGETPATH/HelpIM/bot/bot.py" "$BINTARGETFILE"; then echo "Error while linking $BINTARGETFILE, aborting" exit 1 fi fi # startup script naar /etc/init.d/ if [ ! -f "/etc/init.d/helpim" ]; then if ! cp "$SOURCEPATH/helpim_init.d" "/etc/init.d/helpim"; then echo "Error while creating, /etc/init.d/helpim, aborting" exit 1 fi update-rc.d helpim defaults 85 05 fi