#!/bin/bash RDX_DEVICE="/dev/sdb" RDX_PART="/dev/sdb1" BPC_DATAS_DIR="/var/lib/BackupPC" BPC_FILES="/root/rdx_init.tar.gz" init_rdx() { echo -e "[*] Unmounting RDX " 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" 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" 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 echo "[*] RDX SMART OK, mouting BackupPC filesystem" if [ -e $RDX_PART ]; then echo -e "[*] fsck $RDX_PART" /sbin/fsck -f $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 echo -e "[*] RDX is already initilised, all is done :)" /etc/init.d/backuppc restart else echo -e "[x] RDX is steal empty" init_rdx fi else echo -e "[x] Device $RDX_PART not found, maybe no parted?" echo -e "[*] RDX Initialisation..." init_rdx fi fi } check_rdx