-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy pathMakefile
164 lines (133 loc) · 4.66 KB
/
Makefile
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
# My preferred way to quickly test distri in a somewhat real environment is to
# use qemu (with KVM acceleration).
#
# To build an image in DISKIMG (default /tmp/root.img) which is ready to be used
# via qemu-serial¹, use e.g.:
# % make image serial=1
# % make qemu-serial
#
# If you want a graphical output instead, use e.g.:
# % make image
# % make qemu-graphic
#
# To test an encrypted root file system, substitute the image target with the
# cryptimage target.
#
# ① Unfortunately, the linux console can only print to one device.
DISKIMG=/tmp/distri-disk.img
GCEDISKIMG=/tmp/distri-gcs.tar.gz
DOCSDIR=/tmp/distri-docs
QEMU=qemu-system-x86_64 \
-device e1000,netdev=net0 \
-netdev user,id=net0,hostfwd=tcp::5555-:22 \
-device virtio-rng-pci \
-smp 8 \
-machine accel=kvm \
-m 4096 \
-drive if=none,id=hd,file=${DISKIMG},format=raw \
-device virtio-scsi-pci,id=scsi \
-device scsi-hd,drive=hd
# To use gdb to debug the Linux kernel, use e.g.:
#
# make qemu-serial \
# kgdb=1 \
# kernel=/home/michael/fuse-debug/linux/arch/x86/boot/bzImage \
# cmdline="panic_on_oops=1"
#
# gdb vmlinux
# (gdb) target remote localhost:1234
# (gdb) continue
ifdef kgdb
cmdline+= nokaslr
cmdline+= kgdbwait
cmdline+= kgdboc=ttyS0,115200
QEMU+= -serial tcp::1234,server,nowait
endif
ifdef kernel
QEMU+= -kernel "${kernel}"
QEMU+= -append "root=/dev/sda4 ro ${cmdline} $(shell tr -d '\n' < ${DISKIMG}.cmdline)"
endif
PACKFLAGS=
# for when you want to see non-kernel console output (e.g. systemd), useful with qemu
ifdef serial
PACKFLAGS+= -serialonly
endif
ifdef authorized_keys
PACKFLAGS+= -authorized_keys=${authorized_keys}
endif
ifdef branch
PACKFLAGS+= -branch=${branch}
endif
ifdef extra_kernel_params
PACKFLAGS+= -extra_kernel_params="${extra_kernel_params}"
endif
ifdef override_repo
PACKFLAGS+= -override_repo="${override_repo}"
endif
ifdef lvm
PACKFLAGS+= -lvm
endif
IMAGE=distri pack \
-diskimg=${DISKIMG} \
-base=base-x11 ${PACKFLAGS}
GCEIMAGE=distri pack \
-gcsdiskimg=${GCEDISKIMG} \
-base=base-cloud ${PACKFLAGS}
DOCKERTAR=distri pack -docker ${PACKFLAGS}
.PHONY: install
all: install
install:
# TODO: inherit CAP_SETFCAP
CGO_ENABLED=0 go install ./cmd/... && sudo setcap 'CAP_SYS_ADMIN,CAP_DAC_OVERRIDE=ep CAP_SETFCAP=eip' $(shell go env GOPATH)/bin/distri
# Enable using systemctl --user enable --now distri-autobuilder.service
mkdir -p ~/.config/systemd/user && sed "s,@AUTOBUILDER@,$(shell which autobuilder),g" systemd/distri-autobuilder.service.in > ~/.config/systemd/user/distri-autobuilder.service
# This is a no-op if the unit is not running
systemctl --user daemon-reload || true
systemctl --user try-restart distri-autobuilder.service || true
test: install
DISTRIROOT=$$PWD go test -failfast -v ./cmd/... ./integration/... ./internal/...
image:
DISTRIROOT=$$PWD ${IMAGE}
cryptimage:
DISTRIROOT=$$PWD ${IMAGE} -encrypt
gceimage:
DISTRIROOT=$$PWD ${GCEIMAGE}
dockertar:
@DISTRIROOT=$$PWD ${DOCKERTAR}
qemu-serial:
${QEMU} -nographic
qemu-graphic:
${QEMU}
.PHONY: docs screen usb release deploy-repobrowser
docs: asciidocs/building.asciidoc asciidocs/package-format.asciidoc asciidocs/index.asciidoc asciidocs/rosetta-stone.asciidoc
mkdir -p ${DOCSDIR}
asciidoctor --destination-dir ${DOCSDIR} $^
# Example screen session for working with distri:
screen:
# Start screen in detached mode
screen -S distri -d -m
# Window 1: make command to pack a new distri disk image
screen -S distri -X title "image"
screen -S distri -X stuff "make image serial=1 authorized_keys=~/.ssh/authorized_keys"
# Window 2: make command to start the disk image in a qemu session
screen -S distri -X screen
screen -S distri -X title "qemu"
screen -S distri -X stuff "make qemu-serial"
# Window 3: SSH into the distri instance (better than serial)
screen -S distri -X screen
screen -S distri -X title "ssh"
screen -S distri -X stuff "ssh -F systemd/ssh_config distri0"
# Setup done, now resume screen
screen -r distri
usb:
[ -n "${USB_DISK_ID}" ] || (echo "Usage example: make usb USB_DISK_ID=usb-SanDisk_Extreme_Pro_12345878D17B-0:0" >&2; false)
sudo dd if=${DISKIMG} of=/dev/disk/by-id/${USB_DISK_ID} bs=1M status=progress oflag=direct
release:
DISTRIROOT=$$PWD go run release/release.go
umount:
for f in $$(mount | grep distri | cut -d' ' -f 3); do fusermount -u "$$f"; done
deploy-repobrowser: install
rsync $(shell go env GOPATH)/bin/distri-repobrowser $(shell go env GOPATH)/bin/distri-checkupstream chuchi:/srv/browse.distr1.org/
rsync -a cmd/distri-repobrowser/assets chuchi:/srv/browse.distr1.org/
rsync systemd/distri-repobrowser.service systemd/distri-checkupstream.{service,timer} chuchi:/etc/systemd/system/
ssh chuchi 'systemctl daemon-reload && systemctl restart distri-repobrowser'