-
Notifications
You must be signed in to change notification settings - Fork 13
/
create-smf-repo
executable file
·139 lines (127 loc) · 4.14 KB
/
create-smf-repo
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
#!/bin/bash
#
# CDDL HEADER START
#
# The contents of this file are subject to the terms of the
# Common Development and Distribution License (the "License").
# You may not use this file except in compliance with the License.
#
# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
# or http://www.opensolaris.org/os/licensing.
# See the License for the specific language governing permissions
# and limitations under the License.
#
# When distributing Covered Code, include this CDDL HEADER in each
# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
# If applicable, add the following below this CDDL HEADER, with the
# fields enclosed by brackets "[]" replaced with your own identifying
# information: Portions Copyright [yyyy] [name of copyright owner]
#
# CDDL HEADER END
#
# Copyright (c) 2012 Joyent, Inc. All rights reserved.
# Copyright (c) 2022 MNX Cloud. All rights reserved.
#
#
# This tool builds a small SMF seed repository for a given brand based on its
# manifests file which is used by our zones service.
#
#
# Changes for this 'imagetools' version:
#
# * Use a configurable location to the 'smartos-live' build area
# * Copy in manifests from multiple locations, and show where they came from.
#
if [ $# -ne 3 ]; then
echo "usage: $0 <smartoslive> <manifests> <output>" >&2
exit 2
else
SMARTOS_LIVE=$1; shift
MANIFEST_LIST=$1; shift
OUTPUT=$1; shift
fi
SVCCFG="${SMARTOS_LIVE}/projects/illumos/usr/src/cmd/svc/svccfg/svccfg-native"
CONFIGD="${SMARTOS_LIVE}/projects/illumos/usr/src/cmd/svc/configd/svc.configd-native"
#MANIFEST_LIST="${SMARTOS_LIVE}/overlay/generic/usr/lib/brand/joyent/manifests"
MANIFESTS_LOCAL="$(dirname $0)/manifest"
MANIFESTS_GENERIC="${SMARTOS_LIVE}/overlay/generic/lib/svc/manifest"
MANIFESTS_PROTO="${SMARTOS_LIVE}/proto/lib/svc/manifest"
MANIFESTS_SMARTOS="${SMARTOS_LIVE}/overlay/smartos/lib/svc/manifest"
TMPFILE="/tmp/$(basename $0).$$"
function fail
{
local msg="$*"
[[ -z "$msg" ]] && msg="failed"
echo "$msg" >&2
exit 1
}
#
# XXX We really want to control this in a different way. We'd really rather not
# have to hardcode machinations on the XML format of a manifest, because really,
# that's just bad. On the flip side, we can't use libscf, but we can change the
# file format that we use, which is probably what makes sense in the long run.
# e.g. because a manifest can deliver more than one instance, we'd need to
# explicitly call out which instances delivered by the manifest we'd like to
# enable and disable.
#
function import_manifest
{
local svc
if [ -f "$MANIFESTS_LOCAL/$1" ]; then
svc="$MANIFESTS_LOCAL/$1"
echo -n "local: "
elif [ -f "$MANIFESTS_GENERIC/$1" ]; then
svc="$MANIFESTS_GENERIC/$1"
echo -n "generic: "
elif [ -f "$MANIFESTS_PROTO/$1" ]; then
svc="$MANIFESTS_PROTO/$1"
echo -n "proto: "
elif [ -f "$MANIFESTS_SMARTOS/$1" ]; then
svc="$MANIFESTS_SMARTOS/$1"
echo -n "smartos: "
else
fail "cannot find $1"
fi
on=""
[[ ! -f "$svc" ]] && fail "cannot find $svc"
nawk -v status=$2 < $svc > $TMPFILE '{
if (($1 == "<instance" &&
$2 == "name=\047default\047") ||
$1 == "<create_default_instance") {
if (status == "enabled")
n=sub("\047false\047", "\047true\047")
else
n=sub("\047true\047", "\047false\047")
}
print $0
}'
[[ $? -eq 0 ]] || fail "failed to nawk manifest"
$SVCCFG import $TMPFILE || fail "failed to import $svc"
rm -f $TMPFILE
}
function build_database
{
local input output
input=$1
output=$2
export SVCCFG_REPOSITORY=$output
export SVCCFG_CONFIGD_PATH=$CONFIGD
rm -f $SVCCFG_REPOSITORY
[[ -f $input ]] || fail "can't read manifest input file: $input"
while read service enabled import; do
[[ -z "$service" ]] && continue
[[ "$service" =~ ^\# ]] && continue
[[ "$import" == "noimport" ]] && continue
import_manifest $service $enabled
echo $service $enabled
done < $input
}
#
# We need to walk through a few different sources of brands and work through it.
# For now we only care about doing this for the minimal zone. Some day we can
# extend this to everything.
#
build_database ${MANIFEST_LIST} ${OUTPUT}
chmod 444 ${OUTPUT}
chown root:root ${OUTPUT}
echo "Generated ${OUTPUT}"