Skip to content

Instantly share code, notes, and snippets.

@marcolino
Created November 7, 2013 14:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save marcolino/7355101 to your computer and use it in GitHub Desktop.
Save marcolino/7355101 to your computer and use it in GitHub Desktop.
Post Install for Centos (tested on 6.3)
#!/bin/bash
#
# Post-install script for a Linux Centos Server
#
# N.B.: tested on Centos 6.3
###################################################################################################
_()(set -o pipefail;"$@" 2>&1>&3|sed $'s,.*,\e[31m&\e[m,'>&2)3>&1 # point out errors prefix
err()(echo -e "\e[31m$1\e[m" 1>&2) # point out errors function
IP="`/sbin/ifconfig eth0 | grep 'inet addr:' | cut -d: -f2 | awk '{print $1}'`"; # current first network interface IP address
echo "Post-install script for Centos"
# check for root privileges
if [ "$(id -u)" != "0" ]; then
err "sorry, this script must be run as root"
exit 1
fi
# show and validate config
echo -e "\nCurrent config:"
source ./config # include config file
set +x
# let user confirm config
echo -ne "\nhit <Enter> to start, <Ctrl-C> to abort ... "; read answer; tput cuu1; tput el
# config checks
if [ "$installLibreoffice" -eq 1 -a "$installOpenoffice" -eq 1 ]; then
err -ne "selected for install both LibreOffice and OpenOffice; please select at most one."
exit 1
fi
# set system defaults
arch="`uname -i`"
if [ -z "$hostName" ]; then hostName="`hostname`"; fi
osVersion="`cat /etc/issue | perl -ne 'if ($_ =~ /release ([\d.]+)/) { print $1 }'`"
webserverUser="apache"
webserverGroup="apache"
# handle SELinux
if [ "$useSELinux" -eq 1 ]; then # enabling SELinux enforced (TODO: TO BE TESTED!!!)
echo "- configuring SELinux enforced..."
setenforce 1
sed -i "s/^SELINUX=disabled/SELINUX=enforced/" /etc/selinux/config
sed -i "s/^SELINUX=permissive/SELINUX=enforced/" /etc/selinux/config
setsebool -P httpd_can_network_connect 1
setsebool -P httpd_execmem 1
d="/var/www/cgi-bin/koor2p/"; if [ -d "$d" ]; then chcon -v -R --type=httpd_sys_content_t "$d"; fi
else # disable SELinux to avoid complexity
echo "- disabling SELinux..."
setenforce 0
sed -i "s/^SELINUX=enforcing/SELINUX=disabled/" /etc/selinux/config
sed -i "s/^SELINUX=permissive/SELINUX=disabled/" /etc/selinux/config
fi
# set requested locale
echo "- setting locale ${locale}..."
sed -i "s/^LANG=\".*\"/LANG=\"${locale}\"/" /etc/sysconfig/i18n
export LANG="${locale}"
# set hostname
echo "- setting hostname ${hostName}..."
sed -i "s/^HOSTNAME=.*/HOSTNAME=$hostName/" /etc/sysconfig/network
hostname "$hostName"
# activate networking (by default it's disabled...)
if [ -n "`grep '^ONBOOT=yes' /etc/sysconfig/network-scripts/ifcfg-eth0`" ]; then
: # networking already active
else
echo "- activating networking..."
_ perl -pi -e 's/^ONBOOT\s*=\s*.*?/ONBOOT=yes/' /etc/sysconfig/network-scripts/ifcfg-eth0
_ service network restart >/dev/null || exit
fi
# open requested ports on firewall
echo "- modifying firewall to allow access to ports ${firewallPorts}..."
_ cp /etc/sysconfig/iptables /etc/sysconfig/iptables-backup-$$
> /etc/sysconfig/iptables
cat >> /etc/sysconfig/iptables <<EOT
# Firewall configuration written by system-config-firewall
# Manual customization of this file is not recommended.
*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
-A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
-A INPUT -p icmp -j ACCEPT
-A INPUT -i lo -j ACCEPT
EOT
for port in $firewallPorts; do
cat >> /etc/sysconfig/iptables <<EOT
# allow inbound access to port ${port}
-A INPUT -m state --state NEW -m tcp -p tcp --dport $port -j ACCEPT
EOT
done
cat >> /etc/sysconfig/iptables <<EOT
# log dropped packages
#-N LOGGING
#-A INPUT -j LOGGING
#-A LOGGING -m limit --limit 2/min -j LOG --log-prefix "Dropped: " --log-level 4
#-A LOGGING -j DROP
-A INPUT -j REJECT --reject-with icmp-host-prohibited
-A FORWARD -j REJECT --reject-with icmp-host-prohibited
COMMIT
EOT
_ service iptables restart > /dev/null || exit
# remove identical backups
if [ "`md5sum /etc/sysconfig/iptables | cut -f1 -d' '`" = "`md5sum /etc/sysconfig/iptables-backup-$$ | cut -f1 -d' '`" ]; then
rm -f "/etc/sysconfig/iptables-backup-$$"
fi
# put our public key on source server
if [ ! -f /root/.ssh/id_rsa.pub ]; then
echo "- generating keys for root..."
rm -f /root/.ssh/id_rsa
_ ssh-keygen -t rsa -f /root/.ssh/id_rsa -N '' > /dev/null
echo "- copying public key to server $sourceServer..."
cat /root/.ssh/id_rsa.pub | ssh "root@$sourceServer" "mkdir -p ~/.ssh; cat >> ~/.ssh/authorized_keys"
fi
# add users
if [ -n "$users" ]; then
echo -n "- adding users: "
salt='KSWge%r~aNjg3q4$%'
gid="`getent group users | cut -d: -f3`"
sudoersfile="/etc/sudoers"
i=0; n=0
for userpass in $users; do
i=`expr $i + 1`
user=$(echo $userpass | cut -f1 -d:)
# set user as sudoer
sudoersline="$user ALL=(ALL) ALL"
if [ -z "`grep \"^$sudoersline$\" $sudoersfile`" ]; then
echo "$sudoersline" >> "$sudoersfile"
fi
if id -u "$user" >/dev/null 2>&1; then
: # user already exists, skip it...
else
pass=$(echo $userpass | cut -f2 -d:)
nextUID=`awk -vi="$i" -F: '($3>100) && ($3<50000) && ($3>max) { max=$3; } END { print max+i; }' /etc/passwd`
nextGID=$gid
passCrypted="`perl -e \"print crypt(\\"$pass\\", \\"$salt\\")\"`"
_ useradd -p "$passCrypted" -m "$user"
echo -ne "$user "
n=`expr $n + 1`
fi
done
if [ $n -le 0 ]; then
echo "all users already present"
else
echo
fi
fi
# install perl
if [ "$installPerl" -eq 1 ]; then
echo -ne "- installing Perl:"
_ yum install -y -q perl > /dev/null
_ yum install -y -q cpan > /dev/null # install CPAN + CPANM
_ curl -s -L http://cpanmin.us | perl - --self-upgrade > /dev/null # install CPAN + CPANM
echo "`perl --version | head -2 | tail -1 | cut -d, -f2`"
fi
# install perl CPAN modules
echo -n "- installing Perl CPAN modules: "
m='Development Tools'; echo -n "$m "; _ yum groupinstall -y -q "$m" > /dev/null 2>&1 | grep -v '^Warning'
m='perl-Pod-Escapes'; echo -n "$m "; _ yum install -y -q "$m" > /dev/null
m='perl-libs'; echo -n "$m "; _ yum install -y -q "$m" > /dev/null
m='perl-version'; echo -n "$m "; _ yum install -y -q "$m" > /dev/null
m='perl-Module-Pluggable'; echo -n "$m "; _ yum install -y -q "$m" > /dev/null
m='perl-Pod-Simple'; echo -n "$m "; _ yum install -y -q "$m" > /dev/null
m='perl-Locale-Maketext-Simple'; echo -n "$m "; _ yum install -y -q "$m" > /dev/null
m='perl-Params-Check'; echo -n "$m "; _ yum install -y -q "$m" > /dev/null
m='perl-Test-Harness'; echo -n "$m "; _ yum install -y -q "$m" > /dev/null
m='perl-ExtUtils-ParseXS'; echo -n "$m "; _ yum install -y -q "$m" > /dev/null
m='perl-devel'; echo -n "$m "; _ yum install -y -q "$m" > /dev/null
m='perl-ExtUtils-MakeMaker'; echo -n "$m "; _ yum install -y -q "$m" > /dev/null
m='perl-Module-Load'; echo -n "$m "; _ yum install -y -q "$m" > /dev/null
m='perl-Module-Load-Conditional'; echo -n "$m "; _ yum install -y -q "$m" > /dev/null
m='perl-IPC-Cmd'; echo -n "$m "; _ yum install -y -q "$m" > /dev/null
m='perl-Log-Message'; echo -n "$m "; _ yum install -y -q "$m" > /dev/null
m='perl-IO-Compress-Base'; echo -n "$m "; _ yum install -y -q "$m" > /dev/null
m='perl-Package-Constants'; echo -n "$m "; _ yum install -y -q "$m" > /dev/null
m='perl-Compress-Raw-Zlib'; echo -n "$m "; _ yum install -y -q "$m" > /dev/null
m='perl-IO-Compress-Zlib'; echo -n "$m "; _ yum install -y -q "$m" > /dev/null
m='perl-Compress-Zlib'; echo -n "$m "; _ yum install -y -q "$m" > /dev/null
m='perl-IO-Zlib'; echo -n "$m "; _ yum install -y -q "$m" > /dev/null
m='perl-Archive-Tar'; echo -n "$m "; _ yum install -y -q "$m" > /dev/null
m='perl-Log-Message-Simple'; echo -n "$m "; _ yum install -y -q "$m" > /dev/null
m='perl-Term-UI'; echo -n "$m "; _ yum install -y -q "$m" > /dev/null
m='perl-File-Fetch'; echo -n "$m "; _ yum install -y -q "$m" > /dev/null
m='perl-Archive-Extract'; echo -n "$m "; _ yum install -y -q "$m" > /dev/null
m='perl-Test-Simple'; echo -n "$m "; _ yum install -y -q "$m" > /dev/null
m='perl-ExtUtils-CBuilder'; echo -n "$m "; _ yum install -y -q "$m" > /dev/null
m='perl-Object-Accessor'; echo -n "$m "; _ yum install -y -q "$m" > /dev/null
m='perl-Module-Loaded'; echo -n "$m "; _ yum install -y -q "$m" > /dev/null
m='perl-Module-CoreList'; echo -n "$m "; _ yum install -y -q "$m" > /dev/null
m='perl-Digest-SHA'; echo -n "$m "; _ yum install -y -q "$m" > /dev/null
m='perl-Compress-Raw-Bzip2'; echo -n "$m "; _ yum install -y -q "$m" > /dev/null
m='perl-URI'; echo -n "$m "; _ yum install -y -q "$m" > /dev/null
m='perl-DBI'; echo -n "$m "; _ yum install -y -q "$m" > /dev/null
m='perl-DBIx-Simple'; echo -n "$m "; _ yum install -y -q "$m" > /dev/null
m='perl-DBD-SQLite'; echo -n "$m "; _ yum install -y -q "$m" > /dev/null
m='perl-IO-Compress-Bzip2'; echo -n "$m "; _ yum install -y -q "$m" > /dev/null
m='perl-CPAN'; echo -n "$m "; _ yum install -y -q "$m" > /dev/null
m='perl-Module-Build'; echo -n "$m "; _ yum install -y -q "$m" > /dev/null
m='perl-ExtUtils-Embed'; echo -n "$m "; _ yum install -y -q "$m" > /dev/null
m='perl-CGI'; echo -n "$m "; _ yum install -y -q "$m" > /dev/null
m='perl-XML-Simple'; echo -n "$m "; _ yum install -y -q "$m" > /dev/null
m='perl-JSON'; echo -n "$m "; _ yum install -y -q "$m" > /dev/null
m='perl-DBD-Pg'; echo -n "$m "; _ yum install -y -q "$m" > /dev/null
m='perl-DateTime'; echo -n "$m "; _ yum install -y -q "$m" > /dev/null
m='perl-Time-HiRes'; echo -n "$m "; _ yum install -y -q "$m" > /dev/null
m='Template'; echo -n "$m "; _ cpan "$m" > /dev/null
m='Config::IniFiles'; echo -n "$m "; _ cpan "$m" > /dev/null
m='Log::Log4perl'; echo -n "$m "; _ cpan "$m" > /dev/null
echo
# install, setup and start http daemon
if [ "$installHttpd" -eq 1 ]; then
echo -ne "- installing Httpd:"
_ yum install -y -q httpd > /dev/null
if [ `grep -c "^ServerName\s+" "/etc/httpd/conf/httpd.conf"` = 1 ]; then
sed -i "1s/^/ServerName $hostName\n\n/" /etc/httpd/conf/httpd.conf
fi
_ chkconfig httpd on
_ service httpd start > /dev/null || exit
echo "`httpd -V | head -1 | cut -d: -f2`"
fi
# install Libreoffice
if [ "$installLibreoffice" -eq 1 ]; then
echo -ne "- installing LibreOffice: "
#yum install -y -q libreoffice > /dev/null
_ yum install -y -q libreoffice-headless > /dev/null
echo "`soffice --version | head -1`"
fi
# install OpenOffice
if [ "$installOpenoffice" -eq 1 ]; then
echo -ne "- installing LibreOffice: "
pushd . > /dev/null
_ cd /tmp/
if [ "${serverArch}" = "x86_64" ]; then
ooArch="x86-64"
else
oo="${serverArch}"
fi
oo="Apache_OpenOffice_incubating_3.4.1_Linux_${ooArch}_install-rpm_en-US.tar.gz"
if [ ! -f "$oo" ]; then
_ wget -nv "http://sourceforge.net/projects/openofficeorg.mirror/files/stable/3.4.1/download/$oo"
fi
_ tar xzf "$oo"
_ cd "en-US/RPMS/"
_ rpm -i *.rpm
_ rpm -i desktop-integration/*-redhat-*
popd > /dev/null
echo "`soffice --version | head -1`"
fi
# install postgresql
if [ "$installPostgresql" -eq 1 ]; then
echo -ne "- installing PostgreSQL: "
confdir="/var/lib/pgsql/data/"
_ yum install -y -q postgresql postgresql-server postgresql-contrib > /dev/null
_ service postgresql initdb > /dev/null
if [ `grep -c "^listen_addresses\s+=\s+'\*'" "$confdir/postgresql.conf"` = 1 ]; then
echo "please add a line with \"listen_addresses = '*'\" (or = LAN MASK) in postgresql config file \"$confdir/postgresql.conf\" to remove access restrictions (hit <Enter> to continue...)"
read wait
vi '+/listen_addresses =' $confdir/postgresql.conf
fi
if [ `grep -c "^host\s+all\s+all\s+$dbAccessNetmask\s+trust$" "$confdir/pg_hba.conf"` = 1 ]; then
echo "please add a line like \"host all all $dbAccessNetmask trust\" to postgresql config file \"$confdir/pg_hba.conf\" to remove network restrictions (hit <Enter> to continue...)"
vi '+/^host' $confdir/pg_hba.conf
fi
_ service postgresql restart > /dev/null
_ chkconfig postgresql on
echo "`psql --version | head -1`"
fi
# install postgresql 9.1
if [ "$installPostgresql91" -eq 1 ]; then
echo -ne "- installing PostgreSQL 9.1: "
confdir="/var/lib/pgsql/9.1/data/"
_ rpm -i http://yum.postgresql.org/9.1/redhat/rhel-6-x86_64/postgresql91-server-9.1.8-2PGDG.rhel6.x86_64.rpm > /dev/null
_ rpm -i http://yum.postgresql.org/9.1/redhat/rhel-6-x86_64/postgresql91-9.1.8-2PGDG.rhel6.x86_64.rpm > /dev/null
_ rpm -i http://yum.postgresql.org/9.1/redhat/rhel-6-x86_64/pgadmin3_91-1.16.1-3.rhel6.x86_64.rpm > /dev/null
_ yum install -y -q postgresql91-server.x86_64 > /dev/null
_ yum install -y -q postgresql91.x86_64 > /dev/null
_ yum install -y -q pgadmin3_91.x86_64 > /dev/null
if [ `grep -c "^listen_addresses\s+=\s+'\*'" "$confdir/postgresql.conf"` = 1 ]; then
echo "please add a line with \"listen_addresses = '*'\" (or = LAN MASK) in postgresql config file \"$confdir/postgresql.conf\" to remove access restrictions (hit <Enter> to continue...)"
read wait
vi '+/listen_addresses =' $confdir/postgresql.conf
fi
if [ `grep -c "^host\s+all\s+all\s+$dbAccessNetmask\s+trust$" "$confdir/pg_hba.conf"` = 1 ]; then
echo "please add a line like \"host all all $dbAccessNetmask trust\" to postgresql config file \"$confdir/pg_hba.conf\" to remove network restrictions (hit <Enter> to continue...)"
vi '+/^host' $confdir/pg_hba.conf
fi
_ service postgresql-9.1 initdb
_ service postgresql-9.1 start > /dev/null
_ service postgresql-9.1 status > /dev/null
_ chkconfig postgresql on
echo "`psql --version | head -1`"
fi
# install Cache' ODBC client
if [ "$installCacheODBC" -eq 1 ]; then
echo -ne "- installing Cache' ODBC client: "
# install prerequisite modules
_ yum install -y -q unixODBC > /dev/null
_ yum install -y -q ncompress > /dev/null
_ cpan DBD::ODBC > /dev/null
# download Cache' driver
#if [ $arch = "i386" ]; then cacheODBCDriver="Cache.5.0.21.ODBC-6408-linux"; fi
#if [ $arch = "x86_64" ]; then cacheODBCDriver="Cache.5.0.21.ODBC-6408-linuxamd64"; fi
######################################################################################
#if [ $arch = "i386" ]; then cacheODBCDriver="Cache.5.2.0.ODBC-329-lnxrhx86"; fi
#if [ $arch = "x86_64" ]; then cacheODBCDriver="Cache.5.2.0.ODBC-329-lnxrhamd64"; fi
######################################################################################
if [ $arch = "i386" ]; then cacheODBCDriver="cache.2013.1.1.ODBC-lnxrhx86"; fi
if [ $arch = "x86_64" ]; then cacheODBCDriver="cache.2013.1.1.ODBC-lnxrhx64"; fi
if [ -z "$cacheODBCDriver" ]; then
err "sorry, no Cache ODBC driver for architecture $arch"
else
pushd . > /dev/null
_ mkdir -p /opt/software/Cache && cd /opt/software/Cache
#_ wget -nv ftp://ftp.intersystems.com/pub/cache/odbc/5.2/$cacheODBCDriver.tar.Z
#_ wget -nv ftp://ftp.intersystems.com/pub/cache/odbc/5.0/$cacheODBCDriver.tar.Z
_ wget -q -nc ftp://ftp.intersystems.com/pub/cache/odbc/2013/$cacheODBCDriver.tar.gz
if [ $? -ne 0 ]; then
popd > /dev/null
err "$cacheODBCDriver can't be downloaded"
else
if [ -f "$cacheODBCDriver.tar.Z" ]; then
_uncompress -f "$cacheODBCDriver.tar.Z"
else
_ gunzip "$cacheODBCDriver.tar.gz"
fi
_ tar xf $cacheODBCDriver.tar
_ rm -f $cacheODBCDriver.tar
_ ./ODBCinstall > /dev/null
# install odbc config file
popd > /dev/null
if [ -f /etc/odbc.ini ]; then
_ cp /etc/odbc.ini /etc/odbc.ini-backup-$$
# remove identical backups
if [ "`md5sum /etc/odbc.ini | cut -f1 -d' '`" = "`md5sum /etc/odbc.ini-backup-$$ | cut -f1 -d' '`" ]; then
rm -f "/etc/odbc.ini-backup-$$"
fi
fi
_ cp odbc.ini /etc/odbc.ini
echo "$cacheODBCDriver"
fi
# test cache' ODBC
echo -ne "- testing Cache' ODBC client: "
pushd . > /dev/null
cd /opt/software/Cache/dev/odbc/samples/select/
_ gcc select.c -lodbc -o select
export ODBCINI=/opt/software/Cache/mgr/cacheodbc.ini
export LD_LIBRARY_PATH=/opt/software/Cache/bin
if [ -n "`echo 'select * from sample.person where ID = 1' | ./select Samples | grep 'Peterson,Filomena O.'`" ]; then
echo "passed"
else
err "failed"
exit 1
fi
popd > /dev/null
fi
fi
# install Oracle client
if [ "$installOracleClient" -eq 1 ]; then
echo -ne "- installing Oracle client: "
_ cpan DBD::Oracle > /dev/null
_ rsync -r --ignore-existing root@${sourceServer}:/opt/oracle/${arch} /tmp/oracle/ # download oracle drivers
oracleClientVersion="`ls /tmp/oracle/${arch} | sort | tail -1`" # greatest dir name inside '/tmp/oracle/' subdir
# install prerequisite modules
rpm -qa | grep "oracle-instantclient.*-basic.*.${arch}" > /dev/null
if [ $? -eq 1 ]; then # not installed, install it
_ rpm -i /tmp/oracle/${arch}/${oracleClientVersion}/oracle-instantclient*-basic*.${arch}.rpm > /dev/null
fi
rpm -qa | grep "oracle-instantclient.*-devel.*.${arch}" > /dev/null
if [ $? -eq 1 ]; then # not installed, install it
_ rpm -i /tmp/oracle/${arch}/${oracleClientVersion}/oracle-instantclient*-devel*.${arch}.rpm > /dev/null
fi
rpm -qa | grep "oracle-instantclient.*-sqlplus.*.${arch}" > /dev/null
if [ $? -eq 1 ]; then # not installed, install it
_ rpm -i /tmp/oracle/${arch}/${oracleClientVersion}/oracle-instantclient*-sqlplus*.${arch}.rpm > /dev/null
fi
echo $oracleClientVersion
# test oracle client library
echo -ne "- testing Oracle client: "
oracleClientBasePath=/usr/lib/oracle/${oracleClientVersion}
if [ "${arch}" = "i368" ]; then
export ORACLE_HOME=${oracleClientBasePath}/client
else
export ORACLE_HOME=${oracleClientBasePath}/client64
fi
export LD_LIBRARY_PATH=$ORACLE_HOME/lib
# add $hostName to /etc/hosts, if not present
if [ `egrep -c "^${IP}\s+${hostName}\s+${hostName}\.localhost\.localdomain$" "/etc/hosts"` = 0 ]; then
echo -e "\n${IP}\t${hostName}\t${hostName}.localhost.localdomain" >> "/etc/hosts"
fi
cat > /tmp/testOracleClient.pl <<EOT
#!/usr/bin/perl
#
# Test Oracle DBI connection
use strict;
use warnings;
use DBI;
my \$host = "192.168.10.31";
my \$port = "1521";
my \$sid = "KOINE";
my \$user = "IMS";
my \$pass = "bbeep";
my \$sql = "SELECT * FROM IMS.CCE WHERE ROWNUM<=1";
my \$dbh = DBI->connect("dbi:Oracle:host=\${host};sid=\${sid};port=\${port}", \$user, \$pass)
or die "couldn't connect to database: " . DBI->errstr;
my \$sth = \$dbh->prepare(\$sql)
or die "couldn't prepare statement: " . \$dbh->errstr;
\$sth->execute()
or die "couldn't execute statement: " . \$sth->errstr;
\$sth->fetchrow()
or die "couldn't execute fetch: " . \$sth->errstr;
if (\$sth->rows <= 0) {
die "no rows returned.";
}
print "passed" . "\n";
\$sth->finish;
\$dbh->disconnect;
exit 0;
EOT
_ perl /tmp/testOracleClient.pl
rm -f /tmp/testOracleClient.pl
fi
# install java (java is already installed on even the minimal Centos install)
echo -ne "- installing Java: ";
_ yum install java-openjdk > /dev/null
java -version 2>&1 | tr '\n' ' '; echo
# nstall samba and setup config
echo -ne "- installing Samba: "
_ yum install -y -q samba > /dev/null
_ cp /etc/samba/smb.conf /etc/samba/smb.conf-backup-$$
# build users group
group=''
for userpass in $users; do
user=$(echo $userpass | cut -f1 -d:)
group="$group $user"
done
_ cat > /etc/samba/smb.conf <<EOT
[global]
workgroup = KOINE
server string = Samba Server Version %v
log file = /var/log/samba/log.%m
max log size = 50
security = user
passdb backend = tdbsam
load printers = yes
cups options = raw
users = $group
[printers]
comment = All Printers
path = /var/spool/samba
browseable = no
guest ok = no
writable = no
printable = yes
[tmp]
comment = Tmp
path = /tmp
public = yes
writable = yes
printable = no
write list = @users
[logs]
comment = Logs
path = /var/log
public = yes
writable = no
printable = no
[software]
comment = Software
path = /opt/software
guest ok = yes
writable = no
create mask = 0664
directory mask = 0775
valid users = @users
write list = @users
EOT
if [ "`md5sum /etc/samba/smb.conf | cut -f1 -d' '`" = "`md5sum /etc/samba/smb.conf-backup-$$ | cut -f1 -d' '`" ]; then
rm -f "/etc/samba/smb.conf-backup-$$"
fi
# add users to samba configuration
for userpass in $users; do
user=$(echo $userpass | cut -f1 -d:)
pass=$(echo $userpass | cut -f2 -d:)
(echo ${pass}; echo ${pass}) | _ /usr/bin/smbpasswd -s -a ${user} > /dev/null
done
_ service smb restart > /dev/null
echo "`smbd --version`"
# install KLOS
if [ "$installKLOS" -eq 1 ]; then
echo -ne "- installing KLOS: "
# install KLOS core
echo -n "core "
dir="/opt/software/LibreOffice"
_ mkdir -p "$dir/tmp"
_ mkdir -p "$dir/opt/software/LibreOffice/output"
_ scp -r -q "root@${sourceServer}:$dir/doc" "$dir/"
_ scp -r -q "root@${sourceServer}:$dir/log" "$dir/"
_ scp -r -q "root@${sourceServer}:$dir/RunMacro.jar" "$dir/"
_ scp -r -q "root@${sourceServer}:$dir/input" "$dir/"
_ scp -r -q "root@${sourceServer}:$dir/template" "$dir/"
_ scp -r -q "root@${sourceServer}:$dir/tmp" "$dir/"
_ scp -r -q "root@${sourceServer}:$dir/uty" "$dir/"
_ chown $webserverUser.users "$dir/input/" -R
_ chown $webserverUser.users "$dir/template/" -R
_ chown $webserverUser.users "$dir/tmp/" -R
_ chown $webserverUser.users "$dir/output/" -R
_ chmod g+rw /opt/software/ -R
# install KLOS html
echo -n "KLOS-html "
dir="/var/www/html/koine"
_ mkdir -p "$dir/"
#_ scp -r -q "root@${sourceServer}:/var/www/libreoffice" "$dir/"
_ scp -r -q "root@${sourceServer}:$dir" "$dir/"
_ chown $webserverUser.users "$dir/test" -R
#_ chmod 755 .
# install KLOS cgi
echo -n "cgi "
dir="/var/www/cgi-bin/libreoffice"
_ mkdir -p "$dir/"
_ scp -q "root@$sourceServer:/usr/lib/cgi-bin/libreoffice/app.ini" "$dir/"
_ scp -q "root@$sourceServer:/usr/lib/cgi-bin/libreoffice/log.conf" "$dir/"
_ scp -q "root@$sourceServer:/usr/lib/cgi-bin/libreoffice/runmacro.pl" "$dir/"
_ chown $webserverUser.users "$dir/" -R
_ chmod 755 "$dir/"
_ chmod a+x "$dir/"*.pl
_ chmod g+rw /opt/software/ -R
# write "app.ini"
_ cat > "$dir/app.ini" <<EOT
[GENERALE]
LOG_CONFIG_FILE=./log.conf
[DATABASE]
dsn=dbi:Pg:host=$dbHost;port=$dbPort;dbname=$dbName
usr=$dbUser
pwd=$dbPassword
EOT
dir="/var/www/cgi-bin/ksearch"
_ scp -r -q "root@$sourceServer:/usr/lib/cgi-bin/ksearch" /var/www/cgi-bin/
_ chmod 755 "$dir/"
_ chown $webserverUser.users "$dir/" -R
_ cp /var/www/cgi-bin/libreoffice/app.ini "$dir/" # copy libreoffice app.ini to ksearch ...
# set KLOS permissions
pushd . > /dev/null
cd /opt/software/LibreOffice/
_ ln -sf /var/www/html/libreoffice www
_ ln -sf /var/www/cgi-bin/libreoffice cgi
_ chmod a+x log
_ chmod 666 -f log/RunMacro.log
_ popd > /dev/null
_ mkdir -p /var/log/runmacro/
_ touch /var/log/runmacro/runmacro.log
_ chown $webserverUser.users /var/log/runmacro/runmacro.log
_ chgrp $webserverUser /var/www/
_ chmod g+w /var/www/
# install KLOS perl modules
echo -n "modules "
perlKSModulesSourceDirectory="/usr/local/lib/site_perl/"
perlKSModulesDirectory="/usr/share/perl5/vendor_perl"
_ mkdir -p ${perlKSModulesDirectory}
_ scp -r -q "root@${sourceServer}:${perlKSModulesSourceDirectory}/KS" "${perlKSModulesDirectory}"
# install libreoffice service script
echo -n "service "
_ scp -r -q root@${sourceServer}:/etc/init.d/libreoffice-svr /etc/init.d/libreoffice-svr
_ chmod a+x /etc/init.d/libreoffice-svr
_ chkconfig libreoffice-svr on
_ service libreoffice-svr start > /dev/null
# install KLOS database
echo -n "DB "
dbKeep=0
# check if database already exists...
if [ `su postgres -c "psql -l | grep \"$dbName\" | wc -l"` = 1 ]; then
echo
echo -ne " database <$dbName> already exists: drop it and re-install [y|N] ? "
read answer
if [ "$answer" = "Y" -o "$answer" = "y" ]; then
_ su postgres -c "psql --command \"
DROP DATABASE $dbName
\"" > /dev/null
if [ $? = 0 ]; then
echo " database <$dbName> dropped"
else
err "couldn't drop database <$dbName>!"
exit 1
fi
else
echo " database <$dbName> not modified"
dbKeep=1
fi
fi
if [ $dbKeep != 1 ]; then
if [ -z `su postgres -c "psql --command \"SELECT 1 FROM pg_roles WHERE rolname='oper'\"" | grep -q 1 && echo "y"` ]; then
_ su postgres -c "psql --command \"
CREATE ROLE $dbUser LOGIN PASSWORD '$dbPassword' SUPERUSER INHERIT CREATEDB CREATEROLE;
\"" > /dev/null
if [ $? = 0 ]; then
:
else
err "couldn't create role <$dbUser> for database <$dbName>!"
exit 1
fi
fi
_ su postgres -c "psql --command \"
CREATE DATABASE $dbName
WITH OWNER = $dbUser
TEMPLATE template0
ENCODING = '$dbEncoding'
TABLESPACE = $dbTablespace
LC_COLLATE = '$dbCollate'
LC_CTYPE = '$dbType'
CONNECTION LIMIT = -1;
\"" > /dev/null
if [ $? = 0 ]; then
echo " database <$dbName> created"
else
err "couldn't create database <$dbName>!"
exit 1
fi
if [ -f "$dbImportSqlFile" ]; then
_ su postgres -c "psql \"$dbName\" < $dbImportSqlFile" > /dev/null
if [ $? = 0 ]; then
echo
echo " database <$dbName> imported from file <$dbImportSqlFile>"
else
err "couldn't import database <$dbName>!"
exit 1
fi
else
err "couldn't find import file <$dbImportSqlFile>!"
exit 1
fi
fi
echo -ne "- testing KLOS: "
_ pushd . > /dev/null
cd /var/www/cgi-bin/libreoffice
rm -f "/opt/software/LibreOffice/output/testconn.pdf"
_ ./runmacro.pl --reportName=KLOSRCONN --outputFile=testconn
if [ -f "/tmp/semaphore.lock" ]; then # to allow web functionality
_ chmod a+rw "/tmp/semaphore.lock";
fi
if [ -f "/opt/software/LibreOffice/output/testconn.pdf" ]; then
if [ -n "`file /opt/software/LibreOffice/output/testconn.pdf | grep 'PDF document'`" ]; then
echo "passed"
else
err "error: output file is not a PDF document!"
exit 1
fi
else
err "error: no output file produced!"
exit 1
fi
_ popd > /dev/null
fi
# install Klosdash
if [ "$installKlosdash" -eq 1 ]; then
echo "- installing Klosdash..."
# install Klosdash cgi
dir="/var/www/cgi-bin/klosdash"
_ scp -r -q "root@${sourceServer}:$dir/" "$dir/"
_ chown $webserverUser.users "$dir/" -R
_ chmod 755 "$dir/"
_ chmod a+x "$dir/"*.pl
# install KLOS html
dir="/var/www/html/klosdash"
_ mkdir -p "$dir/"
_ scp -r -q "root@${sourceServer}:$dir" "$dir/"
_ chown $webserverUser.users "$dir/" -R
# # write "app.ini"
# _ cat > "$dir/app.ini" <<EOT
#EOT
fi
echo "- done."
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment