summaryrefslogtreecommitdiff
path: root/build-rootfs.sh
blob: 76daf667f908bc21a05fb07cbc0776f6839eb753 (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
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
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
#!/bin/sh
set -e
release=stretch
img_name=2018-06-27
img_file=debootstrap/${release}-minbase-amd64.${img_name}.btrfs

die() { printf '%s\n' "$*" >&2; exit 1; }

chroot="./debootstrap.sh chroot $release $img_name"
img_sh="./debootstrap.sh sh     $release $img_name"

install_packages()
{
#    $chroot env DEBIAN_FRONTEND=noninteractive apt-get -y install "$@"
    (set -x; ./debootstrap.sh add "$release" "$img_name" "$@")
}

defrag()
{
    $img_sh btrfs fi def -rc .
}

wordlines() { printf '%s\n' "$@"; }

xorg_packages()
{
    wordlines xorg libxss1 xserver-xorg-input-all xserver-xorg-input-wacom
}

necessary_packages()
{
    wordlines systemd-sysv
}

useful_packages()
{
    wordlines vim-tiny git tmux ssh
}

network_packages()
{
    wordlines \
        network-manager avahi-daemon libnss-mdns \
        iproute2 iw iputils-ping \
        firmware-iwlwifi firmware-linux firmware-linux-nonfree \
        firmware-atheros firmware-linux-free firmware-b43legacy-installer \
        firmware-ti-connectivity firmware-libertas firmware-ipw2x00 \
        firmware-ralink firmware-b43-installer firmware-realtek firmware-iwlwifi \
        firmware-brcm80211 firmware-zd1211
}

filesystem_tool_packages()
{
    wordlines btrfs-progs cryptsetup-bin hfsprogs mdadm nbd-client ntfs-3g
}

boot_tool_packages()
{
    wordlines grub-pc isolinux initramfs-tools
}

samizdat_dep_packages()
{
    wordlines \
        ca-certificates cryptsetup-bin dnsmasq eject \
        gnupg gnupg2 gnupg-agent grub2-common grub-common grub-pc \
        grub-pc-bin hfsprogs hfsutils nbd-server netscript-ipfilter \
        openssl pinentry-curses strongswan tor xorriso
}

find_prog()
{
  want_prog=$1
  prog=$(which "$want_prog") && return
  if [ "$SUDO_USER" -a "$(id -u)" = 0 ]; then
    prog=$(sh -c 'su - "$SUDO_USER" -c "which \"'"${want_prog}"'\""')
  else
    false
  fi
}

install_program_from_path1()
{
    find_prog "$1" || die "program not found: $1"
    $img_sh cp -L "$prog" ./usr/local/bin/"$1"
}

install_program_from_path()
{
    local f
    for f in "$@"; do
        install_program_from_path1 "$f" || die "could not install package '$f'"
    done
}

install_xmonad()
{
    install_program_from_path xmonad
    $chroot ln -s /usr/local/bin/xmonad /etc/alternatives/x-window-manager
    $chroot ln -s /etc/alternatives/x-window-manager /usr/bin/x-window-manager
}

kernel_packages()
{
    wordlines busybox cpio firmware-linux-free \
        initramfs-tools initramfs-tools-core irqbalance \
        klibc-utils kmod libklibc libnuma1 linux-base \
        linux-image-4.9.0-6-amd64 linux-image-amd64
}

install_apt_cache()
{
    $img_sh rsync -RaP /var/lib/apt/lists --exclude partial ./
}

install_kiki()
{
    install_program_from_path cokiki kiki
}

install_samizdat()
{
    srcdir=$(pwd) || return
    export srcdir
    $img_sh sh -c 'instdir=$(pwd) && cd "$srcdir" && make instdir="${instdir}" install install-configuration'
}

make_bootable()
{
    ln -sf "$PWD"/"${img_file}" /srv/nbd.btrfs
    btrfstune -S1 /srv/nbd.btrfs
}

print_config_dat()
{
    # perl -n -00 -e '/^Flags:.*seen/m && print;' /var/cache/debconf/config.dat > config.seen.dat
    cat <<'EOF'

Name: debconf/frontend
Template: debconf/frontend
Value: Noninteractive
Owners: debconf
Flags: seen

Name: debconf/priority
Template: debconf/priority
Value: critical
Owners: debconf
Flags: seen

Name: locales/locales_to_be_generated
Template: locales/locales_to_be_generated
Value: en_US.UTF-8 UTF-8
Owners: locales
Flags: seen

Name: locales/default_environment_locale
Template: locales/default_environment_locale
Value: en_US.UTF-8
Owners: locales
Flags: seen
Variables:
 locales = en_US.UTF-8

Name: tzdata/Areas
Template: tzdata/Areas
Value: US
Owners: tzdata
Flags: seen

Name: tzdata/Zones/Etc
Template: tzdata/Zones/Etc
Value: UTC
Owners: tzdata
Flags: seen

Name: tzdata/Zones/US
Template: tzdata/Zones/US
Value: Michigan
Owners: tzdata
Flags: seen

Name: firmware-ipw2x00/license/accepted
Template: firmware-ipw2x00/license/accepted
Owners: firmware-ipw2x00

Name: firmware-ipw2x00/license/error
Template: firmware-ipw2x00/license/error
Owners: firmware-ipw2x00

Name: b43-fwcutter/install-unconditional
Template: b43-fwcutter/install-unconditional
Value: true
Owners: b43-fwcutter

EOF
}

install_config_dat()
{
    print_config_dat | $img_sh sh -c 'cat >> ./var/cache/debconf/config.dat'
}

all_packages()
{
    (kernel_packages
     necessary_packages
     network_packages
     useful_packages
     filesystem_tool_packages
     boot_tool_packages
     samizdat_dep_packages
     xorg_packages) | sort -u
}

choose_hostname()
{
    true
}

main()
{
    ./debootstrap.sh init     $release
    ./debootstrap.sh new      $release $img_name
    ./debootstrap.sh with_img $release $img_name truncate -s 5G
    # ./debootstrap.sh with_img $release $img_name btrfstune -S0 -f || true
    ./debootstrap.sh sh       $release $img_name btrfs filesystem resize max .

    install_config_dat
    install_packages $(necessary_packages)
    install_packages $(kernel_packages)
    install_packages $(network_packages)
    install_packages $(useful_packages)
    install_packages $(filesystem_tool_packages)
    install_packages $(boot_tool_packages)
    install_packages $(samizdat_dep_packages)
    install_packages $(xorg_packages)
    install_packages firefox-esr linphone alsa-utils
    install_xmonad

    # (Note: libglib2.0-bin is needed for mypaint to work correctly)
    install_packages mypaint libglib2.0-bin emacs25 strongswan-pki strongswan-swanctl strongswan-nm
    install_packages build-essential vim less xbindkeys w3m sudo dmenu psmisc rsync
    install_apt_cache

    install_samizdat
    install_kiki
    install_program_from_path google
    install_program_from_path stack
    install_program_from_path dhtd dht

    add_user_account u
    add_git_clone ../src/dotfiles   home/u/src/dotfiles
    add_git_clone ./                home/u/src/samizdat
    add_git_clone ../src/bittorrent home/u/src/presence

    make_bootable
    echo done. >&2
}

add_user_account()
{
    local uname="$1"
    $chroot useradd "$uname" -G sudo -m -p '' -s /bin/bash
}

add_git_clone()
{
    local src dst="$2"
    src=$(realpath -e "$1") || die "add_git_clone: path does not exist: $1"
    $img_sh git clone "$src" ./"$dst"

    # todo: set up to properly push and pull via VPN

    # From "man git clone":
    #
    # This default configuration is achieved by creating references to the
    # remote branch heads under refs/remotes/origin and by initializing
    # remote.origin.url and remote.origin.fetch configuration variables.
}

if [ "${0##*/}" = build-rootfs.sh ]; then
    main
fi


exit
: <<'EOF'
# manual installs

# essential tools
vim-tiny
git
tmux
ssh

# filesystem access
btrfs-tools
cryptsetup
hfsprogs
mdadm
nbd-client
ntfs-3g

# bootloaders
grub-pc
isolinux
initramfs-tools

# network
network-manager
avahi-daemon
libnss-mdns

# network tools
iproute2
iw
iputils-ping

# wifi
firmware-iwlwifi
firmware-linux
firmware-linux-nonfree

# apt-cache pkgnames firmware|while read line; do apt-cache show $line|grep -qi wireless && echo $line; done
firmware-atheros
firmware-linux-free
firmware-b43legacy-installer
firmware-ti-connectivity
firmware-libertas
firmware-ipw2x00
firmware-ralink
firmware-b43-installer
firmware-realtek
firmware-iwlwifi
firmware-brcm80211
firmware-zd1211

# graphics
xorg
libxss1 # for xmonad, to be installed via binary

# samizdat deps

btrfs-progs
ca-certificates
cryptsetup-bin
dnsmasq
eject
gnupg
gnupg2
gnupg-agent
grub2-common
grub-common
grub-pc
grub-pc-bin
hfsprogs
hfsutils
nbd-server
netscript-ipfilter
openssl
pinentry-curses
strongswan
tor
xorriso


EOF