forked from TritonDataCenter/imagetools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall-base
executable file
·166 lines (156 loc) · 4.08 KB
/
install-base
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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
#!/bin/bash
#
# Install base-specific configuration and customization to a zone.
#
usage()
{
echo "usage: install-base [-hv] -c <config> [-n <name>] -r <release> -z <zone>" >&2
exit 1
}
while getopts c:hn:r:vz: flag; do
case "${flag}" in
c) config=$OPTARG ;;
n) name=$OPTARG ;;
r) release=$OPTARG ;;
v) verbose=1 ;;
z) zone=$OPTARG ;;
*) usage ;;
esac
done
#
# Sanity checks.
#
for var in config release zone; do
if [ -z "${!var}" ]; then
echo "ERROR: ${var} not set" >&2
usage
fi
done
if [[ ! "${config}" =~ ^([0-9]{4}Q[0-9]|trunk)-(i386|x86_64|sngl|multiarch) ]]; then
echo "ERROR: Unsupported configuration: ${config}" >&2
exit 1
fi
if ! zoneadm -z ${zone} list >/dev/null 2>&1; then
echo "ERROR: Zone does not exist: ${zone}" >&2
exit 1
fi
if [ "$(dirname $0)" != "." ]; then
echo "ERROR: This script must be run from the imagetools directory." >&2
exit 1
fi
#
# Set up configuration variables for the specified target.
#
IMAGE_PACKAGES="
changepass
coreutils
curl
diffutils
duo-unix
findutils
gawk
genbfpw
grep
gsed
gtar-base
guardtime
less
mozilla-rootcerts
nodejs
patch
pkg_alternatives
postfix
sdc-manta
sdc-smartdc
smtools
sudo
"
if [[ "${config}" =~ sngl ]]; then
CRLE_DPATH_32="/system/lib:/system/usr/lib"
CRLE_DPATH_64="/system/lib/64:/system/usr/lib/64"
CRLE_TPATH_32="/system/lib/secure:/system/usr/lib/secure"
CRLE_TPATH_64="/system/lib/secure/64:/system/usr/lib/secure/64"
IMAGE_MANDIRS="/usr/share/man:/system/usr/share/man"
# Base vim doesn't work due to missing terminfo.
IMAGE_PACKAGES="${IMAGE_PACKAGES} vim"
IMAGE_PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin"
IMAGE_PREFIX="/usr"
IMAGE_SYSCONFDIR="/etc"
IMAGE_DOC="http://wiki.joyent.com/jpc2/SNGL+Instance"
else
CRLE_DPATH_32="/lib:/usr/lib"
CRLE_DPATH_64="/lib/64:/usr/lib/64"
CRLE_TPATH_32="/lib/secure:/usr/lib/secure"
CRLE_TPATH_64="/lib/secure/64:/usr/lib/secure/64"
IMAGE_MANDIRS="/opt/local/man:/usr/share/man"
IMAGE_PATH="/usr/local/sbin:/usr/local/bin:/opt/local/sbin:/opt/local/bin:/usr/sbin:/usr/bin:/sbin"
IMAGE_PREFIX="/opt/local"
IMAGE_SYSCONFDIR="/opt/local/etc"
IMAGE_DOC="http://wiki.joyent.com/jpc2/SmartMachine+Base"
fi
# Older images require groff.
if [[ "${config}" =~ ^(201[012]|2013Q[12]) ]]; then
IMAGE_PACKAGES="${IMAGE_PACKAGES} groff"
fi
if [[ "${config}" =~ ^(2013Q[34]|201[4-9]) ]]; then
IMAGE_PACKAGES="${IMAGE_PACKAGES} rsyslog zoneinit"
fi
IMAGE_PRODUCT="Joyent Instance"
IMAGE_SHORTPRODUCT="Instance"
IMAGE_BRANCH="${config%-*}"
IMAGE_ARCH="${config##*-}"
IMAGE_VERSION="${release}"
if [ -n "${name}" ]; then
IMAGE_NAME="${name}"
else
IMAGE_NAME="${IMAGE_ARCH}"
fi
IMAGE_CSHPATH=$(echo ${IMAGE_PATH} | sed -e 's,:, ,g')
IMAGE_PACKAGES=$(echo ${IMAGE_PACKAGES} | tr '\n' ' ')
#
# Ok, we should have all the configuration setup we need, now we start
# applying the overlay.
#
zoneroot="/zones/${zone}/root"
if [ ! -d ${zoneroot} ]; then
echo "ERROR: Cannot find zone directory." >&2
exit 1
fi
for var in CRLE_DPATH_32 CRLE_DPATH_64 CRLE_TPATH_32 CRLE_TPATH_64 \
IMAGE_PATH IMAGE_CSHPATH IMAGE_MANDIRS \
IMAGE_PREFIX IMAGE_SYSCONFDIR \
IMAGE_PRODUCT IMAGE_SHORTPRODUCT IMAGE_VERSION \
IMAGE_BRANCH IMAGE_ARCH IMAGE_NAME IMAGE_DOC IMAGE_PACKAGES
do
sedsubst="${sedsubst} s!@${var}@!${!var}!g;"
done
for dir in etc root
do
#
# Find all the files in the overlay directory, ensure their target
# directories exist, and then filter them through the configuration
# generator before installing to the target.
#
for f in $(find overlay/${dir} -type f)
do
basef=${f##overlay/}
echo "Installing /${basef}"
mkdir -p ${zoneroot}/$(dirname ${basef})
sed -e "${sedsubst}" ${f} >${zoneroot}/${basef}
if [ -x ${f} ]; then
chmod +x ${zoneroot}/${basef}
fi
done
done
#
# Install IMAGE_SYSCONFDIR files into the correct location
#
for f in $(find overlay/sysconfdir -type f)
do
basef=${f##overlay/sysconfdir/}
echo "Installing ${IMAGE_SYSCONFDIR}/${basef}"
mkdir -p ${zoneroot}${IMAGE_SYSCONFDIR}/$(dirname ${basef})
sed -e "${sedsubst}" ${f} >${zoneroot}${IMAGE_SYSCONFDIR}/${basef}
done
echo "Logging into ${zone} to run /root/customize"
zlogin ${zone} /root/customize