aboutsummaryrefslogtreecommitdiff
path: root/share/hydractl/sync-home
blob: 7be90eaa227e4b804b53cc3d02b9885425656415 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#!/bin/bash
#
# sync-home
#

# Parameters
BASENAME="$0"
TPC="$1"
DEST="/media/$1"
MEDIA="$DEST/var/cache/$TPC/media"
RSYNC="ionice -c 3 nice -n 19 rsync -av --delete --progress"

# Syntax
if [ -z "$TPC" ]; then
  echo "usage: $BASENAME <tpc>"
  exit 1
elif [ ! -d "$DEST" ]; then
  echo "folder $DEST does not exist."
  exit 1
fi

# Sudo
if [ "$USER" != 'root' ]; then
  export SUDO="sudo"
fi

# Encrypted home
$SUDO mkdir -p $DEST/mnt/crypt/home

# Encrypted mountpoints
for folder in /mnt/crypt/home/*; do
  $SUDO mkdir -p $DEST/$folder
done

# Sync files
$SUDO $RSYNC /home/ $DEST/home/