bash-bear rename and a few improvements
[distro-setup] / mount-latest-remote
1 #!/bin/bash
2 # Copyright (C) 2016 Ian Kelling
3
4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at
7
8 # http://www.apache.org/licenses/LICENSE-2.0
9
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
15
16
17 # usage: HOST [mount-latest-subvol args]
18
19 set -e; . /usr/local/lib/bash-bear; set +e
20
21 script_dir=$(dirname $(readlink -f "$BASH_SOURCE"))
22
23 if (( ! $# )); then
24 echo "mount-latest-remote: error: a host argument"
25 exit 1
26 fi
27
28 tg="$1"
29 shift
30
31 $script_dir/install-my-scripts
32 cd /usr/local
33
34 ecode=0
35
36 # exit code run
37 er() {
38 local ret=0
39 "$@" || ret=$?
40 if (( ret )); then
41 echo "$0: failed command: $*"
42 fi
43 if (( ret > ecode )); then
44 ecode=$ret
45 fi
46 }
47 rsynctg=$tg
48 if [[ $tg == *:* ]]; then
49 rsynctg="[$tg]"
50 fi
51 # R = relative, t = times, O = omit-dir-times, p = perms
52 er rsync -RtOp bin/{mount-latest-subvol,check-subvol-stale} lib/bash-bear "root@$rsynctg:/usr/local" || continue
53 # note: this can hang if we have an old nfs mount.
54 er ssh root@$tg timeout -s 9 600 /usr/local/bin/mount-latest-subvol "$@"
55
56 exit $ecode