-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathinstall.sxxu
182 lines (147 loc) · 4.48 KB
/
install.sxxu
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
#!/bin/ksh -
# $Id$
# Copyright (c) 2010 Andrew Fresh <[email protected]>
#
# Permission to use, copy, modify, and distribute this software for any
# purpose with or without fee is hereby granted, provided that the above
# copyright notice and this permission notice appear in all copies.
#
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#
# based on (and some parts taken from) siteXXtools/install.site
# Copyright (c) 2006 Alex Holst <[email protected]>
BASEDIR=/var/siteXX
useradd_args="-m -gid =uid"
[ -e $BASEDIR/siteXXrc ] && . $BASEDIR/siteXXrc
export PKG_PATH
do_pre() {
echo 'Running post install from sxxu'
}
do_post() {
echo 'See /var/log/install.log for install messages.'
}
rename_hostname_if() {
echo ' ==> Renaming hostname.if'
local _f
local _int
for _f in /etc/hostname.*; do
eval _int=\${${_f#*hostname.}_if}
[ -z "$_int" ] && continue
echo " => $_f -> hostname.$_int";
mv $_f /etc/hostname.$_int
done
}
process_roles() {
local _oldpwd="${PWD}"
cd "${BASEDIR}"
if [ ! -e roles ]; then
echo 'No roles defined.'
exit
fi
local _roles
unset _roles
set -A _roles
local _role
while read _role; do
if [ -n "${_role}" ]; then
_role=${_role%%#*} # strip comments
test -z "$_role" && continue
_roles[${#_roles[@]}]="$_role"
fi
done < roles
for _role in "${_roles[@]}"; do
apply_role "$_role"
done
rename_hostname_if
cd "${_oldpwd}"
}
append_pkg_path() {
[ -e pkg_path -o -d packages ] || return
echo ' ==> Setting PKG_PATH'
[ -d packages ] && PKG_PATH="${PKG_PATH}:${PWD}/packages"
[ -e pkg_path ] || return;
local _line
while read _line; do
_line=${_line%%#*} # strip comments
[ -z "$_line" ] && continue
PKG_PATH="${PKG_PATH}:${_line}"
done < pkg_path
PKG_PATH=`eval echo $PKG_PATH | sed -e 's/^:*//'`
}
run_command_lists() {
local _f
for _f in *_list; do
[ ! -f "${_f}" ] && continue
local _cmd=`basename "${_f%_list}"`
local _args=`eval echo \\${${_cmd}_args}`
echo " ==> Running $_cmd $_args"
local _line
while read _line; do
_line=${_line%%#*} # strip comments
test -z "$_line" && continue
echo " => ${_cmd} ${_args} ${_line}"
eval ${_cmd} ${_args} ${_line}
done < "${_f}"
done
}
apply_patches() {
[ ! -d patches ] && return
echo ' ==> Applying patches'
local _p
for _p in patches/*; do
[ X"patches/*" == X"${_p}" ] && continue
echo " => $_p"
# -N Always assume a forward patch.
# -t Never prompt; assume the user is expert
# -p0 full path, always
patch -N -t -p0 -d / < "$_p"
done
}
install_packages() {
[ ! -d packages ] && return
echo ' ==> Installing packages'
find packages -name '*.tgz' -print0 | xargs -0 pkg_add ${pkg_add_args}
}
apply_role() {
local _role="$1"
local _oldpwd="${PWD}"
local _rolepwd="${BASEDIR}/${_role}"
if [ ! -d "${_rolepwd}" ]; then
echo "===> Missing ${_role}"
return
fi
echo "===> Applying role ${_role}"
cd "${_rolepwd}"
if [ -e ./siteXXrc ]; then
echo ' ==> Including siteXXrc'
. ./siteXXrc
fi
cd "${_rolepwd}" && append_pkg_path
cd "${_rolepwd}" && run_command_lists
cd "${_rolepwd}" && apply_patches
cd "${_rolepwd}" && install_packages
cd "${_rolepwd}"
if [ -e ./install.site ]; then
if [ -x ./install.site ]; then
echo ' ==> Running install.site'
./install.site
else
echo ' ==> Including install.site'
. ./install.site
fi
fi
cd "${_oldpwd}"
}
if [ ! -d "${BASEDIR}" ]; then
echo Nothing to do.
exit
fi
do_pre 2>&1 | /usr/bin/tee /var/log/install.log
process_roles 2>&1 | /usr/bin/tee -a /var/log/install.log | grep '^...>'
do_post 2>&1 | /usr/bin/tee -a /var/log/install.log