/
customize
executable file
·68 lines (58 loc) · 1.77 KB
/
customize
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
#!/bin/bash
#
# Copyright (c) 2013 Joyent Inc., All Rights Reserved.
#
set -o errexit
set -o pipefail
status=0
BUILDSTAMP=$2
if [[ -z "${BUILDSTAMP}" ]]; then
BUILDSTAMP=$(TZ=UTC date "+%Y%m%dT%H%M%SZ")
fi
rdmnt=$1
if [[ -z "${rdmnt}" ]]; then
echo "Usage: $0 <rdmnt directory> [buildstamp]"
exit 1
fi
echo "Customizing ${rdmnt}"
pfexec cp /dev/null ${rdmnt}/etc/mnttab
pfexec cp /dev/null ${rdmnt}/var/log/syslog
pfexec cp /dev/null ${rdmnt}/var/adm/wtmpx
pfexec mount -F lofs /dev ${rdmnt}/dev
# If we're in a GZ there will be a /devices we need to
if [[ -d /devices ]]; then
pfexec mount -F lofs /devices ${rdmnt}/devices
fi
pfexec /usr/bin/catman -M "${rdmnt}/usr/share/man:${rdmnt}/smartdc/man" \
-T "${rdmnt}/usr/share/lib/tmac/ansun"
#
# catman(1) will happily create new cat pages even if the original man page is
# a symbolic link to another. This is quite wasteful of space; remove such
# cat pages and replace them with links also.
#
(cd "${rdmnt}/usr/share/man" && for cdir in *; do
[[ -d "${cdir}" ]] || continue
(cd "${cdir}" && for catpage in *; do
manpage="${rdmnt}/usr/share/man/${cdir/cat/man}/${catpage}"
if [[ -L "${manpage}" && ! -L "${catpage}" ]]; then
link="$(readlink ${manpage})"
if [[ ! -f "${rdmnt}/usr/share/man/${cdir}/${link}" ]]
then
echo "FAIL: Missing catpage link source ${link}"
status=1
else
echo "Replacing cat page ${catpage} with link"
pfexec rm -f "${catpage}"
pfexec ln -s "${link}" "${catpage}"
fi
fi
done)
done)
if [[ -d /devices ]]; then
pfexec umount ${rdmnt}/devices
fi
pfexec umount ${rdmnt}/dev
pfexec chown root:root ${rdmnt}
pfexec gsed -i -e "s/ [0-9]\{8\}T[0-9]\{6\}Z/ ${BUILDSTAMP}/" ${rdmnt}/etc/motd
pfexec gsed -i -e "s/ [0-9]\{8\}T[0-9]\{6\}Z/ ${BUILDSTAMP}/" ${rdmnt}/etc/issue
exit $status