summaryrefslogtreecommitdiff
path: root/debian/postinst.in
blob: 67ea151758ee20fc2ec729735fd2bd25a6aaa743 (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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#!/bin/sh
set -e

install_local_dir() {
  if [ ! -d $1 ]; then
    mkdir -p $1
  fi
  chown root:staff $1 2> /dev/null || true
  chmod 2775 $1 2> /dev/null || true
}

install_from_default() {
  if [ ! -f $2 ]; then
    cp -p $1 $2
  fi
}

install_directory() {
  if [ ! -d /$1 ]; then
    mkdir /$1
    chown root:$3 /$1 || true
    chmod $2 /$1
  fi
}

migrate_directory() {
  if [ ! -L $1 ]; then
    rmdir $1
    ln -s $2 $1
  fi
}

if [ ! -e /etc/dpkg/origins/default ]; then
  if [ -e /etc/dpkg/origins/#VENDORFILE# ]; then
    ln -sf #VENDORFILE# /etc/dpkg/origins/default
  fi
fi

# mount points for special filesystems:
[ -e /etc/mnttab ]       || touch /etc/mnttab       || true
[ -e /etc/dfs/sharetab ] || touch /etc/dfs/sharetab || true

if [ "$1" = "configure" ] && [ "$2" = "" ]; then
  install_from_default /usr/share/base-files/nsswitch.conf /etc/nsswitch.conf
  install_from_default /usr/share/base-files/dot.profile   /root/.profile
  install_from_default /usr/share/base-files/dot.bashrc    /root/.bashrc
  install_from_default /usr/share/base-files/profile       /etc/profile
  install_from_default /usr/share/base-files/project       /etc/project
  install_from_default /usr/share/base-files/motd          /etc/motd
  install_directory srv       755 root
  install_directory opt       755 root
  install_directory etc/opt   755 root
  install_directory var/opt   755 root
  install_directory media     755 root
  install_directory export    755 root
  install_directory var/mail 2775 mail
  if [ ! -L /var/spool/mail ]; then
    ln -s ../mail /var/spool/mail
  fi

  install_local_dir /usr/local
  install_local_dir /usr/local/share
  install_local_dir /usr/local/share/man
  install_local_dir /usr/local/bin
  install_local_dir /usr/local/games
  install_local_dir /usr/local/lib
  install_local_dir /usr/local/include
  install_local_dir /usr/local/sbin
  install_local_dir /usr/local/src
  install_local_dir /usr/local/etc
  ln -sf share/man /usr/local/man
fi

if [ ! -d /var/lib/dpkg ]; then
  mkdir -m 755 -p /var/lib/dpkg
  chown root:root /var/lib/dpkg
fi
if [ ! -f /var/lib/dpkg/status ]; then
  echo > /var/lib/dpkg/status
  chmod 644 /var/lib/dpkg/status
  chown root:root /var/lib/dpkg/status
fi

if [ ! -f /usr/info/dir ] && [ ! -f /usr/share/info/dir ]; then
  install_from_default /usr/share/base-files/info.dir /usr/share/info/dir
  chmod 644 /usr/share/info/dir
  chown root:root /usr/share/info/dir
fi

if [ "$1" = "configure" ] && [ "$2" != "" ]; then
  if [ -f /etc/motd ]; then
    oldmd=`awk 'NR > 2' /etc/motd | md5sum | awk '{print $1}'`
    newmd=`awk 'NR > 2' /usr/share/base-files/motd | md5sum | awk '{print $1}'`
    if [ "$oldmd" != "$newmd" ]; then
      if grep -q "$oldmd" /usr/share/base-files/motd.md5sums; then
        awk 'NR <= 2' /etc/motd > /etc/motd.new
        awk 'NR > 2' /usr/share/base-files/motd >> /etc/motd.new
        mv /etc/motd /etc/motd.old
        mv /etc/motd.new /etc/motd
      fi
    fi
  fi
fi