#!/bin/bash RDX_DEVICE="/dev/sdb" RDX_PART="/dev/sdb1" BPC_DATAS_DIR="/var/lib/BackupPC" BPC_FILES="/root/RDX_BackupPC/rdx_init.tar.gz" init_rdx() { echo -e "[*] Unmounting RDX " /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)" /sbin/mkfs.ext4 $RDX_PART 2>&1 || echo -e "[x] Error during mkfs.ext4" /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" = "" ]; then echo -e "[x] RDX SMART , 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.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" /bin/chown -R backuppc:root $BPC_DATAS_DIR 2>&1 || echo -e "[x] Error during chown" 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" /bin/tar xvf $BPC_FILES -C $BPC_DATAS_DIR 2>&1 || echo -e "[x] Error during extract, check if $BPC_FILES exists" fi fi fi } if [ -e $BPC_DATAS_DIR/pool ]; then echo -e "[*] Rien à faire" exit 1 else /etc/init.d/crond stop check_rdx /etc/init.d/crond start fi