X-Git-Url: http://git.grml.org/?a=blobdiff_plain;f=usr_sbin%2Fdirvish-setup;h=8a2497ca810f5ce89a0fe7b1944a36ab4f9aef5e;hb=3b7f948896440f41092f14347b17ce114072c569;hp=d81bf34d030964c4ffa94d6ed0ed2f86ce5a774b;hpb=36a4a57f386b81033c4a70e1cfd24f6214e68f79;p=grml-scripts.git diff --git a/usr_sbin/dirvish-setup b/usr_sbin/dirvish-setup index d81bf34..8a2497c 100755 --- a/usr_sbin/dirvish-setup +++ b/usr_sbin/dirvish-setup @@ -4,9 +4,8 @@ # Authors: grml-team (grml.org), (c) Michael Prokop # Bug-Reports: see http://grml.org/bugs/ # License: This file is licensed under the GPL v2. -# Latest change: Fre Mär 09 19:45:57 CET 2007 [mika] ################################################################################ -# Ressources: +# Resources: # http://apt-get.dk/howto/backup/ # http://edseek.com/~jasonb/articles/dirvish_backup/advanced.html # http://www.dirvish.org/svn/contrib/admin/DailyEmailScript/dirvish-status.sh @@ -14,25 +13,28 @@ set -e +# shellcheck disable=SC1091 . /etc/grml/script-functions +# shellcheck disable=SC1091 . /etc/grml/lsb-functions check4root -check4progs dirvish rsync ssh-keygen ssh-copy-id +check4progs dialog dirvish rsync ssh-keygen ssh-copy-id PN="$0" CONFFILE=/etc/dirvish/master.conf -# make sure we don't lose any files -if [ -f "$CONFFILE" ] ; then - mv $CONFFILE $CONFFILE.$(date +%Y%m%d).$$ -fi - set +e write_conffile() { - cat > $CONFFILE << EOF -# Configuration file for dirvish, created by $PN on $(date) + if [ -f "$CONFFILE" ] ; then + MASTERINFO="Notice: $CONFFILE exists already so I will not touch it. +Please do not forget to add $CLIENT to the file if you wan to use the 'Runall' functionality." + else + MASTERINFO="An initial master configuration ($CONFFILE) has been generated. +Please adjust it according to your needs." + cat > $CONFFILE << EOF +# Master configuration file for dirvish, created by $PN on $(date) bank: $BACKUP_DIR @@ -42,18 +44,20 @@ exclude: # core # *~ # .nfs* +# /var/lib/nfs/*tab # var/cache/apt/archives # var/cache/man -# tmp # var/tmp -# /var/lib/nfs/*tab -# .kde/share/cache/* -# .firefox/default/*/Cache/* +# tmp +# /dev +# .kde/share/cache/* +# .firefox/default/*/Cache/* Runall: $CLIENT 22:00 + # add-another-client-here 22:00 -# See http://www.dirvish.org/debian.howto.html for further details: + # See http://www.dirvish.org/debian.howto.html for further details: expire-default: +30 days expire-rule: # MIN HR DOM MON DOW STRFTIME_FMT @@ -64,11 +68,13 @@ expire-rule: # * * * * 2-7 +15 days EOF + fi } # TODO / integrate? cronsetup() { - test -f ~/.keychain/`uname -n`-sh && source ~/.keychain/`uname -n`-sh +# shellcheck disable=SC1090 + test -f "${HOME}/.keychain/$(uname -n)-sh" && . "${HOME}/.keychain/$(uname -n)-sh" } get_backup_dir() { @@ -77,8 +83,9 @@ get_backup_dir() { if ! [ -d "$BACKUP_DIR" ] ; then dialog --stdout --title "${PN}" --yesno "The directory $BACKUP_DIR does not yet exist. Do you want me to create it for you? " 0 0 + RC=$? - if [ $? -eq 0 ]; then + if [ ${RC} -eq 0 ]; then echo "mkdir $BACKUP_DIR" echo "chmod 700 $BACKUP_DIR" else @@ -118,23 +125,25 @@ EOF } sshkey_setup() { - CLIENTNAME="$(dialog --stdout --inputbox 'Please choose user login and hostname for the client you want to backup. Syntax: user@host' 0 0 root@$(hostname))" + CLIENTNAME="$(dialog --stdout --inputbox 'Please choose user login and hostname for the client you want to backup. Syntax: user@host' 0 0 root@"$(hostname)")" dialog --stdout --title "${PN}" --yesno "Do you want me to create ssh setup for client ${CLIENTNAME} using ssh-keygen and ssh-copy-id?" 0 0 + RC=$? - if [ $? -eq 0 ]; then + if [ ${RC} -eq 0 ]; then [ -d "$HOME/.ssh" ] || mkdir "$HOME/.ssh" einfo "Creating $HOME/.ssh/id_rsa_dirvish_${CLIENT} using ssh-keygen:" ssh-keygen -t rsa -f "$HOME/.ssh/id_rsa_dirvish_${CLIENT}" ; eend $? einfo "Running ssh-copy-id to copy ssh key to $CLIENTNAME:" - ssh-copy-id -i "$HOME/.ssh/id_rsa_dirvish_${CLIENT}.pub" $CLIENTNAME ; eend $? + ssh-copy-id -i "$HOME/.ssh/id_rsa_dirvish_${CLIENT}.pub" "$CLIENTNAME" ; eend $? fi } client_setup() { dialog --stdout --title "${PN}" --yesno "Do you want to backup $CLIENT via network? Answering with no will use localhost [$(hostname)] as client." 0 0 + RC=$? - if [ $? -eq 0 ]; then + if [ ${RC} -eq 0 ]; then sshkey_setup else CLIENTNAME=$(hostname) # use localhost only @@ -145,6 +154,7 @@ display_info() { einfo "Running $PN was successful. Enjoy using dirvish!" ; eend 0 echo einfo "Please adjust ${BACKUP_DIR}/${CLIENT}/dirvish/default.conf according to your needs. +$MASTERINFO Then run the following command to create an initial backup: dirvish --summary long --vault $CLIENT --init @@ -171,11 +181,11 @@ case "$1" in ;; esac -# now run the funtions: +# now run the functions: get_backup_dir && \ client_name && \ -client_setup && \ tree_name && \ +client_setup && \ create_client_conf && \ write_conffile && \ display_info