Repository navigation
Expand file tree
/
Copy pathinstall
More file actions
executable file
·260 lines (209 loc) · 5.62 KB
/
Copy pathinstall
File metadata and controls
executable file
·260 lines (209 loc) · 5.62 KB
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
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
#!/usr/bin/env bash
#
# Copyright (c) 2015 Joyent Inc., All rights reserved.
#
# Install Alpine into a directory, modify the installation, then tar it up.
#
if [[ -n "$TRACE" ]]; then
export PS4='[\D{%FT%TZ}] ${BASH_SOURCE}:${LINENO}: ${FUNCNAME[0]:+${FUNCNAME[0]}(): }'
set -o xtrace
fi
set -euo pipefail
IFS=$'\n\t'
GUESTTOOLS=guesttools
BUILD_DATE=$(date +%Y%m%d)
export PATH=$PATH:/sbin:/bin
usage() {
cat <<EOF
Install and modify Void in a given directory in a given directory using a given mirror
Usage:
$0 -a <ARCH> -x <XBPS_TOOLS> -d <INSTALL_DIR> -m <MIRROR> -i <IMAGE_NAME> -p <NAME> -D <DESC> -u <DOCS>
Example:
$0 -a <x86_64-musl> -x xbps-static-latest.x86_64-musl.tar.xz -d /data/void -m https://alpha.de.repo.voidlinux.org -i void -p "Void Linux" -D "Void 64-bit lx-brand image." -u https://docs.joyent.com/images/container-native-linux
OPTIONS:
-x The required xbps-tools-static package (e.g. xbps-static-latest.x86_64-musl.tar.xz)
-d A path to the install directory
-m A URL for the desired archive mirror
-i The name of the image. This is used for naming the tarball.
-p The proper name of the image. Use quotes. This is used in the MOTD and /etc/product file.
-D A description for the image. This is used in the image manifest and the /etc/product file.
-u A URL to the image docs [optional]
-h Show this message
EOF
}
ARCH=
XBPS_TOOLS=
INSTALL_DIR=
MIRROR=
IMAGE_NAME=
NAME=
DESC=
DOCS=
while getopts "ha:x:d:m:i:p:D:u:" OPTION
do
case $OPTION in
h)
usage
exit
;;
a)
ARCH=${OPTARG}
;;
x)
XBPS_TOOLS=${OPTARG}
;;
d)
INSTALL_DIR=${OPTARG%/}
;;
m)
MIRROR=${OPTARG%/}
;;
i)
IMAGE_NAME=${OPTARG}
;;
p)
NAME=${OPTARG}
;;
D)
DESC=${OPTARG}
;;
u)
DOCS=${OPTARG}
;;
\?)
usage
exit
;;
esac
done
if [[ $# -eq 0 ]]; then
usage
exit 1
fi
if [[ -z ${ARCH} ]]; then
echo "Error: missing arch (-a) value x86_64 || x86_64-musl"
exit 1
fi
if [[ -z ${XBPS_TOOLS} ]]; then
echo "Error: missing void-tools-static package (-x) value"
exit 1
fi
if [[ ! -e ${INSTALL_DIR} ]] ; then
echo "Directory $INSTALL_DIR not found"
exit 1
fi
if [[ -z ${INSTALL_DIR} ]]; then
echo "Error: missing install directory (-d) value"
exit 1
fi
if [[ -z ${MIRROR} ]]; then
echo "Error: missing libc (-m) value"
exit 1
fi
if [[ -z ${IMAGE_NAME} ]]; then
echo "Error: missing image name (-i) value"
exit 1
fi
if [[ -z ${NAME} ]]; then
echo "Error: missing proper name (-p) value"
exit 1
fi
TARGET="${IMAGE_NAME}-${BUILD_DATE}.tar.gz"
if [[ -z ${DOCS} ]]; then
DOCS="https://docs.joyent.com/images/container-native-linux"
fi
echo "==> Installing Void into $INSTALL_DIR"
if [[ -d $INSTALL_DIR ]]; then
echo "====> Found previous chroot. Deleting and creating a new one."
if [[ $(mount | grep -c $INSTALL_DIR/proc) -gt 0 ]]; then
umount $INSTALL_DIR/proc
fi
if [[ $(mount | grep -c $INSTALL_DIR/sys) -gt 0 ]]; then
umount $INSTALL_DIR/sys
fi
rm -rf $INSTALL_DIR
mkdir -p $INSTALL_DIR
fi
echo "===> Getting Void ..."
if [[ ! -d tmp/ ]]; then
echo "===> creating tmp/ directory"
mkdir tmp
fi
cd tmp/
export BIN="./usr/bin"
wget -O - ${MIRROR}/static/xbps-static-latest.$(uname -m)-musl.tar.xz | \
tar Jx
echo "==> Adding void keys"
mkdir -p ${INSTALL_DIR}/var/db/xbps/keys \
&& cp ../keys/* ${INSTALL_DIR}/var/db/xbps/keys/
echo "===> Installing Void base from ${MIRROR}"
XBPS_ARCH=${ARCH} ${BIN}/xbps-install.static -yMU \
--repository=${MIRROR}/current \
--repository=${MIRROR}/current/musl \
-r ${INSTALL_DIR} \
base-minimal \
ca-certificates \
bash \
jq \
curl \
gettext \
less \
man \
openssh \
tzdata \
vim \
pam \
wget \
ncurses \
iproute2 \
iputils
chroot ${INSTALL_DIR} xbps-reconfigure -a
echo "==> Removing unecessary runit services"
rm -rf ${INSTALL_DIR}/etc/runit/core-services/01-static-devnodes.sh
rm -rf ${INSTALL_DIR}/etc/runit/core-services/02-kmods.sh
rm -rf ${INSTALL_DIR}/etc/runit/core-services/02-udev.sh
rm -rf ${INSTALL_DIR}/etc/runit/core-services/03-filesystems.sh
echo "==> linking required runit services"
chroot ${INSTALL_DIR} ln -s /etc/sv/sshd /etc/runit/runsvdir/default
echo "==> removing agetty from default"
for i in {1..6}; do
touch ${INSTALL_DIR}/etc/sv/agetty-tty$i/down
rm -rf ${INSTALL_DIR}/etc/runit/runsvdir/default/agetty-tty$i
done
# Set random root pw
chroot ${INSTALL_DIR} passwd -d root
echo "==> Setting TZ to UTC"
#chroot $INSTALL_DIR apk add --update tzdata
#cp $INSTALL_DIR/usr/share/zoneinfo/UTC $INSTALL_DIR/etc/localtime
#chroot $INSTALL_DIR apk del --purge tzdata
echo "==> Disabling PasswordAuthentication"
sed -ri s/^#?PasswordAuthentication\ no/PasswordAuthentication\ no/ -i $INSTALL_DIR/etc/ssh/sshd_config
sed -ri s/^#?PasswordAuthentication\ yes/PasswordAuthentication\ no/ -i $INSTALL_DIR/etc/ssh/sshd_config
echo "==> Creating /etc/motd"
cat << MOTD > $INSTALL_DIR/etc/motd
__ . .
_| |_ | .-. . . .-. :--. |-
|_ _| ;| || |(.-' | | |
|__| \`--' \`-' \`;-| \`-' ' ' \`-'
/ ; Instance ($NAME $BUILD_DATE)
\`-' $DOCS
MOTD
echo "==> Creating /etc/product file"
cat << PRODUCT > $INSTALL_DIR/etc/product
Name: Joyent Instance
Image: $NAME $BUILD_DATE
Documentation: $DOCS
Description: $DESC
PRODUCT
touch ${INSTALL_DIR}/etc/void-release
echo "==> Installing Guest tools in $INSTALL_DIR"
echo "====> Running ./install.sh -i $INSTALL_DIR"
(
cd ../$GUESTTOOLS
./install.sh -i $INSTALL_DIR
)
echo "==> Saving installation as $TARGET. This may take a few minutes."
tar czf $TARGET --exclude-from=../exclude.txt $INSTALL_DIR/
echo "==> Installation complete!"
echo "==> $TARGET"
exit 0