summaryrefslogtreecommitdiffstats
path: root/partimage/build/doinst.sh
blob: 545a8792c668cc5b0f2511406c411b9bf646bf23 (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
80
81
82
# Handle the incoming configuration files:
config() {
  for infile in $1; do
    NEW="$infile"
    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...
  done
}

partuid=77
partuser=partimag
partconfdir="etc/partimaged"
partdatadir="var/spool/partimaged"
opensslpath="/usr/bin/openssl"

# Create the partimage account
if ! chroot . getent passwd $partuser > /dev/null 2>&1
then
  chroot . useradd -c "Partition Image daemon" -g root -u $partuid -d /tmp -s /bin/false $partuser
  res=$?
  if [ $res -ne 0 ]
  then
    echo "User with UID $partuid already exists! You'll have add a $partuser user manually!"
  echo "Run this command: \"useradd -c 'Partition Image daemon' -u UID -g root -d /tmp -s /bin/false $partuser\""
  echo "And select a free value for UID that is below 500 (check /etc/passwd)"
  echo "Then, run an \"upgradepkg --reinstall\" of this partimage package so that it can run the rest of the install script. "
  exit $res
  fi
fi

# Handle the partimage configuration files
chmod -x etc/rc.d/rc.partimaged.new
config etc/rc.d/rc.partimaged.new
config ${partconfdir}/partimagedusers.new

# The partimag user must own the configuration directory and the users file
chown ${partuser}:root ${partconfdir}
chown ${partuser}:root ${partconfdir}/partimagedusers
chmod 600 ${partconfdir}/partimagedusers

# The partimag user must own the dataspool directory
chown ${partuser}:root ${partdatadir}
chmod 600 ${partdatadir}

# Create certificate for SSL connections
if test -x ${opensslpath} ; then
  if test ! -f ${partconfdir}/partimaged.cert ; then
    echo "===================================================="
    echo "generating certificate for partimage/partimaged ssl:"
    echo "===================================================="
    echo "You will be asked for a passphrase twice. The passphrases must match"
    echo "and will be used to create the key certificate for partimaged."
    echo "Write this passphrase down or memorize it!"
    echo ""
    mkdir -p ${partconfdir} >/dev/null
    touch ${partconfdir}/privkey.pem
    rm -f ${partconfdir}/privkey.pem
    ${opensslpath} req -new -x509 -outform PEM \
      -keyout ${partconfdir}/privkey.pem > ${partconfdir}/partimaged.csr
    ${opensslpath} rsa -in ${partconfdir}/privkey.pem \
      -out ${partconfdir}/partimaged.key
    rm -f ${partconfdir}/privkey.pem
    ${opensslpath} x509 -in ${partconfdir}/partimaged.csr -out \
      ${partconfdir}/partimaged.cert -signkey ${partconfdir}/partimaged.key
    rm ${partconfdir}/partimaged.csr
    chmod 600 ${partconfdir}/partimaged.key
    chmod 600 ${partconfdir}/partimaged.cert
    chown ${partuser}:root ${partconfdir}/partimaged.key
    chown ${partuser}:root ${partconfdir}/partimaged.cert
  else
    echo "Found existing certificate; no new certificate will be generated."
  fi
else
  echo "SSL support not found; no certificate will be generated."
fi