summaryrefslogtreecommitdiffstats
path: root/setup-alpine.in
blob: aeab41a43e358a45e36bc41b61f54759a707b753 (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
#!/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}"
}

while getopts "ah" opt ; do
	case $opt in
		a) ARCHIVE=yes;;
		h) usage;;
		*) usage;;
	esac
done
shift `expr $OPTIND - 1`

if [ "$ARCHIVE" ] ; then
	echo "Creating an Alpine overlay"
	init_tmpdir ROOT
else
	PKGADD=apk_add
fi

$PREFIX/sbin/setup-keymap
$PREFIX/sbin/setup-hostname
$PREFIX/sbin/setup-interfaces

# setup up dns if no dhcp was configured
grep '^iface.*dhcp' $ROOT/etc/network/interfaces > /dev/null ||\
	$PREFIX/sbin/setup-dns

# set root password
[ -z "$NOCOMMIT" ] && while ! passwd ; do echo "Please retry." ; done

rc-update -q add networking 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

printf "Setup internet apk repositories? [y/N]?"
default_read setuprepos "n"

if [ $setuprepos == "Y" ] || [ $setuprepos == "y" ]; then
	$PREFIX/sbin/setup-apkrepos
fi

printf "Change timezone (default is UTC)? [y/N]?"
default_read setuptz "n"

if [ $setuptz == "Y" ] || [ $setuptz == "y" ]; then
	$PREFIX/sbin/setup-timezone
fi