summaryrefslogtreecommitdiffstats
path: root/docker/build/doinst.sh
blob: bb188878d9434a245625be52512800bcc5f7fc0b (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
config() {
  NEW="$1"
  OLD="$(dirname $NEW)/$(basename $NEW .new)"
  # If there's no config file by that name, mv it over:
  if [ ! -r $OLD ]; then
    mv $NEW $OLD
  elif [ "$(cat $OLD | md5sum)" = "$(cat $NEW | md5sum)" ]; then
    # toss the redundant copy
    rm $NEW
  fi
  # Otherwise, we leave the .new copy for the admin to consider...
}

preserve_perms() {
  NEW="$1"
  OLD="$(dirname $NEW)/$(basename $NEW .new)"
  if [ -e $OLD ]; then
    cp -a $OLD ${NEW}.incoming
    cat $NEW > ${NEW}.incoming
    mv ${NEW}.incoming $NEW
  fi
  config $NEW
}

preserve_perms etc/rc.d/rc.docker.new
config etc/default/docker.new
config etc/logrotate.d/docker.new

# Reload udev rules, we just added one with this package:
if [ -x /sbin/udevadm ]; then
  /sbin/udevadm control --reload-rules
fi

# Group 'docker' (grpId=281) is also used by SBo.
DOCKER_GID=${DOCKER_GID:-281}

# Only way to create and use the correct uid and gid on the target system,
# is to use chroot:
chroot . <<EOR 2>/dev/null
# Add the '${DOCKER_GID}' group if it doesn't exist already:
/usr/sbin/groupadd -g ${DOCKER_GID} docker 2> /dev/null
EOR

# Update rc.local so that docker daemon will be started on boot:
if ! grep "rc.docker" etc/rc.d/rc.local 1>/dev/null 2>&1 ; then
  cat <<_EOM_ >> etc/rc.d/rc.local

if [ -x /etc/rc.d/rc.docker ]; then
  # Start Docker daemon:
  echo "Starting Docker daemon:    /etc/rc.d/rc.docker start"
  /etc/rc.d/rc.docker start
fi
_EOM_
fi

# Update rc.local_shutdown so that docker daemon will be stopped:
if ! grep "rc.docker" etc/rc.d/rc.local_shutdown 1>/dev/null 2>&1 ; then
  cat <<_EOM2_ >> etc/rc.d/rc.local_shutdown

if [ -x /etc/rc.d/rc.docker ]; then
  # Stop Docker daemon:
  echo "Stopping Docker daemon:    /etc/rc.d/rc.docker stop"
  /etc/rc.d/rc.docker stop
fi
_EOM2_
fi