From 3d29ecb8767d923f79b82566fd57b08db76b8fc5 Mon Sep 17 00:00:00 2001 From: Silvino Silva Date: Sat, 15 Oct 2016 01:31:34 +0100 Subject: tools revision --- tools/scripts/config-install.sh | 4 -- tools/scripts/install-nginx.sh | 24 ----------- tools/scripts/install-php.sh | 7 ---- tools/scripts/install-postgres.sh | 16 ------- tools/scripts/setup-gitolite.sh | 43 +++++++++++++++++++ tools/scripts/setup-nginx.sh | 24 +++++++++++ tools/scripts/setup-openssh.sh | 43 +++++++++++++++++++ tools/scripts/setup-php.sh | 7 ++++ tools/scripts/setup-postgresql.sh | 87 +++++++++++++++++++++++++++++++++++++++ tools/scripts/system-iptables.sh | 6 +-- tools/scripts/system-qemu.sh | 65 ++++++++++++++++++++++++----- 11 files changed, 261 insertions(+), 65 deletions(-) delete mode 100644 tools/scripts/config-install.sh delete mode 100644 tools/scripts/install-nginx.sh delete mode 100644 tools/scripts/install-php.sh delete mode 100644 tools/scripts/install-postgres.sh create mode 100644 tools/scripts/setup-gitolite.sh create mode 100644 tools/scripts/setup-nginx.sh create mode 100644 tools/scripts/setup-openssh.sh create mode 100644 tools/scripts/setup-php.sh create mode 100644 tools/scripts/setup-postgresql.sh (limited to 'tools/scripts') diff --git a/tools/scripts/config-install.sh b/tools/scripts/config-install.sh deleted file mode 100644 index 061081f..0000000 --- a/tools/scripts/config-install.sh +++ /dev/null @@ -1,4 +0,0 @@ -#!/bin/sh - -CONF_DIR="$(dirname `dirname $0`)/conf" -echo "CONF_DIR=$CONF_DIR\n" diff --git a/tools/scripts/install-nginx.sh b/tools/scripts/install-nginx.sh deleted file mode 100644 index decacc1..0000000 --- a/tools/scripts/install-nginx.sh +++ /dev/null @@ -1,24 +0,0 @@ -#!/bin/sh - -. `dirname $0`/config-install.sh - -prt-get depinst nginx - -cp -R $CONF_DIR/etc/nginx/* /etc/nginx/ - -mkdir /srv/www -chown nginx:www /srv/www - -usermod -a -G www nginx -usermod -m -d /srv/www nginx - -openssl genrsa -des3 -out /etc/ssl/keys/nginx.key 2048 -openssl req -new -key /etc/ssl/keys/nginx.key -out /etc/ssl/certs/nginx.csr -openssl x509 -req -days 365 \ - -in /etc/ssl/certs/nginx.csr \ - -signkey /etc/ssl/keys/nginx.key \ - -out /etc/ssl/certs/nginx.crt - -cp /etc/ssl/keys/nginx.key /etc/ssl/keys/nginx.key.pass -openssl rsa -in /etc/ssl/keys/nginx.key.pass -out /etc/ssl/keys/nginx.key - diff --git a/tools/scripts/install-php.sh b/tools/scripts/install-php.sh deleted file mode 100644 index 4c28173..0000000 --- a/tools/scripts/install-php.sh +++ /dev/null @@ -1,7 +0,0 @@ -#!/bin/sh - -. `dirname $0`/config-install.sh - -prt-get depinst php php-fpm php-gd php-pdo-pgsql php-postgresql - -cp /etc/php/php.ini-development /etc/php/php.ini diff --git a/tools/scripts/install-postgres.sh b/tools/scripts/install-postgres.sh deleted file mode 100644 index 06666e0..0000000 --- a/tools/scripts/install-postgres.sh +++ /dev/null @@ -1,16 +0,0 @@ -#!/bin/sh - -. `dirname $0`/config-install.sh - -prt-get depinst postgresql - -cp -R $CONF_DIR/etc/rc.d/postgresql /etc/rc.d/ - -mkdir /srv/pgsql/ -touch /var/log/postgresql -chown postgres:postgres /srv/pgsql /var/log/postgresql - -sudo -u postgres initdb -D /srv/pgsql/data - -cp $CONF_DIR/srv/pgsql/data/pg_hba.conf /srv/pgsql/data/ -chown postgres:postgres /srv/pgsql/data/pg_hba.conf diff --git a/tools/scripts/setup-gitolite.sh b/tools/scripts/setup-gitolite.sh new file mode 100644 index 0000000..c42db14 --- /dev/null +++ b/tools/scripts/setup-gitolite.sh @@ -0,0 +1,43 @@ +#!/bin/sh + +# First we define the function +ConfirmOrExit () +{ + while true + do + echo -n "Please confirm (y or n) :" + read CONFIRM + case $CONFIRM in + y|Y|YES|yes|Yes) break ;; + n|N|no|NO|No) + echo "Aborting - you entered $CONFIRM" + exit + ;; + *) echo "Please enter only y or n" + esac + done + echo "You entered $CONFIRM. Continuing ..." +} + + +# Absolute path to this script, e.g. /home/user/bin/foo.sh +SCRIPT=$(readlink -f "$0") +# Absolute path this script is in, thus /home/user/bin +SCRIPTPATH=$(dirname "$SCRIPT") + +DIR=$(dirname "$SCRIPTPATH"); +DIR_CONF=$DIR"/conf" + +echo "SCRIPT=$SCRIPT"; +echo "SCRIPTPATH=$SCRIPTPATH"; +echo "DIR=$DIR"; +echo "DIR_CONF=$DIR_CONF"; +ConfirmOrExit + + prt-get depinst gitolite + + mkdir -p /srv/gitolite + useradd -U -d /srv/gitolite gitolite + chown gitolite:gitolite /srv/gitolite + +exit 0; diff --git a/tools/scripts/setup-nginx.sh b/tools/scripts/setup-nginx.sh new file mode 100644 index 0000000..decacc1 --- /dev/null +++ b/tools/scripts/setup-nginx.sh @@ -0,0 +1,24 @@ +#!/bin/sh + +. `dirname $0`/config-install.sh + +prt-get depinst nginx + +cp -R $CONF_DIR/etc/nginx/* /etc/nginx/ + +mkdir /srv/www +chown nginx:www /srv/www + +usermod -a -G www nginx +usermod -m -d /srv/www nginx + +openssl genrsa -des3 -out /etc/ssl/keys/nginx.key 2048 +openssl req -new -key /etc/ssl/keys/nginx.key -out /etc/ssl/certs/nginx.csr +openssl x509 -req -days 365 \ + -in /etc/ssl/certs/nginx.csr \ + -signkey /etc/ssl/keys/nginx.key \ + -out /etc/ssl/certs/nginx.crt + +cp /etc/ssl/keys/nginx.key /etc/ssl/keys/nginx.key.pass +openssl rsa -in /etc/ssl/keys/nginx.key.pass -out /etc/ssl/keys/nginx.key + diff --git a/tools/scripts/setup-openssh.sh b/tools/scripts/setup-openssh.sh new file mode 100644 index 0000000..14afe8b --- /dev/null +++ b/tools/scripts/setup-openssh.sh @@ -0,0 +1,43 @@ +#!/bin/sh + +# First we define the function +ConfirmOrExit () +{ + while true + do + echo -n "Please confirm (y or n) :" + read CONFIRM + case $CONFIRM in + y|Y|YES|yes|Yes) break ;; + n|N|no|NO|No) + echo "Aborting - you entered $CONFIRM" + exit + ;; + *) echo "Please enter only y or n" + esac + done + echo "You entered $CONFIRM. Continuing ..." +} + + +# Absolute path to this script, e.g. /home/user/bin/foo.sh +SCRIPT=$(readlink -f "$0") +# Absolute path this script is in, thus /home/user/bin +SCRIPTPATH=$(dirname "$SCRIPT") + +DIR=$(dirname "$SCRIPTPATH"); +DIR_CONF=$DIR"/conf" + +echo "SCRIPT=$SCRIPT"; +echo "SCRIPTPATH=$SCRIPTPATH"; +echo "DIR=$DIR"; +echo "DIR_CONF=$DIR_CONF"; +ConfirmOrExit + + + #installer overwrite system init script + cp -R $DIR_CONF/etc/ssh/sshd_config /etc/ssh/sshd_config + + sh /etc/rc.d/sshd start + +exit 0; diff --git a/tools/scripts/setup-php.sh b/tools/scripts/setup-php.sh new file mode 100644 index 0000000..4c28173 --- /dev/null +++ b/tools/scripts/setup-php.sh @@ -0,0 +1,7 @@ +#!/bin/sh + +. `dirname $0`/config-install.sh + +prt-get depinst php php-fpm php-gd php-pdo-pgsql php-postgresql + +cp /etc/php/php.ini-development /etc/php/php.ini diff --git a/tools/scripts/setup-postgresql.sh b/tools/scripts/setup-postgresql.sh new file mode 100644 index 0000000..4e1ee3a --- /dev/null +++ b/tools/scripts/setup-postgresql.sh @@ -0,0 +1,87 @@ +#!/bin/sh + +# First we define the function +ConfirmOrExit () +{ + while true + do + echo -n "Please confirm (y or n) :" + read CONFIRM + case $CONFIRM in + y|Y|YES|yes|Yes) break ;; + n|N|no|NO|No) + echo "Aborting - you entered $CONFIRM" + exit + ;; + *) echo "Please enter only y or n" + esac + done + echo "You entered $CONFIRM. Continuing ..." +} + + +# Absolute path to this script, e.g. /home/user/bin/foo.sh +SCRIPT=$(readlink -f "$0") +# Absolute path this script is in, thus /home/user/bin +SCRIPTPATH=$(dirname "$SCRIPT") + +DIR=$(dirname "$SCRIPTPATH"); +DIR_CONF=$DIR"/conf" + +echo "SCRIPT=$SCRIPT"; +echo "SCRIPTPATH=$SCRIPTPATH"; +echo "DIR=$DIR"; +echo "DIR_CONF=$DIR_CONF"; +ConfirmOrExit + +IS_INSTALL=$(prt-get isinst postgresql); +echo $IS_INSTALL; +if [ "$IS_INSTALL" = "package postgresql is installed" ] +then + echo "updating postgresql" + OLD_VERSION=$(prt-get current postgresql); + echo $OLD_VERSION; + + sudo -u postgres pg_dumpall > /srv/pgsql/dump-$OLD_VERSION.sql + + sh /etc/rc.d/postgresql stop + + #extra backup, in case ... + tar --xattrs -zcpf /srv/pgsql/data-$OLD_VERSION.tar.gz \ + --directory=/srv/pgsql/data . + + rm -R /srv/pgsql/data + + prt-get update postgresql + + NEW_VERSION=$(prt-get current postgresql); + echo $NEW_VERSION; + + sudo -u postgres initdb -D /srv/pgsql/data + + rejmerge + #installer overwrite system init script + cp -R $DIR_CONF/etc/rc.d/postgresql /etc/rc.d/ + + sh /etc/rc.d/postgresql start + sleep 5 + + sudo -u postgres psql -d postgres -f /srv/pgsql/dump-$OLD_VERSION.sql + +else + echo "install postgresql and dependencies" + prt-get depinst postgresql + + cp -R $DIR_CONF/etc/rc.d/postgresql /etc/rc.d/ + + mkdir /srv/pgsql/ + touch /var/log/postgresql + chown postgres:postgres /srv/pgsql /var/log/postgresql + + sudo -u postgres initdb -D /srv/pgsql/data + + cp $DIR_CONF/srv/pgsql/data/pg_hba.conf /srv/pgsql/data/ + chown postgres:postgres /srv/pgsql/data/pg_hba.conf +fi + +exit 0; diff --git a/tools/scripts/system-iptables.sh b/tools/scripts/system-iptables.sh index 4ec3b79..429efde 100644 --- a/tools/scripts/system-iptables.sh +++ b/tools/scripts/system-iptables.sh @@ -339,9 +339,9 @@ $IPT -A OUTPUT -o ${PUB_IF} -p tcp --sport 1024:65535 --dport 1024: -m state -- # $IPT -A OUTPUT -o ${PUB_IF} -p tcp --dport 2100 -j ACCEPT # $IPT -A OUTPUT -o ${PUB_IF} -p tcp --dport 9990 -j ACCEPT # -# echo "Allow wesnoth" -# $IPT -A OUTPUT -o ${PUB_IF} -p tcp --dport 15000 -m state --state NEW -j ACCEPT -# $IPT -A OUTPUT -o ${PUB_IF} -p tcp --dport 14998 -m state --state NEW -j ACCEPT + echo "Allow wesnoth" + $IPT -A OUTPUT -o ${PUB_IF} -p tcp --dport 15000 -m state --state NEW -j ACCEPT + $IPT -A OUTPUT -o ${PUB_IF} -p tcp --dport 14998 -m state --state NEW -j ACCEPT ##### END your rules ############ # Less log of known traffic diff --git a/tools/scripts/system-qemu.sh b/tools/scripts/system-qemu.sh index 8c68e70..489af5e 100644 --- a/tools/scripts/system-qemu.sh +++ b/tools/scripts/system-qemu.sh @@ -1,15 +1,58 @@ #!/bin/sh -ISO=~/crux-3.2.iso -IMG=~/crux-img.qcow2 -TAP=$1 +# First we define the function +ConfirmOrExit () +{ + while true + do + echo -n "Please confirm (y or n) :" + read CONFIRM + case $CONFIRM in + y|Y|YES|yes|Yes) break ;; + n|N|no|NO|No) + echo "Aborting - you entered $CONFIRM" + exit + ;; + *) echo "Please enter only y or n" + esac + done + echo "You entered $CONFIRM. Continuing ..." +} -echo "TAP: $TAP" +SCRIPT=$(readlink -f "$0") +# Absolute path this script is in, thus /home/user/bin +SCRIPTPATH=$(dirname "$SCRIPT") -qemu-system-x86_64 \ - -enable-kvm \ - -m 1024 \ - -boot d \ - -cdrom ${ISO} \ - -hda ${IMG} \ - -net nic,model=virtio -net tap,ifname=${TAP},script=no,downscript=no +DIR=$(dirname "$SCRIPTPATH"); +DIR_LOCAL="$(dirname $(dirname ${DIR}))/local"; + +MEM=$1 +TAP=$2 +ISO_FILE="${DIR_LOCAL}/$3" +IMG="${DIR_LOCAL}/$4" + +echo "MEM (512): $MEM" +echo "TAP (tap1): $TAP" +echo "ISO_FILE (crux-3.2.iso): $ISO_FILE" +echo "IMG (crux-img.qcow2): $IMG" +ConfirmOrExit + +if [ "$ISO_FILE" = "$DIR_LOCAL/" ] +then + qemu-system-x86_64 \ + -enable-kvm \ + -m $MEM \ + -boot c \ + -hda ${IMG} \ + -net nic,model=virtio -net tap,ifname=${TAP},script=no,downscript=no +else + qemu-system-x86_64 \ + -enable-kvm \ + -m $MEM \ + -boot d \ + -cdrom ${ISO_FILE} \ + -hda ${IMG} \ + -net nic,model=virtio -net tap,ifname=${TAP},script=no,downscript=no +fi + +exit 0; -- cgit