Browse Source

Add BackupPC install script

root 10 years ago
parent
commit
e8863d2a6a
2 changed files with 109 additions and 19 deletions
  1. 78 0
      BackupPC_install.sh
  2. 31 19
      rdx_manager.sh

+ 78 - 0
BackupPC_install.sh

@@ -0,0 +1,78 @@
+#!/bin/bash
+
+clear
+
+echo "BackupPC Install Script for CentOS 6.x"
+echo "pbourdin@ceme-sa.com"
+
+echo "NOZEROCONF=yes" >> /etc/sysconfig/network
+
+configure_repo() {
+	yum -y install wget vim
+	cd /tmp
+	wget -c http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
+	rpm -Uvh epel-release-6-8.noarch.rpm
+	yum update -y
+}
+
+
+configure_iptables() { 
+
+	iptables -F
+
+	iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
+	iptables -A INPUT -p icmp -j ACCEPT
+	iptables -A INPUT -i lo -j ACCEPT
+	iptables -A INPUT -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT
+	iptables -A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT
+	iptables -A INPUT -m state --state NEW -m tcp -p tcp --dport 443 -j ACCEPT
+	iptables -A INPUT -m state --state NEW -m tcp -p tcp --dport 10050 -j ACCEPT
+	iptables -A INPUT -j REJECT --reject-with icmp-host-prohibited
+
+	/etc/init.d/iptables save
+	/etc/init.d/iptables restart
+	
+}
+
+install_backuppc() {
+	yum -y install perl-Compress-Zlib perl-Archive-Zip perl-File-RsyncP perl-suidperl openssh-clients expect httpd htpasswd backuppc lsof eject vim nmap screen smartmontools 
+	adduser backuppc
+
+	chkconfig backuppc on
+	chkconfig httpd on 
+
+
+	echo "Entrer le mot de passe pour l'utilisateur 'backuppc'"
+        htpasswd -c /etc/BackupPC/apache.users backuppc
+	echo "Entrer le mot de passe pour l'utilisateur 'root'"
+	htpasswd /etc/BackupPC/apache.users root
+
+	sed -i -e "s/allow from 127.0.0.1/allow from all/g" /etc/httpd/conf.d/BackupPC.conf
+
+	sed -i -e "s/$Conf{ServerHost} = 'localhost';/$Conf{ServerHost} = '$(hostname)';/g" /etc/BackupPC/config.pl
+	sed -i -e "s/$Conf{CgiAdminUsers}     = '';/$Conf{CgiAdminUsers}     = 'root';/g" /etc/BackupPC/config.pl
+	sed -i -e "s/$Conf{Language} = 'en';/$Conf{Language} = 'fr';/g" /etc/BackupPC/config.pl
+
+
+	
+	/etc/init.d/httpd restart
+	/etc/init.d/backuppc restart
+}
+
+install_zabbix() {
+	
+	rpm -ivh http://repo.zabbix.com/zabbix/2.2/rhel/6/x86_64/zabbix-release-2.2-1.el6.noarch.rpm
+	yum -y update	
+	yum -y install zabbix-agent
+	sed -i -e "s/Server=127.0.0.1/Server=172.20.11.100/g" /etc/zabbix/zabbix_agentd.conf
+	chkconfig zabbix-agent on
+	/etc/init.d/zabbix-agent start
+}
+
+
+
+
+configure_repo
+install_zabbix
+configure_iptables
+install_backuppc

+ 31 - 19
rdx_manager.sh

@@ -3,62 +3,74 @@
 RDX_DEVICE="/dev/sdb"
 RDX_PART="/dev/sdb1"
 BPC_DATAS_DIR="/var/lib/BackupPC"
-BPC_FILES="/root/rdx_init.tar.gz"
+BPC_FILES="/root/RDX_BackupPC/rdx_init.tar.gz"
 
 init_rdx()
 {
-
+	/etc/init.d/crond stop
 	echo -e "[*] Unmounting RDX "
-	umount $RDX_PART 2>&1 || echo -e "[x] Error unmounting RDX partition"
+	/bin/umount $RDX_PART 2>&1 || echo -e "[x] Error unmounting RDX partition"
 
 	echo -e "[*] Creating /dev/sdb1..."
 	(echo o; echo n; echo p; echo 1; echo ; echo; echo w) | fdisk $RDX_DEVICE 2>&1 || echo -e "[x] Error during parted"
 
 	echo -e "[*] Creating ext4 filesystem... (this can take severals minutes)"
-	mkfs.ext4 $RDX_PART 2>&1 || echo -e "[x] Error during mkfs.ext4"
+	/sbin/mkfs.ext4 $RDX_PART 2>&1 || echo -e "[x] Error during mkfs.ext4"
 
-	echo -e "[*] Mounting and extracting base files..."
-	mount $RDX_PART $BPC_DATAS_DIR 2>&1 || echo -e "[x] Error during mounting"
-	tar xvf $BPC_FILES -C $BPC_DATAS_DIR 2>&1 || echo -e "[x] Error during extract, check if $BPC_FILES exists"
+	/etc/init.d/crond start
+	/sbin/partprobe $RDX_DEVICE
 	check_rdx
 
 }
 
 check_rdx()
 {
-
+	
 	rdx_present=$(smartctl -A $RDX_DEVICE | grep "Current Drive Temperature" | cut -d ":" -f2 | sed -e "s/\ //g")
-
 	if [ "$rdx_present" = "<notavailable>" ]; then
 		echo -e "[x] RDX SMART <notavailable>, maybe the disk is ejected?"
 		echo -e "[x] force unmount of $BPC_DATAS_DIR"
 		/bin/umount -f $BPC_DATAS_DIR
+
 	
 	else
+		/sbin/partprobe $RDX_DEVICE
 		echo "[*] RDX SMART OK, mouting BackupPC filesystem"
+	
+		fs_detect=$(file -s $RDX_PART | grep "ext4" 2>&1 || echo "non")	
+		if [ "$fs_detect" = "non" ]; then
+                        echo -e "[x] Device $RDX_PART not found, maybe no parted?"
+                        echo -e "[*] RDX Initialisation..."
+			init_rdx
+		else
+			echo -e "Good filesystem..."
+		fi
+
 		if [ -e $RDX_PART ]; then
 			echo -e "[*] fsck $RDX_PART"
-			/sbin/fsck -f $RDX_PART 2>&1 || echo -e "[x] Error during fsck"
+#			/sbin/fsck.ext4 -f -y $RDX_PART 2>&1 || echo -e "[x] Error during fsck"
 			echo -e "[*] Mount $RDX_PART in $BPC_DATAS_DIR"
 			/bin/mount $RDX_PART $BPC_DATAS_DIR 2>&1 || echo -e "[x] Error during mount"
 
-			if [ -d "/var/lib/BackupPC/pool" ]; then
+			if [ -d "$BPC_DATAS_DIR/pool" ]; then
 				echo -e "[*] RDX is already initilised, all is done :)"
 				/etc/init.d/backuppc restart
+				exit 1
 			else
 				echo -e "[x] RDX is steal empty"
-				init_rdx
+				/bin/tar xvf $BPC_FILES -C $BPC_DATAS_DIR 2>&1 || echo -e "[x] Error during extract, check if $BPC_FILES exists"
 			fi
-
-		else
-			echo -e "[x] Device $RDX_PART not found, maybe no parted?"
-			echo -e "[*] RDX Initialisation..."
-			init_rdx
-
 		fi
 	
 	fi
 }
 
 
-check_rdx
+if [ -e $BPC_DATAS_DIR/pool ]; then
+	exit 1
+
+else
+	check_rdx
+fi
+
+