typo
[hband-tools.git] / mount / mount.restic
blobd943e8b29d87293f6f840890971c34a9ca71c195
1 #!/bin/bash
3 set -e
4 set -u
6 declare -a available_restic_mount_opts=($(restic mount --help | grep -Eio "[-]-[a-z0-9-]+"))
7 declare -a restic_mount_args=()
8 fuse_opts=''
10 mntname=$1
11 shift
12 mntpoint=$1
13 shift
16 while [ $# -gt 0 ]
18 case "$1" in
19 -o)
20 shift
21 oldIFS=$IFS
22 IFS=,
23 for option in $1
25 option_key=${option%%=*}
26 is_restic_opt=0
27 for restic_opt in "${available_restic_mount_opts[@]}"
29 case "$restic_opt" in
30 --repo) continue;;
31 esac
33 if [ "--$option_key" = "$restic_opt" ]
34 then
35 if [[ $option =~ =(.+) ]]
36 then
37 option_value=${BASH_REMATCH[1]}
38 if [ "${option_value:0:2}" = '~/' ]
39 then
40 option_value=$HOME/${option_value:2}
41 option="$option_key=$option_value"
45 restic_mount_args+=("--$option")
46 is_restic_opt=1
47 break
49 done
51 if [ $is_restic_opt = 0 ]
52 then
53 fuse_opts=$fuse_opts${fuse_opts:+,}$option
55 done
56 IFS=$oldIFS
58 -n|-s)
59 true
62 echo "Unknown option: $1" >&2
63 exit 255
65 esac
66 shift
67 done
69 set +u
71 exec setsid restic mount "${restic_mount_args[@]}" --repo="$mntname" ${fuse_opts:+-o "$fuse_opts"} "$mntpoint" &
72 disown