summaryrefslogtreecommitdiff
path: root/adelie-build-txz
blob: 1ae12fa3922679ff30dc4e883072cf2a4e672aea (plain) (blame)
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
#!/bin/sh

def_arch=$(uname -m)
def_ver="1.0-beta1"
declare -r PROGNAME=$(basename $0)


warn() {
    printf '>>> '
    printf '\033[01;33mWARNING\033[00;39m '
    printf '>>> '
    printf '\033[01;33mWARNING\033[00;39m '
    printf '>>> '
    printf '\033[01;33mWARNING\033[00;39m '
    printf '>>> '
    printf '\033[01;33mWARNING\033[00;39m '
    printf '>>>\n'
}


fatal() {
    printf '>>> '
    printf '\033[01;31mERROR\033[00;39m '
    printf '>>> '
    printf '\033[01;31mERROR\033[00;39m '
    printf '>>> '
    printf '\033[01;31mERROR\033[00;39m '
    printf '>>> '
    printf '\033[01;31mERROR\033[00;39m '
    printf '>>>\n'
}


ensure_commands() {
    if ! type apk>/dev/null 2>/dev/null; then
        fatal
        printf 'You must have apk installed.  On Gentoo, see sys-devel/apk-tools.\n'
        exit -1
    fi

    if ! type tar>/dev/null 2>/dev/null; then
        fatal
        printf 'You must have tar installed.\n'
        exit -1
    fi
}


usage() {
    printf 'usage: %s [-a ARCH] [-s] [-v VERSION] [--help]\n\n' $PROGNAME
    printf 'Create an Adélie Linux root FS tarball (.TXZ) using the specified parameters.\n\n'
    printf 'Default ARCH: %s\n' $def_arch
    printf 'Default VERSION: %s\n' $def_ver
}


while [ -n "$1" ]; do
    case $1 in
        -a | --arch)
            shift
            declare -r MY_ARCH=$1
            ;;
        -h | --help)
            usage
            exit
            ;;
        -s | --sign)
            declare -r SIGN=yes
            ;;
        -v | --version)
            shift
            declare -r MY_VER=$1
            ;;
        *)
            usage >&2
            exit -1
            ;;
    esac
    shift
done

set -a
declare -r ARCH=${MY_ARCH:-$def_arch}
declare -r LDARCH=${LDARCH:-$ARCH}
declare -r PHASE=${MY_PHASE:-all}
declare -r VERSION=${MY_VER:-$def_ver}
declare -r URL=${MY_URL:-https://distfiles.adelielinux.org/adelie/$VERSION/}
set +a

ensure_commands

header() {
	printf '\033[01;32m * \033[37m%s\033[00;39m\n' "$1"
}

header 'Adélie Linux Root FS Tarball Creation Tool'
printf '\n'

clean_dirs() {
	warn
	printf 'This will erase all files at the directories %s/rootfs-%s.\n\n' `pwd` $ARCH
	printf 'When you are ready, press RETURN.  To cancel, press Ctrl-C.\n'
	read

	rm -rf rootfs-$ARCH
	mkdir rootfs-$ARCH
	mkdir -p out
}

install_pkgs() {
	header "Installing base system to tar root..."

	declare -r PACKAGES=$(cat packages 2>/dev/null || fatal 'No core packages specified')
	declare -r ARCH_PKGS=$(cat packages-$ARCH 2>/dev/null || echo '')

	mkdir -p rootfs-$ARCH/etc/apk/keys
	cp 'packages@adelielinux.org.pub' rootfs-$ARCH/etc/apk/keys/
	# XXX: Handle pre-install scripts.
	mkdir -p rootfs-$ARCH/dev
	mknod rootfs-$ARCH/dev/urandom c 1 9
	mkdir -p rootfs-$ARCH/usr/sbin
	cp addgroup adduser rootfs-$ARCH/usr/sbin/
	apk --arch $ARCH \
		-X "$URL/system/$EXTRA_MIRROR" \
		-X "$URL/user/$EXTRA_MIRROR" \
		-U --root rootfs-$ARCH --initdb add $PACKAGES $ARCH_PKGS
}

make_structure() {
	mkdir -p rootfs-$ARCH/etc/runlevels/{sysinit,boot,default,shutdown}

	echo 'adelie-root' > rootfs-$ARCH/etc/hostname
	echo 'mtab_is_file=no' > rootfs-$ARCH/etc/conf.d/mtab

	for siservice in udev udev-trigger lvmetad; do
		ln -s /etc/init.d/$siservice \
		   rootfs-$ARCH/etc/runlevels/sysinit/$siservice
	done

	for bootservice in root binfmt bootmisc fsck hostname hwclock keymaps \
	    localmount loopback modules mtab procfs sysctl sysfsconf termencoding \
	    tmpfiles.setup urandom; do
		ln -s /etc/init.d/$bootservice \
		   rootfs-$ARCH/etc/runlevels/boot/$bootservice
	done

	cat >rootfs-$ARCH/etc/fstab <<- FSTAB
		# Welcome to Adélie Linux.
		# This fstab(5) is for the live media only.  Edit for use for your installation.

		tmpfs	/tmp		tmpfs	defaults	0	1
		proc	/proc		proc	defaults	0	1
	FSTAB

	cat >rootfs-$ARCH/etc/shells <<- SHELLS
		/bin/bash
		/bin/zsh
	SHELLS

	cat >rootfs-$ARCH/etc/resolv.conf <<- RESOLVE
		nameserver 84.200.69.80
		nameserver 2001:1608:10:25::1c04:b12f
	RESOLVE

	cat >rootfs-$ARCH/etc/apk/repositories <<-REPOS
		https://distfiles.adelielinux.org/adelie/$VERSION/system/$EXTRA_MIRROR
		https://distfiles.adelielinux.org/adelie/$VERSION/user/$EXTRA_MIRROR
	REPOS

	cp AdelieTux.icns rootfs-$ARCH/.VolumeIcon.icns

	# Put a copy of the kernel(s) in the kernels-$ARCH/ directory, so that
	# users may download them for netbooting or such.
	mkdir -p out/kernels/$ARCH
	cp rootfs-$ARCH/boot/* out/kernels/$ARCH/
}

tar_it() {
	header 'Creating compressed file system image...'

	cd rootfs-$ARCH
	tar -cJf ../out/adelie-rootfs-$ARCH-$VERSION-$(date +%Y%m%d).txz .
}

# in case we want to add phase support like adelie-build-cd has later
case $PHASE in
	clean)
		clean_dirs
		;;
	install)
		install_pkgs
		make_structure
		;;
	tar)
		tar_it
		;;
	*)
		clean_dirs
		install_pkgs
		make_structure
		tar_it
		;;
#	*)
#		fatal
#		printf 'Unknown phase %s.  Stop.\n' $PHASE
#		;;
esac