summaryrefslogtreecommitdiffstats
path: root/debian/postinst
blob: d7bf2bcb3bfa46d6ac8b70f2ea3aaeaa8e1f6f22 (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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
#!/bin/sh
set -e

ensure_file_owner_mode() {
  if [ ! -f "$DPKG_ROOT$1" ]; then
    : > "$DPKG_ROOT$1"
  fi
  chown "$2" "$DPKG_ROOT$1"
  chmod "$3" "$DPKG_ROOT$1"
}

install_local_dir() {
  if [ ! -d "$DPKG_ROOT$1" ]; then
    mkdir -p "$DPKG_ROOT$1"
  fi
  if [ -f "$DPKG_ROOT/etc/staff-group-for-usr-local" ]; then
    chown root:staff "$DPKG_ROOT$1" 2>/dev/null || true
    chmod 2775 "$DPKG_ROOT$1" 2> /dev/null || true
  fi
}

install_from_default() {
  if [ ! -f "$DPKG_ROOT$2" ]; then
    cp -p "$DPKG_ROOT/usr/share/base-files/$1" "$DPKG_ROOT$2"
  fi
}

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

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

update_to_current_default() {
  if [ -f "$2" ]; then
    md5=$(md5sum "$2" | cut -f 1 -d " ")
    if grep -q "$md5" "/usr/share/base-files/$1.md5sums"; then
      if ! cmp -s "/usr/share/base-files/$1" "$2"; then
        cp -p "/usr/share/base-files/$1" "$2"
        echo Updating $2 to current default.
      fi
    fi
  fi
}

# remove debian origin default symlink
if [ -h "$DPKG_ROOT/etc/dpkg/origins/default" ]; then
  if [ "`readlink "$DPKG_ROOT/etc/dpkg/origins/default"`" = "debian" ]; then
    rm -f "$DPKG_ROOT/etc/dpkg/origins/default"
  fi
fi

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

if [ "$1" = "configure" ] && [ "$2" = "" ]; then
  install_from_default dot.profile   /root/.profile
  install_from_default dot.bashrc    /root/.bashrc
  install_from_default profile       /etc/profile
  install_from_default motd          /etc/motd
  install_directory mnt       755 root
  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 var/mail 2775 mail
  if [ ! -L "$DPKG_ROOT/var/spool/mail" ]; then
    ln -s ../mail "$DPKG_ROOT/var/spool/mail"
  fi
  install_directory run/lock 1777 root
  migrate_directory /var/run /run
  migrate_directory /var/lock /run/lock

  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/libexec
  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 "$DPKG_ROOT/usr/local/man"

  ensure_file_owner_mode /var/log/wtmp root:utmp 664
  ensure_file_owner_mode /var/log/btmp root:utmp 660
  ensure_file_owner_mode /var/log/lastlog root:utmp 664
fi

if [ -d "$DPKG_ROOT/usr/share/info" ] && [ ! -f "$DPKG_ROOT/usr/info/dir" ] && [ ! -f "$DPKG_ROOT/usr/share/info/dir" ]; then
  install_from_default info.dir /usr/share/info/dir
  chmod 644 $DPKG_ROOT/usr/share/info/dir
fi

if [ "$1" = "configure" ] && [ "$2" != "" ]; then
  update_to_current_default profile       /etc/profile
  update_to_current_default dot.profile   /root/.profile
  update_to_current_default motd          /etc/motd
  if dpkg --compare-versions "$2" lt-nl "7.7"; then
    install_directory mnt 755 root
  fi
fi

case "${1}" in
	configure)
		. /usr/share/debconf/confmodule

		db_get base-files/os-identification
		OS_IDENTIFICATION="${RET}" # select (w/o empty)

		db_stop

		rm -f /etc/lsb-release
		rm -f /usr/lib/os-release
		rm -f /etc/dpkg/origins/default
		rm -f /etc/dpkg/origins/progress-linux
		rm -f /etc/progress-linux_version

		case "${OS_IDENTIFICATION}" in
			debian)
				cp /usr/share/base-files/debian/os-release /usr/lib/os-release
				ln -s debian /etc/dpkg/origins/default
				;;

			progress-linux)
				cp /usr/share/base-files/progress-linux/lsb-release /etc/lsb-release
				cp /usr/share/base-files/progress-linux/os-release /usr/lib/os-release
				cp /usr/share/base-files/progress-linux/progress-linux /etc/dpkg/origins/progress-linux
				ln -s progress-linux /etc/dpkg/origins/default
				cp /usr/share/base-files/progress-linux/progress-linux_version /etc/progress-linux_version
				;;
		esac
		;;
esac