#!/bin/bash if [ -f /lib/lsb/init-functions ]; then . /lib/lsb/init-functions else log_failure_msg() { echo "ERROR: $1"; } log_success_msg() { echo "SUCCESS: $1"; } fi f_control_cmd() { if eval $2 then log_success_msg "$1" else log_failure_msg "$1" fi } PATH=$PATH:/sbin:/usr/sbin/ check_pidfile() { ps -p $(cat $1 2>/dev/null) >/dev/null 2>&1 } P=$(dirname $0) if [ "$P" = "." ]; then P=$PWD; fi if [ "$CURDIR" = "" ] then CURDIR=$P fi # install all script under $ROOT ROOT=$CURDIR/root # use $BUILD_DIR for building from sources BUILD_DIR=$CURDIR/build # port for database server if [ "$PORT" = "" ] then DB_PORT=22345 else DB_PORT=$PORT fi # port for corba nameservice NS_PORT=$(($DB_PORT+1)) # port for pyfred corba backend PYFRED_PORT=$(($DB_PORT+2)) # port for rifd corba backend RIFD_PORT=$(($DB_PORT+3)) # port for pifd corba backend PIFD_PORT=$(($DB_PORT+4)) # port for adifd corba backend ADIFD_PORT=$(($DB_PORT+5)) # port for epp apache server EPP_PORT=$(($DB_PORT+6)) # port for unix whois apache server WHOIS_PORT=$(($DB_PORT+7)) # port for web administration interface WADMIN_PORT=$(($DB_PORT+8)) # port for web administration interface WEB_PORT=$(($DB_PORT+9)) # port for local named (bind) service NAMED_PORT=$(($DB_PORT+10)) # port for local named (bind) service PGPOOL_PORT=$(($DB_PORT+11)) # port for logd corba backend LOGD_PORT=$(($DB_PORT+12)) # path to pgpool executable PGPOOL_BIN=/usr/sbin/pgpool # path to named executable NAMED_BIN=/usr/sbin/named if [ ! -x $PGPOOL_BIN ] then PGPOOL_PORT=$DB_PORT fi PACKAGE_LIST="db idl pyfred server doc2pdf mod-corba mod-whoisd mod-eppd \ whois webadmin client" VERSION_1_10_0="1.9.0 1.10.0 1.9.1 1.10.1 1.4.1 1.3.0 2.2.0 1.7.0 1.10.4 2.1.1 1.6.1" VERSION_1_11_0="1.9.1 1.11.0 1.9.1 1.11.0 1.4.1 1.3.0 2.2.0 1.7.0 1.10.4 2.2.2 1.6.1" VERSION_2_0_0="2.1.0 2.0.1 2.0.1 2.0.8 2.0.0 1.3.0 3.0.1 2.0.2 2.0.1 3.0.4 2.0.4" VERSION_2_1_0="2.1.0 2.1.0 2.1.2 2.1.2 2.0.0 1.3.0 3.1.0 2.1.0 2.1.2 3.1.1 2.1.2" VERSION_2_1_1="2.1.1 2.1.0 2.1.3 2.1.7 2.0.1 1.3.0 3.1.1 2.1.0 2.1.2 3.1.2 2.1.3" VERSION_2_1_4="2.1.3 2.1.0 2.1.5 2.1.11 2.0.2 1.3.0 3.1.1 2.1.1 2.1.2 3.1.4 2.1.4" VERSION_2_1_5="2.1.4 2.1.1 2.1.8 2.1.18 2.0.3 1.3.0 3.1.1 2.1.1 2.1.6 3.1.6 2.1.5" VERSION_2_2_0="2.2.0 2.2.0 2.1.8 2.2.0 2.0.3 1.3.0 3.1.1 2.2.0 2.2.0 3.2.0 2.2.0" VERSION_BRANCHE_2_2="branches/2.2 branches/2.2 branches/2.1 branches/2.2 branches/2.0 branches/1.3 branches/3.1 branches/2.2 branches/2.2 branches/3.2 branches/2.2" if [ "$VERSION" = "" ]; then VERSION=2_2_0 # VERSION=TRUNK fi if [ $VERSION != TRUNK ]; then VERSION_LIST=$(eval echo \$VERSION_${VERSION}) fi #SPECIAL_VERSION="branches/2.1 branches/2.1 branches/2.1 branches/2.1 branches/2.0 branches/1.3 branches/3.1 branches/2.1 branches/2.1 branches/3.1 branches/2.1" if [ -d $CURDIR/download/src -a "$VERSION" != "TRUNK" ]; then SRC_DIR=$CURDIR/download/src RESULT="" VL=$VERSION_LIST for PACKAGE in $PACKAGE_LIST; do V="${VL%% *}" VL="${VL#* }" RESULT="${RESULT}fred-$PACKAGE-$V " done else SRC_DIR=$P/../../../ RESULT="" VL=$VERSION_LIST for PACKAGE in $PACKAGE_LIST; do V="${VL%% *}" VL="${VL#* }" if [ "$SPECIAL_VERSION" != "" ]; then HV="${SPECIAL_VERSION%% *}" SPECIAL_VERSION="${SPECIAL_VERSION#* }" RESULT="${RESULT}$PACKAGE/$HV " elif [ "$VERSION" = "BRANCHE_2_2" ]; then RESULT="${RESULT}$PACKAGE/$V " elif [ "$VERSION" = "TRUNK" ]; then RESULT="${RESULT}$PACKAGE/trunk " else RESULT="${RESULT}$PACKAGE/tags/$V " fi done fi # source directories of subprojects DB_SRC=$SRC_DIR/${RESULT%% *}; RESULT=${RESULT#* }; IDL_SRC=$SRC_DIR/${RESULT%% *}; RESULT=${RESULT#* }; PYFRED_SRC=$SRC_DIR/${RESULT%% *}; RESULT=${RESULT#* }; SERVER_SRC=$SRC_DIR/${RESULT%% *}; RESULT=${RESULT#* }; DOC2PDF_SRC=$SRC_DIR/${RESULT%% *}; RESULT=${RESULT#* }; MODCORBA_SRC=$SRC_DIR/${RESULT%% *}; RESULT=${RESULT#* }; MODWHOISD_SRC=$SRC_DIR/${RESULT%% *}; RESULT=${RESULT#* }; MODEPPD_SRC=$SRC_DIR/${RESULT%% *}; RESULT=${RESULT#* }; WHOIS_SRC=$SRC_DIR/${RESULT%% *}; RESULT=${RESULT#* }; WEBADMIN_SRC=$SRC_DIR/${RESULT%% *}; RESULT=${RESULT#* }; CLIENT_SRC=$SRC_DIR/${RESULT%% *}; RESULT=${RESULT#* }; FOUND=0 PGDIRDEB=$(ls -d /usr/lib/postgresql/*/bin/ 2>/dev/null| sort -r) for DB_BIN_F in $DB_BIN /usr/bin $PGDIRDEB do if [ -x $DB_BIN_F/pg_ctl ]; then FOUND=1; break; fi done if [ $FOUND -eq 0 ] then echo "PostgreSQL missing in $DB_BIN /usr/bin /usr/lib/postgresql/*/bin/"; exit 1 else DB_BIN=$DB_BIN_F fi FOUND=0 for APACHE_F in $APACHE /usr/sbin/apache2 /usr/sbin/httpd do if [ -x $APACHE_F ]; then FOUND=1; break; fi done if [ $FOUND -eq 0 ] then echo "Apache missing in $APACHE /usr/sbin/apache2 /usr/sbin/httpd"; exit 1 else APACHE=$APACHE_F fi FOUND=0 for APACHEDIR_F in $APACHEDIR /usr/lib/apache2/modules /usr/lib*/httpd/modules do if [ -f $APACHEDIR_F/mod_ssl.so ]; then FOUND=1; break; fi done if [ $FOUND -eq 0 ] then echo "SSL module missing in $APACHE_DIR " /usr/lib/apache2/modules \ /usr/lib*/httpd/modules exit 1 else APACHEDIR=$APACHEDIR_F fi OMNI=/usr/bin/omniNames if [ ! -x $OMNI ] then echo "OmniORB nameservice $OMNI not exits"; exit 1; fi export PGHOST=$ROOT/nofred/pg_sockets/ # hack for Ubuntu make_dir() { if [ ! -d $BUILD_DIR/$1 ] then mkdir $BUILD_DIR/$1 fi cd $BUILD_DIR/$1 } f_configure() { export CXXFLAGS='-g' # -=-=-=-=-=-=-=-=-=-=-=-= # prepare build dir # -=-=-=-=-=-=-=-=-=-=-=-= if [ ! -d $BUILD_DIR ] then mkdir $BUILD_DIR fi SAVE_PWD=$PWD # -=-=-=-=-=-=-=-=-=-=-=-= # configure fred-db # -=-=-=-=-=-=-=-=-=-=-=-= if [ "$1" = "db" -o "$1" = "" ] then make_dir fred-db RES=0 if grep -q "exit 0" config.log 2>/dev/null; then /bin/true; else $DB_SRC/configure \ --prefix=$ROOT \ --with-dbhost=$ROOT/nofred/pg_sockets \ --with-dbport=$DB_PORT \ --with-pgdatadir=$ROOT/nofred/pg \ --with-pghbadir=$ROOT/nofred/pg RES=$? fi cd $SAVE_PWD if [ $RES -ne 0 ]; then exit 1; fi fi # -=-=-=-=-=-=-=-=-=-=-=-= # configure fred-idl # -=-=-=-=-=-=-=-=-=-=-=-= if [ "$1" = "idl" -o "$1" = "" ] then make_dir fred-idl RES=0 if grep -q "exit 0" config.log 2>/dev/null; then /bin/true; else $IDL_SRC/configure \ --prefix=$ROOT RES=$? fi cd $SAVE_PWD if [ $RES -ne 0 ]; then exit 1; fi fi # -=-=-=-=-=-=-=-=-=-=-=-= # configure server # -=-=-=-=-=-=-=-=-=-=-=-= if [ "$1" = "server" -o "$1" = "" ] then make_dir fred-server RES=0 if grep -q "exit 0" config.log 2>/dev/null; then /bin/true; else $SERVER_SRC/configure \ --prefix=$ROOT \ --with-dbhost=$ROOT/nofred/pg_sockets \ --with-dbport=$PGPOOL_PORT \ --with-nshost=localhost \ --with-nsport=$NS_PORT \ --with-rifdport=$RIFD_PORT \ --with-pifdport=$PIFD_PORT \ --with-adifdport=$ADIFD_PORT \ --with-logdport=$LOGD_PORT \ --with-idldir=$IDL_SRC/idl RES=$? fi cd $SAVE_PWD if [ $RES -ne 0 ]; then exit 1; fi fi # -=-=-=-=-=-=-=-=-=-=-=-= # configure mod-corba # -=-=-=-=-=-=-=-=-=-=-=-= if [ "$1" = "mod-corba" -o "$1" = "" ] then make_dir fred-mod-corba RES=0 if grep -q "exit 0" config.log 2>/dev/null; then /bin/true; else $MODCORBA_SRC/configure \ --prefix=$ROOT RES=$? fi cd $SAVE_PWD if [ $RES -ne 0 ]; then exit 1; fi fi # -=-=-=-=-=-=-=-=-=-=-=-= # configure mod-whoisd # -=-=-=-=-=-=-=-=-=-=-=-= if [ "$1" = "mod-whoisd" -o "$1" = "" ] then make_dir fred-mod-whoisd RES=0 if grep -q "exit 0" config.log 2>/dev/null; then /bin/true; else $MODWHOISD_SRC/configure \ --prefix=$ROOT \ --with-nshost=localhost:$NS_PORT \ --with-port=$WHOIS_PORT \ --with-idldir=$IDL_SRC/idl RES=$? fi cd $SAVE_PWD if [ $RES -ne 0 ]; then exit 1; fi fi # -=-=-=-=-=-=-=-=-=-=-=-= # configure mod-eppd # -=-=-=-=-=-=-=-=-=-=-=-= if [ "$1" = "mod-eppd" -o "$1" = "" ] then make_dir fred-mod-eppd RES=0 if grep -q "exit 0" config.log 2>/dev/null; then /bin/true; else $MODEPPD_SRC/configure \ --prefix=$ROOT \ --with-nshost=localhost:$NS_PORT \ --with-port=$EPP_PORT \ --with-idldir=$IDL_SRC/idl RES=$? fi cd $SAVE_PWD if [ $RES -ne 0 ]; then exit 1; fi fi } f_install_local_named() { NAMED_PIDFILE=$ROOT/nofred/named/named.pid if [ ! -d $ROOT/nofred/named ]; then mkdir $ROOT/nofred/named chmod 775 $ROOT/nofred/named fi cat << _EOF_ > $ROOT/nofred/named/named.conf // sample bind configuration for FRED demonstration options { recursion no; pid-file "$NAMED_PIDFILE"; }; include "$ROOT/nofred/named/named_zones.conf"; _EOF_ touch $ROOT/nofred/named/named_zones.conf # cron job will be added when the service is started } f_named_add_cron() { # make sure that the added entry won't cause duplicity f_named_rem_cron echo "* * * * * ( $ROOT/bin/genzone_client -z $ROOT/nofred/named -f $ROOT/etc/fred/genzone.conf -g $ROOT/nofred/named/named_zones.conf -o; $CURDIR/$(basename $0) named_reload ) >> $ROOT/nofred/named/cron.log 2>&1 " | crontab - > /dev/null } f_named_rem_cron() { crontab -l | grep -v 'named_reload' | crontab - >/dev/null } f_install_a() { if [ "$1" = "$2" -o "$1" = "" ] then make_dir fred-$2 make install RES=$? cd $SAVE_PWD if [ $RES -ne 0 ]; then exit 1; fi fi } f_install_s() { if [ "$1" = "$2" -o "$1" = "" ] then make_dir fred-$2 python $3/setup.py install $4 2>&1 | tee install.log grep "Error" install.log >/dev/null 2>&1 # shouldn't be here RES=$(($? - 1)) cd $SAVE_PWD if [ $RES -ne 0 ]; then exit 1; fi fi } f_install_pgpool() { if [ -x $PGPOOL_BIN ] then mkdir -p $ROOT/nofred/pgpool > /dev/null cat << _EOF_ > $ROOT/nofred/pgpool/pgpool.conf #sample pgpool configuration file listen_addresses = '' port = $PGPOOL_PORT socket_dir = '$ROOT/nofred/pg_sockets' backend_port = $DB_PORT backend_socket_dir = '$ROOT/nofred/pg_sockets' logdir = '$ROOT/nofred/pgpool/' num_init_children = 32 max_pool = 4 _EOF_ fi } f_install() { # -=-=-=-=-=-=-=-=-=-=-=-= # create database cluster # -=-=-=-=-=-=-=-=-=-=-=-= if [ ! -d $ROOT/nofred/pg ] then $DB_BIN/initdb -D $ROOT/nofred/pg fi f_configure $1 if [ "$1" = "pgpool" -o "$1" = "" ] then f_install_pgpool fi f_install_a "$1" "db" f_install_a "$1" "idl" f_install_s "$1" "pyfred" $PYFRED_SRC " \ --prefix=$ROOT \ --dbhost=$ROOT/nofred/pg_sockets \ --dbport=$PGPOOL_PORT \ --nsport=$NS_PORT \ --pyfredport=$PYFRED_PORT" f_install_s "$1" "doc2pdf" $DOC2PDF_SRC " \ --prefix=$ROOT" f_install_a "$1" "server" f_install_a "$1" "mod-corba" f_install_a "$1" "mod-whoisd" f_install_a "$1" "mod-eppd" f_install_s "$1" "webadmin" $WEBADMIN_SRC " \ --prefix=$ROOT \ --nsport=$NS_PORT \ --webadminport=$WADMIN_PORT" f_install_s "$1" "client" $CLIENT_SRC " \ --prefix=$ROOT \ --port=$EPP_PORT" f_install_s "$1" "whois" $WHOIS_SRC " \ --prefix=$ROOT \ --host=localhost:$NS_PORT" # -=-=-=-=-=-=-=-=-=-=-=-= # prepare directories # -=-=-=-=-=-=-=-=-=-=-=-= mkdir -p $ROOT/nofred/pg_sockets/ >/dev/null 2>&1 mkdir -p $ROOT/nofred/sessiondb > /dev/null 2>&1 mkdir -p $ROOT/var/lib/fred-webadmin/sessions/ >/dev/null 2>&1 mkdir -p $ROOT/var/log > /dev/null 2>&1 mkdir -p $ROOT/var/www/html >/dev/null 2>&1 ln -s ../../../nofred/named/ $ROOT/var/www/html/zones >/dev/null 2>&1 # -=-=-=-=-=-=-=-=-=-=-=-= # prepare client package # -=-=-=-=-=-=-=-=-=-=-=-= if [ "$1" = "client-package" -o "$1" = "" ]; then make_dir fred-client-dist rm $ROOT/var/www/html/fred-client* python $CLIENT_SRC/setup.py bdist_simple --format=zip \ --install-extra-opts="--host=$(hostname) --port=$EPP_PORT" \ --dist-dir=$ROOT/var/www/html/ fi cd $SAVE_PWD # -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= # create apache configuation file # -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= if [ "$1" = "config" -o "$1" = "" ]; then if [ ! -f $APACHEDIR/mod_python.so ]; then echo "Need mod_python module. Exiting!"; exit 1; fi { echo "LoadModule ssl_module $APACHEDIR/mod_ssl.so" # next three modules are because of web whois apache config # they are builtin on ubuntu apache so test must be done if $APACHE -L | grep mod_dir > /dev/null 2>&1; then /bin/true; else echo "LoadModule dir_module $APACHEDIR/mod_dir.so"; fi if $APACHE -L | grep mod_alias > /dev/null 2>&1; then /bin/true; else echo "LoadModule alias_module $APACHEDIR/mod_alias.so"; fi if $APACHE -L | grep mod_mime > /dev/null 2>&1; then /bin/true; else echo "LoadModule mime_module $APACHEDIR/mod_mime.so"; fi echo "LoadModule python_module $APACHEDIR/mod_python.so" echo "TypesConfig /etc/mime.types" echo "PidFile $ROOT/nofred/apache.pid" echo "ErrorLog $ROOT/nofred/apache.log" cat $ROOT/share/fred-mod-corba/01-fred-mod-corba-apache.conf cat $ROOT/share/fred-mod-whoisd/02-fred-mod-whoisd-apache.conf cat $ROOT/share/fred-mod-eppd/02-fred-mod-eppd-apache.conf echo "Listen $WEB_PORT" cat $ROOT/share/doc/fred-whois/apache.conf # if modpython session database file already exist, it's usually # created in /tmp as a file owned by www-date and so # unaccessible by regular user. So next three options handle # this situation. They are three because od different name in # different mod_python versions echo -n "PythonOption mod_python.dbm_session.database_directory " echo "$ROOT/nofred/sessiondb" echo "PythonOption session_directory $ROOT/nofred/sessiondb" echo "PythonOption SessionDbm $ROOT/oldsession" # root for web echo "DocumentRoot $ROOT/var/www/html" } > $ROOT/nofred/apache.conf fi # -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= # create simple fred homepage # -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= if [ "$1" = "homepage" -o "$1" = "" ]; then { URL="http://$(hostname)" CLPCKG=$(basename $ROOT/var/www/html/fred-client*) echo "
" echo "" echo "whois -h $(hostname) -p $WHOIS_PORT QUERY" echo "" echo "To test EPP client call:" echo "
" echo -n "fred-client -h $(hostname) -p $EPP_PORT " echo "-u REG-FRED_A -w passwd" echo "" echo "or download, unpack and run prepared client " echo "package" echo "
Zone is generated every minute. To test generated " echo "zone using DNS protocol call:" echo "
dig AXFR cz @$(hostname) -p $NAMED_PORT" echo "
Or you can download generated zone using http protocol on following links: