aboutsummaryrefslogtreecommitdiff
path: root/share/hydractl/sync-tpc
blob: 5b990bb055e5468c5072dfc45d8c06a89d4ae1c1 (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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#!/bin/bash
#
# sync-tpc
#

# 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/
$SUDO $RSYNC /var/cache/pbuilder/   $DEST/var/cache/pbuilder/
$SUDO $RSYNC /var/chroot/           $DEST/var/chroot/
$SUDO $RSYNC /var/lib/wicd/         $DEST/var/lib/wicd/

# Network config
$SUDO cp -a /etc/network/interfaces                   $DEST/etc/network/interfaces
$SUDO cp -a /etc/udev/rules.d/70-persistent-net.rules $DEST/etc/udev/rules.d/70-persistent-net.rules

# Custom network config
if [ -e '/etc/network/interfaces.d/' ]; then
  $SUDO $RSYNC /etc/network/interfaces.d/ $DEST/etc/network/interfaces.d/
fi

# Wicd
if [ -d "/etc/wicd" ]; then
  $SUDO mkdir -p                               $DEST/etc/wicd
  $SUDO cp -a /etc/wicd/manager-settings.conf  $DEST/etc/wicd/manager-settings.conf
  $SUDO cp -a /etc/wicd/wireless-settings.conf $DEST/etc/wicd/wireless-settings.conf
fi

# Ensure the media folder exist
if [ ! -d "$MEDIA" ]; then
  $SUDO mkdir -p $MEDIA

  OWNER="$(stat -c %U /var/cache/`hostname -s`/media)"
  GROUP="$(stat -c %G /var/cache/`hostname -s`/media)"

  # With the right permissions
  $SUDO chown $OWNER.$GROUP $MEDIA
fi

# Guest images were previously synced using rsync
#$SUDO $RSYNC /var/cache/virtualbox/ $DEST/var/cache/virtualbox/
#$SUDO $RSYNC /var/cache/qemu/       $DEST/var/cache/qemu/
#$SUDO $RSYNC /var/cache/vagrant/    $DEST/var/cache/vagrant/

# Sync qemu guest images
if [ -d "/var/cache/qemu" ]; then
  hydractl sync-guestfs /var/cache/qemu $DEST/var/cache/qemu
fi

# Sync media remotes
hydractl sync-media-remotes $MEDIA