-
Notifications
You must be signed in to change notification settings - Fork 13
/
install-base
executable file
·219 lines (207 loc) · 5.09 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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
#!/bin/bash
#
# Install base-specific configuration and customization to a zone.
#
usage()
{
echo "usage: install-base [-hv] -c <config> [-d <date>] -n <name> -r <release> -z <zone>" >&2
exit 1
}
while getopts c:d:hn:r:vz: flag; do
case "${flag}" in
c) config=$OPTARG ;;
d) dflag=$OPTARG ;;
n) name=$OPTARG ;;
r) release=$OPTARG ;;
v) verbose=1 ;;
z) zone=$OPTARG ;;
*) usage ;;
esac
done
#
# Sanity checks.
#
for var in config name 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|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
#
# Get a single version string we can use for comparison
#
OIFS=${IFS}
IFS="."
set -- ${release}
releasenum=$(for i; do printf "%02d" $i 2>/dev/null; done)
IFS=${OIFS}
#
# The basic set of packages from the minimal bootstrap. Only list packages
# that may require 'pkg_add -u' at build time, and even then we really should
# just use an updated bootstrap kit.
#
# Any package in the list will be marked keepable due to the explicit upgrade.
#
if [ ${releasenum} -ge 230400 ]; then
bootstrap_packages=(
mozilla-rootcerts-openssl
pkg_alternatives
pkg_install
pkgin
pkgsrc-gnupg-keys
)
else
bootstrap_packages=(
mozilla-rootcerts
openssl
pkg_alternatives
pkg_install
pkgin
pkgsrc-gnupg-keys
)
fi
#
# Minimal images only add that which is required to get a zone to boot.
#
minimal_packages=(
${bootstrap_packages[@]}
changepass
smtools
zoneinit
)
#
# Base adds a set of common packages on top of minimal.
#
npm=
if [ ${releasenum} -ge 180200 ] && [ ${releasenum} -lt 230400 ]; then
npm="npm"
fi
base_packages=(
${minimal_packages[@]}
coreutils
curl
diffutils
findutils
gawk
grep
gsed
gtar-base
less
nodejs
${npm}
patch
perl
postfix
rsyslog
sudo
wget
)
#
# pkgbuild needs base + git
#
pkgbuild_packages=(
${base_packages[@]}
git-base
)
#
# Common settings.
#
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_PRODUCT="SmartOS Instance"
IMAGE_SHORTPRODUCT="Instance"
IMAGE_BRANCH="${config%-*}"
IMAGE_ARCH="${config##*-}"
IMAGE_NAME="${name}"
IMAGE_VERSION="${release}"
IMAGE_BOOTDATE="${dflag:+-$dflag}"
IMAGE_CSHPATH=$(echo ${IMAGE_PATH} | sed -e 's,:, ,g')
if [[ "$release" =~ ^trunk ]] || [ ${releasenum} -ge 220400 ]; then
IMAGE_GIT_BRANCH="release/${IMAGE_BRANCH}"
else
IMAGE_GIT_BRANCH="joyent/release/${IMAGE_BRANCH}"
fi
#
# Per-image settings.
#
if [[ "${name}" =~ ^base ]]; then
IMAGE_DOC="https://docs.tritondatacenter.com/public-cloud/instances/infrastructure/images/smartos/base"
IMAGE_PACKAGES="${base_packages[@]}"
elif [[ "${name}" =~ ^minimal ]]; then
IMAGE_DOC="https://docs.tritondatacenter.com/public-cloud/instances/infrastructure/images/smartos/minimal"
IMAGE_PACKAGES="${minimal_packages[@]}"
elif [[ "${name}" =~ ^pkgbuild ]]; then
IMAGE_DOC="https://docs.tritondatacenter.com/public-cloud/instances/infrastructure/images/smartos/pkgbuild"
IMAGE_PACKAGES="${pkgbuild_packages[@]}"
else
echo "ERROR: Unsupported image name '${name}'" >&2
exit 1
fi
#
# 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_BOOTDATE \
IMAGE_PRODUCT IMAGE_SHORTPRODUCT IMAGE_VERSION \
IMAGE_BRANCH IMAGE_GIT_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 base images.
#
if [[ "${name}" =~ ^(base|pkgbuild) ]]; then
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
fi
echo "Logging into ${zone} to run /root/customize"
zlogin ${zone} /root/customize