#!/usr/bin/perl ####################################################################################### restic setup (mwx'2023) use Config; die if (!-f "./files/rt"); #myuname: linux localhost 4.19.0 #1 smp debian 4.19.0 armv7l gnulinux #archname: arm-linux-gnueabihf-thread-multi-64int if ($Config{archname}=~/^darwin/) { # --------------------------------------------------------------- mac setup $XRT = $ENV{"HOME"}.'/bin/rt'; $XRTLOG = $ENV{"HOME"}.'/.rt.log'; $XRESTIC = $ENV{"HOME"}.'/bin/restic'; $XLOG = $ENV{"HOME"}.'/.restic.log'; $XPWFILE = $ENV{"HOME"}.'/.restic.pw'; $XSRC = $ENV{"HOME"}.'/Sync /Volumes/Pictures'; $XEXCLUDE = '-e .Spotlight-V100 -e .Trashes -e .fseventsd -e .bzvol -e .DS_Store ' . '-e .TemporaryItems -e .DocumentRevisions-V100'; $config=$ENV{"HOME"}.'/.rt.conf'; system('./upd https://github.com/restic/restic -i '.$ENV{"HOME"}.'/bin'); system("cp ./files/rt $XRT"); system("chmod 755 $XRT"); } elsif ($Config{archname}=~/-linux-/) { # ------------------------------------------------ ubuntu/debian setup $XRT = '/db/bin/rt'; $XRTLOG = '/var/log/rt.log'; $XRESTIC = '/db/bin/restic'; $XLOG = '/var/log/restic.log'; $XLOG = '/var/log/restic.log'; $XPWFILE = '/db/etc/restic.pw'; $XSRC = '/etc /db /var /root /home /usr/local /opt'; $XEXCLUDE = '-e /var/lib/lxcfs -e /var/log/journal'; $config='/db/etc/rt.conf'; system('./upd https://github.com/restic/restic -i /db/bin'); system("cp ./files/rt $XRT"); system("chmod 755 $XRT"); system("mkdir -p /db/etc /db/tmp"); } else {die "architecture not found";} # ---------------------------------------------------------------------- chomp($host=`hostname`);$host=~s/^([^\.]+).*/$1/; $host=&readline("Hostname: ",$host); if (!-f $config) { # write config file open(OUT,"> $config"); print OUT <<"ENDOFCONF"; \$NAME = '$host'; \$ID = '0'; \$TAG = 'ppb'; \$PASSWORD = ""; \$TARGET = ""; \$ENV{'AWS_ACCESS_KEY_ID'} = ''; \$ENV{'AWS_SECRET_ACCESS_KEY'} = ''; \$SRC = '$XSRC'; \$EXCLUDE = '$XEXCLUDE'; \$RESTIC = '$XRESTIC'; \$LOG = '$XLOG'; \$PWFILE = '$XPWFILE'; \$HTTP_LOG = 'log.fhi.berlin'; ENDOFCONF } system("vi $config"); system("$XRT init"); &setupcron(); ####################################################################################################### SUPPORT sub setupcron() { open(CRON,"crontab -l |"); while() { chomp(); push(@CRON,$_) if (!/rt\s+selfupdate/ && !/rt delaybackup/); } push(@CRON,"0 2 * * * $XRT delaybackup >> $XRTLOG 2>&1"); open(OUT,"> /tmp/cron.$$"); for (@CRON) { print OUT "$_\n"; } close(OUT); system("/usr/bin/crontab /tmp/cron.$$"); system("rm -f /tmp/cron.$$"); } sub readline() { my($prompt,$input)=@_; use Term::ReadLine; BEGIN{ $ENV{PERL_RL} = 'Perl o=0' } if (!$term) {;$term = new Term::ReadLine 'term';} my($txt)=$term->readline($prompt,$input); return $txt; } ########################################################################################################### END