Commit 2ce19a30 authored by Igor Pecovnik's avatar Igor Pecovnik
Browse files

Installer rework, first commit.

parent bab034b7
#!/bin/bash
#
#
# (c) Igor Pecovnik
#
# Very basic stuff
apt-get -y -qq install dialog whiptail lsb-release
# gather some info
distribution=$(lsb_release -cs)
family=$(lsb_release -is)
serverIP=$(ip route get 8.8.8.8 | awk '{ print $NF; exit }')
set ${serverIP//./ }
SUBNET="$1.$2.$3."
hostnamefqdn=$(hostname -f)
mysql_pass=""
#distribution=$(lsb_release -i)" "$(lsb_release -cs)
function choose_webserver
{
dialog --title "Choose a webserver" \
--backtitle "Micro home server (c) Igor Pecovnik " \
--yes-label "Apache" \
--no-label "Nginx" \
--yesno "\nChoose a wenserver which you are familiar with. They both work almost the same." 8 70
response=$?
case $response in
0) server="apache";;
1) server="nginx";;
255) exit;;
esac
echo $server > /tmp/server
}
function server_conf
{
exec 3>&1
dialog --title "Server configuration" \
--separate-widget $'\n' --ok-label "Install" \
--backtitle "Micro home server (c) Igor Pecovnik " \
--form "\nPlease fill out this form:\n " \
12 70 0 \
"Your FQDN for $serverip:" 1 1 "$hostnamefqdn" 1 31 32 0 \
"Mysql root password:" 2 1 "$mysql_pass" 2 31 32 0 \
2>&1 1>&3 | {
read -r hostnamefqdn
read -r mysql_pass
echo $mysql_pass > /tmp/mysql_pass
echo $hostnamefqdn > /tmp/hostnamefqdn
choose_webserver
# end
}
exec 3>&-
# read variables back
mysql_pass=`cat /tmp/mysql_pass`
hostnamefqdn=`cat /tmp/hostnamefqdn`
server=`cat /tmp/server`
}
before_install ()
{
#--------------------------------------------------------------------------------------------------------------------------------
# What do we need anyway
#--------------------------------------------------------------------------------------------------------------------------------
apt-get update | dialog --backtitle "Micro home server (c) Igor Pecovnik " \
--progressbox "Force package list update ..." 20 70
apt-get -y upgrade | dialog --backtitle "Micro home server (c) Igor Pecovnik " \
--progressbox "Force upgrade ..." 20 70
apt-get -y autoremove | dialog --backtitle "Micro home server (c) Igor Pecovnik " \
--progressbox "Remove packages that are no more needed ..." 20 70
install_packet "debconf-utils dnsutils unzip build-essential alsa-base alsa-utils stunnel4 html2text apt-transport-https"\
"Downloading basic packages"
}
function what_to_install()
{
#--------------------------------------------------------------------------------------------------------------------------------
# Installation menu
#--------------------------------------------------------------------------------------------------------------------------------
DIALOG=${DIALOG=dialog}
tempfile=`tempfile 2>/dev/null` || tempfile=/tmp/test$$
trap "rm -f $tempfile" 0 1 2 5 15
$DIALOG --backtitle "Micro home server (c) Igor Pecovnik" \
--title "Installing to $family $distribution" --clear --checklist "\nChoose what you want to install:\n " 20 70 15 \
"Samba" "Windows compatible file sharing " off \
"TV headend" "TV streaming / proxy" off \
"Syncthing" "Personal cloud @syncthing.net" off \
"CUPS" "Printing" off \
"Scanner" "Control your scanner with buttons + OCR" off \
"Temper" "USB temperature sensor" off \
"Rpi monitor" "Status page and statistics" off \
"Transmission" "Torrent downloading" off \
"ISPConfig" "WWW, PHP, SQL, SMTP, IMAP, POP3" off 2> $tempfile
retval=$?
choice=`cat $tempfile`
case $retval in
0)
;;
1)
exit;;
255)
exit;;
esac
IFS=";"
choice="${choice//\" /;}"
choice="${choice//\"/}"
declare -a choice=($choice)
}
install_packet ()
{
#--------------------------------------------------------------------------------------------------------------------------------
# Install missing packets
#--------------------------------------------------------------------------------------------------------------------------------
i=0
j=1
IFS=" "
declare -a PACKETS=($1)
skupaj=${#PACKETS[@]}
while [[ $i -lt $skupaj ]]; do
procent=$(echo "scale=2;($j/$skupaj)*100"|bc)
x=${PACKETS[$i]}
if [ $(dpkg-query -W -f='${Status}' $x 2>/dev/null | grep -c "ok installed") -eq 0 ]; then
printf '%.0f\n' $procent | dialog \
--backtitle "Micro home server (c) Igor Pecovnik " \
--title "Installing" \
--gauge "\n$2\n\n$x" 10 70
if [ "$(DEBIAN_FRONTEND=noninteractive apt-get -qq -y install $x >/tmp/install.log 2>&1 || echo 'Installation failed' | grep 'Installation failed')" != "" ]; then
echo -e "[\e[0;31m error \x1B[0m] Installation failed"
tail /tmp/install.log
exit
fi
fi
i=$[$i+1]
j=$[$j+1]
done
echo ""
}
install_basic (){
#--------------------------------------------------------------------------------------------------------------------------------
# Set hostname, FQDN, add to sources list
#--------------------------------------------------------------------------------------------------------------------------------
if [ "$distribution" != "wheezy" ]; then
dialog --msgbox "This installation of ISPConfig works only on Wheezy." 7 70
exit 1
fi
IFS=" "
HOSTNAMEFQDN="server1.example.com"
HOSTNAMEFQDN=$(whiptail --inputbox "\nWhat is your full hostname?" 10 78 $HOSTNAMEFQDN --title "$serverIP" 3>&1 1>&2 2>&3)
exitstatus=$?; if [ $exitstatus = 1 ]; then exit 1; fi
set ${HOSTNAMEFQDN//./ }
HOSTNAMESHORT="$1"
cp /etc/hosts /etc/hosts.backup
cp /etc/hostname /etc/hostname.backup
sed -e 's/127.0.0.1 localhost/127.0.0.1 localhost.localdomain localhost/g' -i /etc/hosts
cat >> /etc/hosts <<EOF
${serverIP} ${HOSTNAMEFQDN} ${HOSTNAMESHORT}
EOF
sed -i '/#ispconfig/d' /etc/hosts
sed -e 's/127.0.0.1.*/127.0.0.1 localhost.localdomain localhost/g' -i /etc/hosts
echo "${serverIP} ${HOSTNAMEFQDN} ${HOSTNAMESHORT} #ispconfig " >> /etc/hosts
echo "$HOSTNAMESHORT" > /etc/hostname
/etc/init.d/hostname.sh start >/dev/null 2>&1
}
......@@ -138,17 +294,18 @@ cp TSL2561_test /usr/local/bin/tsl2561
install_tvheadend (){
#--------------------------------------------------------------------------------------------------------------------------------
# TVheadend
# TVheadend https://tvheadend.org/
#--------------------------------------------------------------------------------------------------------------------------------
if !(grep -qs tvheadend "/etc/apt/sources.list");then
cat >> /etc/apt/sources.list <<EOF
# TV headend
deb http://apt.tvheadend.org/stable wheezy main
EOF
if !(grep -qs tvheadend "/etc/apt/sources.list.d/tvheadend.list");then
echo "deb http://apt.tvheadend.org/stable wheezy main" >> /etc/apt/sources.list.d/tvheadend.list
wget -qO - http://apt.tvheadend.org/stable/repo.gpg.key | apt-key add -
fi
wget -qO - http://apt.tvheadend.org/stable/repo.gpg.key | apt-key add -
debconf-apt-progress -- apt-get update
debconf-apt-progress -- apt-get -y install tvheadend
apt-get update | dialog --progressbox "Force package list update ..." 20 70
install_packet "tvheadend xmltv-util"
install -m 755 scripts/tv_grab_file /usr/bin/tv_grab_file
sed -i 's/name": ".*"/name": "'$0'"/' /home/hts/.hts/tvheadend/superuser
sed -i 's/word": ".*"/word": "'$1'"/' /home/hts/.hts/tvheadend/superuser
service tvheadend restart
}
......@@ -241,20 +398,6 @@ service samba restart
}
install_temper (){
#--------------------------------------------------------------------------------------------------------------------------------
# Install USB temperature sensor
#--------------------------------------------------------------------------------------------------------------------------------
debconf-apt-progress -- apt-get -y install libusb-dev libusb-1.0-0-dev
cd /tmp
wget https://github.com/igorpecovnik/Debian-micro-home-server/blob/next/src/temper_v14_altered.tgz?raw=true -O - | tar -xz
cd temperv14
make
make rules-install
cp temperv14 /usr/bin/temper
}
install_scaner_and_scanbuttons (){
#--------------------------------------------------------------------------------------------------------------------------------
# Install Scanner buttons
......@@ -287,22 +430,17 @@ apt-get -y install ruby tesseract-ocr libtiff-tools
}
install_btsync (){
install_syncthing (){
#--------------------------------------------------------------------------------------------------------------------------------
# Install Personal cloud
# Install Personal cloud https://syncthing.net/
#--------------------------------------------------------------------------------------------------------------------------------
cd /tmp
if [ "$(dpkg --print-architecture | grep armhf)" != "" ]; then
wget http://download.getsyncapp.com/endpoint/btsync/os/linux-arm/track/stable/btsync_arm.tar.gz -O - | tar -xz
else
wget http://download-new.utorrent.com/endpoint/btsync/os/linux-i386/track/stable/bittorrent_sync_i386.tar.gz -O - | tar -xz
fi
mv btsync /usr/local/bin
ln -sf /lib/ld-linux-armhf.so.3 /lib/ld-linux.so.3
chmod +x /usr/local/bin/btsync
curl -s https://syncthing.net/release-key.txt | sudo apt-key add -
echo deb http://apt.syncthing.net/ syncthing release | sudo tee /etc/apt/sources.list.d/syncthing-release.list
sudo apt-get update
sudo apt-get install syncthing
sed -e 's/exit 0//g' -i /etc/rc.local
cat >> /etc/rc.local <<"EOF"
/usr/local/bin/btsync
syncthing
exit 0
EOF
}
......@@ -377,7 +515,7 @@ install_DashNTP (){
#--------------------------------------------------------------------------------------------------------------------------------
echo "dash dash/sh boolean false" | debconf-set-selections
dpkg-reconfigure -f noninteractive dash > /dev/null 2>&1
debconf-apt-progress -- apt-get -y install ntp ntpdate
install_packet "ntp ntpdate" "Install DASH and ntp service"
}
......@@ -389,7 +527,7 @@ mysql_pass=$(whiptail --inputbox "What is your mysql root password?" 8 78 $mysql
exitstatus=$?; if [ $exitstatus = 1 ]; then exit 1; fi
echo "mysql-server-5.5 mysql-server/root_password password $mysql_pass" | debconf-set-selections
echo "mysql-server-5.5 mysql-server/root_password_again password $mysql_pass" | debconf-set-selections
debconf-apt-progress -- apt-get -y install mysql-client mysql-server
install_packet "mysql-client mysql-server" "Install Mysql client / server"
#Allow MySQL to listen on all interfaces
cp /etc/mysql/my.cnf /etc/mysql/my.cnf.backup
sed -i 's|bind-address = 127.0.0.1|#bind-address = 127.0.0.1|' /etc/mysql/my.cnf
......@@ -403,7 +541,8 @@ install_MySQLDovecot (){
#--------------------------------------------------------------------------------------------------------------------------------
echo "postfix postfix/main_mailer_type select Internet Site" | debconf-set-selections
echo "postfix postfix/mailname string $HOSTNAMEFQDN" | debconf-set-selections
debconf-apt-progress -- apt-get -y install postfix postfix-mysql postfix-doc openssl getmail4 rkhunter binutils dovecot-imapd dovecot-pop3d dovecot-mysql dovecot-sieve sudo libsasl2-modules
install_packet "postfix postfix-mysql postfix-doc openssl getmail4 rkhunter binutils dovecot-imapd dovecot-pop3d dovecot-mysql \
dovecot-sieve sudo libsasl2-modules" "postfix, dovecot, saslauthd, phpMyAdmin, rkhunter, binutils"
#Uncommenting some Postfix configuration files
cp /etc/postfix/master.cf /etc/postfix/master.cf.backup
sed -i 's|#submission inet n - - - - smtpd|submission inet n - - - - smtpd|' /etc/postfix/master.cf
......@@ -425,15 +564,17 @@ install_Virus (){
#--------------------------------------------------------------------------------------------------------------------------------
# Install Amavisd-new, SpamAssassin, And Clamav
#--------------------------------------------------------------------------------------------------------------------------------
debconf-apt-progress -- apt-get -y install amavisd-new spamassassin clamav clamav-daemon zoo unzip bzip2 arj p7zip unrar ripole rpm nomarch lzop cabextract apt-listchanges libnet-ldap-perl libauthen-sasl-perl clamav-docs daemon libio-string-perl libio-socket-ssl-perl libnet-ident-perl zip libnet-dns-perl
install_packet "amavisd-new spamassassin clamav clamav-daemon zoo unzip bzip2 arj p7zip unrar ripole rpm nomarch lzop \
cabextract apt-listchanges libnet-ldap-perl libauthen-sasl-perl clamav-docs daemon libio-string-perl libio-socket-ssl-perl \
libnet-ident-perl zip libnet-dns-perl" "amavisd, spamassassin, clamav"
/etc/init.d/spamassassin stop
insserv -rf spamassassin
}
install_Apache (){
install_apache (){
#--------------------------------------------------------------------------------------------------------------------------------
#Install Apache2, PHP5, phpMyAdmin, FCGI, suExec, Pear, And mcrypt
# Install Apache2, PHP5, phpMyAdmin, FCGI, suExec, Pear and mcrypt
#--------------------------------------------------------------------------------------------------------------------------------
clear_console
echo "========================================================================="
......@@ -448,10 +589,14 @@ echo 'phpmyadmin phpmyadmin/reconfigure-webserver multiselect apache2' | debconf
#BELOW ARE STILL NOT WORKING
#echo 'phpmyadmin phpmyadmin/dbconfig-reinstall boolean false' | debconf-set-selections
#echo 'phpmyadmin phpmyadmin/dbconfig-install boolean false' | debconf-set-selections
debconf-apt-progress -- apt-get -y install apache2 apache2.2-common apache2-doc apache2-mpm-prefork apache2-utils libexpat1 ssl-cert libapache2-mod-php5 php5 php5-common php5-gd php5-mysql php5-imap phpmyadmin php5-cli php5-cgi libapache2-mod-fcgid apache2-suexec php-pear php-auth php5-mcrypt mcrypt php5-imagick imagemagick libapache2-mod-suphp libruby libapache2-mod-ruby libapache2-mod-python php5-curl php5-intl php5-memcache php5-memcached php5-ming php5-ps php5-pspell php5-recode php5-snmp php5-sqlite php5-tidy php5-xmlrpc php5-xsl memcached
install_packet "apache2 apache2.2-common apache2-doc apache2-mpm-prefork apache2-utils libexpat1 ssl-cert libapache2-mod-php5 \
php5 php5-common php5-gd php5-mysql php5-imap phpmyadmin php5-cli php5-cgi libapache2-mod-fcgid apache2-suexec php-pear \
php-auth php5-mcrypt mcrypt php5-imagick imagemagick libapache2-mod-suphp libruby libapache2-mod-ruby libapache2-mod-python \
php5-curl php5-intl php5-memcache php5-memcached php5-ming php5-ps php5-pspell php5-recode php5-snmp php5-sqlite php5-tidy \
php5-xmlrpc php5-xsl memcached" "apache2, PHP5, phpMyAdmin, FCGI, suExec, pear and mcrypt"
a2enmod suexec rewrite ssl actions include
a2enmod dav_fs dav auth_digest
a2enmod suexec rewrite ssl actions include >> /dev/null
a2enmod dav_fs dav auth_digest >> /dev/null
#Fix Ming Error
rm /etc/php5/cli/conf.d/ming.ini
......@@ -491,14 +636,14 @@ EOF
sed -i 's|application/x-ruby|#application/x-ruby|' /etc/mime.types
#Install XCache
apt-get -y -qq install php5-xcache
install_packet "php5-xcache" "Install XCache"
#Restart Apache
service apache2 restart >> /dev/null
}
install_NginX (){
install_nginx (){
#--------------------------------------------------------------------------------------------------------------------------------
# Install NginX, PHP5, phpMyAdmin, FCGI, suExec, Pear, And mcrypt
#--------------------------------------------------------------------------------------------------------------------------------
......@@ -536,7 +681,7 @@ rm /etc/php5/cli/conf.d/ming.ini
cat > /etc/php5/cli/conf.d/ming.ini <<"EOF"
extension=ming.so
EOF
/etc/init.d/php5-fpm restart
/etc/init.d/php5-fpm restart >> /dev/null
}
......@@ -544,7 +689,7 @@ install_PureFTPD (){
#--------------------------------------------------------------------------------------------------------------------------------
# Install PureFTPd
#--------------------------------------------------------------------------------------------------------------------------------
debconf-apt-progress -- apt-get -y install pure-ftpd-common pure-ftpd-mysql
install_packet "pure-ftpd-common pure-ftpd-mysql" "p3ureFTPd"
sed -i 's/VIRTUALCHROOT=false/VIRTUALCHROOT=true/' /etc/default/pure-ftpd-common
echo 1 > /etc/pure-ftpd/conf/TLS
......@@ -552,7 +697,7 @@ mkdir -p /etc/ssl/private/
openssl req -x509 -nodes -days 7300 -newkey rsa:2048 -subj "/C=/ST=/L=/O=/CN=$(hostname -f)" -keyout /etc/ssl/private/pure-ftpd.pem -out /etc/ssl/private/pure-ftpd.pem
chmod 600 /etc/ssl/private/pure-ftpd.pem
/etc/init.d/pure-ftpd-mysql restart
/etc/init.d/pure-ftpd-mysql restart >> /dev/null
}
......@@ -561,7 +706,7 @@ install_Bind (){
#--------------------------------------------------------------------------------------------------------------------------------
# Install BIND DNS Server
#--------------------------------------------------------------------------------------------------------------------------------
debconf-apt-progress -- apt-get -y install bind9 dnsutils
install_packet "bind9 dnsutils" "Install BIND DNS Server"
}
......@@ -569,7 +714,7 @@ install_Stats (){
#--------------------------------------------------------------------------------------------------------------------------------
# Install Vlogger, Webalizer, And AWstats
#--------------------------------------------------------------------------------------------------------------------------------
debconf-apt-progress -- apt-get -y install vlogger webalizer awstats geoip-database libclass-dbi-mysql-perl
install_packet "vlogger webalizer awstats geoip-database libclass-dbi-mysql-perl" "vlogger, webalizer, awstats"
sed -i "s/*/10 * * * * www-data/#*/10 * * * * www-data/" /etc/cron.d/awstats
sed -i "s/10 03 * * * www-data/#10 03 * * * www-data/" /etc/cron.d/awstats
}
......@@ -579,7 +724,7 @@ install_Fail2BanDovecot() {
#--------------------------------------------------------------------------------------------------------------------------------
# Install fail2ban
#--------------------------------------------------------------------------------------------------------------------------------
debconf-apt-progress -- apt-get -y install fail2ban
install_packet "fail2ban" "Install fail2ban"
cat > /etc/fail2ban/jail.local <<"EOF"
[pureftpd]
......
#!/bin/bash
#
# Debian micro home server installation(c) Igor Pecovnik
#
#
# Copyright (c) 2015 Igor Pecovnik, igor.pecovnik@gma**.com
#
# This file is licensed under the terms of the GNU General Public
# License version 2. This program is licensed "as is" without any
# warranty of any kind, whether express or implied.
#
# This file is a part of https://github.com/igorpecovnik/Debian-micro-home-server
#
# Read functions
source "functions.sh"
# Check if user is root
if [ $(id -u) != "0" ]; then
echo "Error: You must be root to run this script, please use the root user to install the software."
exit 1
dialog --msgbox "Error: You must be root to run this script, please use the root user to install the software." 7 70
exit 1
fi
# Debian only
if [ ! -f /etc/debian_version ]; then
echo "Unsupported Linux Distribution. Prepared for Debian"
exit 1
dialog --msgbox "Warning: Unsupported Linux Distribution, it might not install properly. Tailored for Debian. " 7 70
fi
# Ramlog must be disabled
if [ -f /run/ramlog.lock ]; then
echo "RAMlog is running. Please disable before running (service ramlog disable). Reboot is required."
dialog --msgbox "Ramlog is running. Please disable before running (service ramlog disable). Reboot is required." 7 70
exit 1
fi
# Choose what to install
what_to_install
#before_install
for i in "${choice[@]}"
do
#--------------------------------------------------------------------------------------------------------------------------------
# What do we need anyway
debconf-apt-progress -- apt-get update
debconf-apt-progress -- apt-get -y upgrade
debconf-apt-progress -- apt-get -y install debconf-utils dnsutils unzip whiptail git build-essential alsa-base alsa-utils stunnel4 html2text
#--------------------------------------------------------------------------------------------------------------------------------
if [ "$i" == "ISPConfig" ] ; then
server_conf
if [[ "$mysql_pass" == "" ]]; then
dialog --msgbox "Mysql password can't be blank. Exiting..." 7 70
exit
fi
install_basic; install_DashNTP; install_MySQL; install_MySQLDovecot; install_Virus; install_$server
create_ispconfig_configuration; install_PureFTPD; install_Fail2BanDovecot; install_Fail2BanRulesDovecot;
install_ISPConfig
fi
if [ "$i" == "Samba" ] ; then
install_samba
fi
if [ "$i" == "TV headend" ] ; then
install_tvheadend
fi
if [ "$i" == "Transmission" ] ; then
install_transmission
fi
#--------------------------------------------------------------------------------------------------------------------------------
done
exit
SECTION="Basic configuration"
# Read IP address
#
serverIP=$(ip route get 8.8.8.8 | awk '{ print $NF; exit }')
set ${serverIP//./ }
SUBNET="$1.$2.$3."
#
# Read full qualified hostname
HOSTNAMEFQDN=$(hostname -f)
HOSTNAMEFQDN=$(whiptail --inputbox "\nWhat is your full qualified hostname for $serverIP ?" 10 78 $HOSTNAMEFQDN --title "$SECTION" 3>&1 1>&2 2>&3)
exitstatus=$?; if [ $exitstatus = 1 ]; then exit 1; fi
set ${HOSTNAMEFQDN//./ }
HOSTNAMESHORT="$1"
source "functions.sh"
......@@ -74,31 +115,12 @@ do
done < results
if [[ "$ins_samba" == "true" ]]; then install_samba; fi
if [[ "$ins_tvheadend" == "true" ]]; then install_tvheadend; fi
if [[ "$ins_samba" == "true" ]]; then ; fi
if [[ "$ins_tvheadend" == "true" ]]; then ; fi
if [[ "$ins_btsync" == "true" ]]; then install_btsync; fi
if [[ "$ins_vpn_server" == "true" ]]; then install_vpn_server; fi
if [[ "$ins_cups" == "true" ]]; then install_cups; fi
if [[ "$ins_scanner_and_scanbuttons" == "true" ]]; then install_scaner_and_scanbuttons; fi
if [[ "$ins_temper" == "true" ]]; then install_temper; fi
if [[ "$ins_rpimonitor" == "true" ]]; then install_bmc180; install_tsl2561; install_rpimonitor; fi
if [[ "$ins_transmission" == "true" ]]; then install_transmission; fi
if [[ "$ins_ispconfig" == "true" ]]; then
install_basic
install_DashNTP
install_MySQL
install_MySQLDovecot
install_Virus;
if (whiptail --no-button "Apache" --yes-button "NginX" --title "Choose webserver platform" --yesno "ISPConfig can run on both." 7 78) then
server="nginx"
install_NginX
else
server="apache"
install_Apache
fi
create_ispconfig_configuration
install_PureFTPD; install_Fail2BanDovecot; install_Fail2BanRulesDovecot; install_ISPConfig
fi
rm results
if [[ "$ins_transmission" == "true" ]]; then ; fi
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment