blob: 82f09bc7a032befee45f9fbb5fc195b4a33d3241 (
plain)
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
|
#!/bin/sh
PROGRAM=setup-alpine
VERSION=@VERSION@
PREFIX=
. $PREFIX/lib/libalpine.sh
# Extract fully qualified domain name from current hostname. If none is
# currently set, use 'my.domain'.
get_fqdn() {
local _dn
_dn=$(hostname -f 2>/dev/null)
_dn=${_dn#$(hostname -s 2>/dev/null)}
_dn=${_dn#.}
echo "${_dn:=my.domain}"
}
usage() {
cat <<__EOF__
usage: setup-alpine [-ha] [-f FILE] [-c FILE]
Setup Alpine Linux
options:
-h Show this help
-a Create Alpine Linux overlay file
-f Answer file to use installation
-c Create answer file (do not install anything)
__EOF__
exit 1
}
while getopts "af:c:h" opt ; do
case $opt in
a) ARCHIVE=yes;;
f) USEANSWERFILE="$OPTARG";;
c) CREATEANSWERFILE="$OPTARG";;
h) usage;;
*) usage;;
esac
done
shift `expr $OPTIND - 1`
if [ "$USEANSWERFILE" != "" ]; then
if [ -e "$USEANSWERFILE" ]; then
. "$USEANSWERFILE"
fi
fi
if [ "$CREATEANSWERFILE" != "" ]; then
touch "$CREATEANSWERFILE" || echo "Cannot touch file $CREATEANSWERFILE"
cat <<__EOF__ > "$CREATEANSWERFILE"
# Example answer file for setup-alpine script
# If you don't want to use a certain option, then comment it out
# Use US layout with US variant
KEYMAPOPTS="us us"
# Set hostname to alpine-test
HOSTNAMEOPTS="-n alpine-test"
# Contents of /etc/network/interfaces
INTERFACESOPTS="auto lo
iface lo inet loopback
auto eth0
iface eth0 inet dhcp
hostname alpine-test
"
# Search domain of example.com, Google public nameserver
DNSOPTS="-d example.com -n 8.8.8.8"
# Set timezone to UTC
TIMEZONEOPTS="-z UTC"
# Add a random mirror
APKREPOSOPTS="-r"
# Install Openssh
SSHDOPTS="-c openssh"
# Use openntpd
NTPOPTS="-c openntpd"
# Use /dev/sda as a data disk
DISKOPTS="-m data /dev/sda"
# Setup in /media/sdb1
LBUOPTS="/media/sdb1"
APKCACHEOPTS="/media/sdb1/cache"
__EOF__
echo "Answer file $CREATEANSWERFILE has been created. Please add or remove options as desired in that file"
exit 0
fi
if [ "$ARCHIVE" ] ; then
echo "Creating an Alpine overlay"
init_tmpdir ROOT
else
PKGADD=apk_add
fi
$PREFIX/sbin/setup-keymap ${KEYMAPOPTS}
$PREFIX/sbin/setup-hostname ${HOSTNAMEOPTS}
if [ -n "$INTERFACESOPTS" ]; then
printf "$INTERFACESOPTS" | $PREFIX/sbin/setup-interfaces -i
else
$PREFIX/sbin/setup-interfaces
fi
# start the networking in background
/etc/init.d/networking --quiet start &
# setup up dns if no dhcp was configured
grep '^iface.*dhcp' $ROOT/etc/network/interfaces > /dev/null ||\
$PREFIX/sbin/setup-dns ${DNSOPTS}
# set root password
[ -z "$NOCOMMIT" ] && while ! passwd ; do echo "Please retry." ; done
# pick timezone
$PREFIX/sbin/setup-timezone ${TIMEZONEOPTS}
rc-update -q add networking boot
rc-update -q add urandom boot
rc-update -q add acpid
rc-update -q add cron
# enable new hostname
/etc/init.d/hostname --quiet restart
# start up the services
rc boot
rc default
# update /etc/hosts - after we have got dhcp address
# Get default fully qualified domain name from *first* domain
# given on *last* search or domain statement.
_dn=$(sed -n \
-e '/^domain[[:space:]][[:space:]]*/{s///;s/\([^[:space:]]*\).*$/\1/;h;}' \
-e '/^search[[:space:]][[:space:]]*/{s///;s/\([^[:space:]]*\).*$/\1/;h;}' \
-e '${g;p;}' /etc/resolv.conf 2>/dev/null)
_hn=$(hostname)
_hn=${_hn%%.*}
sed -i -e "s/^127\.0\.0\.1.*/127.0.0.1\t${_hn}.${_dn:-$(get_fqdn)} ${_hn} localhost.localdomain localhost/" /etc/hosts
$PREFIX/sbin/setup-apkrepos ${APKREPOSOPTS}
$PREFIX/sbin/setup-sshd ${SSHDOPTS}
$PREFIX/sbin/setup-ntp ${NTPOPTS}
DEFAULT_DISK=none \
$PREFIX/sbin/setup-disk -q ${DISKOPTS}
if [ "`cat /tmp/alpine-install-diskmode.out`" != "sys" ]; then
$PREFIX/sbin/setup-lbu ${LBUOPTS}
$PREFIX/sbin/setup-apkcache ${APKCACHEOPTS}
fi
|