]> www.wagner.pp.ru Git - oss/restore.git/blob - aftermount
Documented backup and afermount scripts
[oss/restore.git] / aftermount
1 #!/bin/bash
2 #
3 # Intended to be called from file manager as aftermount command.
4 # Checks if mounted volume looks like rsnapshot snapshot_root and if
5 # so, asks to run backup in a graphical dialog.
6 #
7 # Expected backup script installed into BACKUP path below and
8 # passwordless sudo available for it for any user of %plugdev group
9
10 BACKUP=/usr/local/sbin/backup
11 SUDOCMD=sudo
12 spacefm_dialog() {
13         eval "$(spacefm -g --title "$1" --label "$2" --button no --button yes)"
14         [ "$dialog_pressed_label" = "yes" ]&& return 0
15         return 1
16 }
17
18 spacefm_monolog() {
19         spacefm -g --title "$1" --label "$2" --window-icon "$3" --button ok >/dev/null
20 }
21
22 zenity_dialog() {
23         zenity --question --title "$1" --text "$2"
24 }
25
26 zenity_monolog() {
27         zenity --$3 --title "$1" --text "$2"
28 }
29 mountpoint="$1"
30 grep -q "^snapshot_root $mountpoint" /etc/rsnapshot.conf || exit 0
31
32
33
34 eval "$(df -H "$mountpoint"|awk 'NR>1 {printf "dev=%s\nsize=%s\nfree=%s\nmp=%s",$1,$2,$4,$6;}')"
35 message="Backup media inserted into $dev\nTotal space $size\nFree space=$free\n. Would you like to start backup?"
36
37 if command -v spacefm; then
38         iface=spacefm
39 else
40         iface=zenity
41 fi
42
43 ${iface}_dialog "Backup media inserted" "$message" || exit 0
44
45 if sudo $BACKUP; then
46         ${iface}_monolog "Backup successful" "Backup finished successfully" info
47 else 
48         ${iface}_monolog "Backup failed" "Backup finished with errors. See logs" error
49         exit 1
50 fi