-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
39 lines (31 loc) · 1.1 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
.PHONY: build uidcheck install uninstall reinstall
NAME?=eid
_UID=$(shell id -u)
_USER=$(USER)
_GID=$(shell id -g)
_GROUP=$(shell id -gn)
_HOME=$(HOME)
_OUTPUT_DIR=mkosi.output
_IMAGE_SRC=$(_OUTPUT_DIR)/$(NAME).tar
_NSPAWN_SRC=$(_OUTPUT_DIR)/$(NAME).nspawn
_NSPAWN_DIR=/etc/systemd/nspawn
_NSPAWN_DST=$(_NSPAWN_DIR)/$(NAME).nspawn
build:
mkdir -p $(_OUTPUT_DIR)
_UID="$(_UID)" _USER="$(_USER)" _GID="$(_GID)" _GROUP="$(_GROUP)" _HOME="$(_HOME)" mkosi --image-id $(NAME) -f
./mkosi.nspawn.make > $(_NSPAWN_SRC)
uidcheck:
@if [ "$(_UID)" != 0 ]; then echo 'use sudo'; exit 1; fi
install: uidcheck
mkdir -p $(_NSPAWN_DIR)
importctl -m import-tar $(_IMAGE_SRC) $(NAME)
if [ -f $(_NSPAWN_SRC) ]; then cp $(_NSPAWN_SRC) $(_NSPAWN_DST); fi
systemctl daemon-reload
machinectl start $(NAME)
uninstall: uidcheck
if machinectl status $(NAME) > /dev/null 2>&1; then machinectl terminate $(NAME); sleep 3; fi
if machinectl image-status $(NAME) > /dev/null 2>&1; then machinectl remove $(NAME); fi
rm -f $(_NSPAWN_DST)
rmdir --ignore-fail-on-non-empty $(_NSPAWN_DIR)
systemctl daemon-reload
reinstall: uninstall install