#!/bin/bash # # install 2006-04-02, last edit 2008-08-13 # # script to install the junkview suite # # Copyright (C) 2006 Grant Coady GPLv2 # # home site: # # This script MUST be run as root from the directory the junkview # tarball was unpacked to, prior to using junkview. # ### user config ############################################################### # # codepath and datapath MUST be set in etc/junkview.conf prior to running # this installer for the first time, defaults are /usr/local and # /usr/local/share/junkview if [ -f /etc/junkview.conf ] then # if we have prior install, use /etc/junkview.conf codepath=$(awk '/^codepath/ {print $2}' /etc/junkview.conf) datapath=$(awk '/^datapath/ {print $2}' /etc/junkview.conf) else # else use tarball default codepath=$(awk '/^codepath/ {print $2}' etc/junkview.conf) datapath=$(awk '/^datapath/ {print $2}' etc/junkview.conf) fi # this example lets a semi-privileged user perform database updates BIN_OWNER="root:wheel" # bin and /etc/rc.s/rc.junkview DATA_OWNER="root:wheel" # data files # BIN_PERMS="775" DATA_PERMS="664" DDIR_PERMS="775" ### take care below here ###################################################### ME="install" if [ $(id -u) -ne 0 ] # must be root to run this script then printf "\n$ME: fatal: need to be root.\n\n" exit 1 fi DOT_CONF="/etc/junkview.conf" # configuration file DIR_SOURCE=$PWD # where user unpacked the tarball DIR_BIN="$codepath/bin" # user scripts DIR_RC_D="/etc/rc.d" # ip2cn-server start|stop script UNINSTALL="$DIR_BIN/junkview-uninstall.sh" # installer writes an uninstaller write_uninstall_header() { # start new uninstall script, note we make this a little difficult # to use by not supplying shebang nor marking executable printf "##\n## junkview uninstaller, written $(date)\n##\n##" \ > $UNINSTALL echo ' home site: ' \ >> $UNINSTALL printf "\necho \"\n uninstalling junkview, installed on $(date)\"\n" \ >> $UNINSTALL } write_uninstall_footer() { printf "\n#remove $DIR_BIN/junkview-uninstall.sh\n" >> $UNINSTALL printf "rm -f $DIR_BIN/junkview-uninstall.sh\n" >> $UNINSTALL printf "\necho \" Note:\t$DOT_CONF not removed\n\"\n" >> $UNINSTALL printf " $DIR_BIN:\n junkview-uninstall.sh\n" } write_junkview_conf() { # perhaps create a new /etc/junkview.conf, the slack way ;) printf "Install junkview:\n /etc:\n junkview.conf" if [ -r $DOT_CONF ] then cat $DIR_SOURCE/$DOT_CONF > $DOT_CONF.new echo ".new" else cat $DIR_SOURCE/$DOT_CONF > $DOT_CONF echo "" fi } copy_data_files() { # data files # make sure we have a destination data directory, copy data, chown it echo " $datapath:" [ ! -d $datapath ] && mkdir --parents $datapath chown $DATA_OWNER $datapath chmod $DDIR_PERMS $datapath cd $DIR_SOURCE/data for xx in * do echo " $xx" rm -f $datapath/$xx cp --preserve=timestamps $xx $datapath done chown $DATA_OWNER $datapath/* chmod $DATA_PERMS $datapath/* cd .. printf "\n# remove data files\nrm -rf $datapath\n" >> $UNINSTALL } copy_bin_files() { # bin scripts echo " $codepath/bin:" printf "\n#remove bin scripts\n" >> $UNINSTALL cd $DIR_SOURCE/bin for xx in * do echo " $xx" rm -f $codepath/bin/$xx cp $xx $codepath/bin chown $BIN_OWNER $codepath/bin/$xx chmod $BIN_PERMS $codepath/bin/$xx echo rm -f $DIR_BIN/$xx >> $UNINSTALL done cd .. } copy_rc_junkview() { # rc.junkview echo " $DIR_RC_D:" rm -f $DIR_RC_D/rc.junkview echo " rc.junkview, rc.ip2cn-server" cp $DIR_SOURCE/rc.d/rc.junkview $DIR_RC_D chown $BIN_OWNER $DIR_RC_D/rc.junkview chmod $BIN_PERMS $DIR_RC_D/rc.junkview printf "\n#remove rc.junkview script\n" >> $UNINSTALL printf "$DIR_RC_D/rc.junkview stop\n" >> $UNINSTALL printf "rm -f $DIR_RC_D/rc.junkview\n" >> $UNINSTALL } copy_readme() { local docdir="$codepath/doc/junkview" printf " $docdir:\n README\n" [ ! -d "$docdir" ] && mkdir --parents $docdir chown $DATA_OWNER $docdir chmod $DDIR_PERMS $docdir cp -f $DIR_SOURCE/README $docdir chown $DATA_OWNER $docdir/README printf "\n#remove doc\nrm -rf $docdir\n" >> $UNINSTALL } write_uninstall_header write_junkview_conf copy_data_files copy_bin_files copy_rc_junkview copy_readme write_uninstall_footer # perhaps update the database and kick ip2cn-server if [ "$codepath" == "/usr" ] then junkview-update-database echo " Next, you need to configure your iptables to log 'JLE' entries, see the README and other documentation. " else echo " Run 'junkview-update-database' as user to update the database and optionally start the ip2cn-server. After that, you need to configure your iptables to log 'JLE' entries, see the README and other documentation. " fi # end