-
Notifications
You must be signed in to change notification settings - Fork 3
/
Makefile
188 lines (147 loc) · 6.11 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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
#=======================================================
# Makefile for soe-ubuntu
#
# Description: This makefile works on Linux and MacOS
#
# Dependencies:
# - MacOS: brew, brew packages: dvdrtools
#
#=======================================================
MY_FILES = my_files
RELEASE=22
ifeq ($(RELEASE),16)
BASE_VERSION = 16.04
VERSION = 16.04.5
BASE_URL = http://mirror.init7.net/ubuntu-releases/$(BASE_VERSION)
DST_IMAGE = soe-ubuntu-$(VERSION).iso
BASE_IMAGE = ubuntu-$(VERSION)-server-amd64.iso
endif
ifeq ($(RELEASE),18)
BASE_VERSION = 18.04
VERSION = 18.04.2
BASE_URL=http://cdimage.ubuntu.com/releases/$(BASE_VERSION)/release
DST_IMAGE = soe-ubuntu-$(VERSION).iso
BASE_IMAGE = ubuntu-$(VERSION)-server-amd64.iso
endif
ifeq ($(RELEASE),20)
BASE_VERSION = 20.04
VERSION = 20.04.4
BASE_URL=https://releases.ubuntu.com/$(VERSION)
DST_IMAGE = soe-ubuntu-$(VERSION).iso
BASE_IMAGE = ubuntu-$(VERSION)-live-server-amd64.iso
endif
#--- https://releases.ubuntu.com/22.04/ubuntu-22.04-beta-live-server-amd64.iso
ifeq ($(RELEASE),22)
BASE_VERSION = 22
VERSION = 22.04
BASE_URL=https://releases.ubuntu.com/$(VERSION)
DST_IMAGE = soe-ubuntu-$(VERSION).iso
BASE_IMAGE = ubuntu-$(VERSION)-beta-live-server-amd64.iso
endif
#DST_IMAGE = soe-ubuntu-$(VERSION).iso
#BASE_IMAGE = ubuntu-$(VERSION)-server-amd64.iso
WORK_DIR = work.$(RELEASE)
USER = ops
#PASSWORD = P@ssw0rd
SALT = saltsalt
TIMEZONE = Europe/Zurich
#PROXY_URL = 10.0.20.5
#PROXY_PORT = 3142
MNT_DIR = mnt
OS := $(shell uname)
CUR_USER := $(shell id -u)
CUR_GROUP := $(shell id -g)
#ASK_PASSWORD ?= $(shell stty -echo; read -p "$(USER) Password: " pwd; stty echo; echo $$pwd)
#PASSWORD := $(ASK_PASSWORD)
help:
@echo "Usage:"
@echo ""
@echo "make clean # will unmount the source image and remove mnt and remove the password_hash file"
@echo "make dist-clean # will make clean and remove the $(WORK_DIR) directory"
@echo ""
@echo "#--- some helpful stuff"
@echo "make download # will download the ubuntu iso"
@echo "make mnt # will download the ubuntu iso and mount it on ./mnt"
@echo ""
@echo "#--- Variables - as set right now"
@echo ""
@echo "RELEASE = $(RELEASE)"
@echo "BASE_VERSION = $(BASE_VERSION)"
@echo "VERSION = $(VERSION)"
@echo "ISO = $(BASE_URL)/$(BASE_IMAGE)"
@echo ""
@echo "#--- the magic"
@echo "make soe RELEASE=16 # will copy the files in my_files and create the image for Ubuntu 16"
@echo "make soe # will copy the files in my_files and create the image for Ubuntu 18"
@echo "make soe USER=$(USER) # will copy the files in my_files and create the image using $(USER) as credentials for the default user"
password_hash:
ifeq ($(OS),Darwin)
$(eval PASSWORD := $(shell stty -echo; read -p "$(USER) Password: " pwd; stty echo; echo $$pwd))
openssl passwd -1 -salt "$(SALT)" "$(PASSWORD)" > password_hash
else
mkpasswd -m sha-512 -S $(SALT) > password_hash
endif
all: soe
mount: $(BASE_IMAGE) $(MNT_DIR) $(MNT_DIR)/md5sum.txt
download: $(BASE_IMAGE)
umount:
sudo umount $(MNT_DIR)
work: $(WORK_DIR)/md5sum.txt
soe: password_hash $(MNT_DIR)/md5sum.txt $(WORK_DIR)
cp $(MY_FILES)/$(BASE_VERSION)/show-ip-address $(WORK_DIR)/show-ip-address
#--- only for proxy based installations
# cat $(MY_FILES)/proxy.template | sed -e "s/XXX_PROXY_URL_XXX/$(PROXY_URL)/g" -e "s/XXX_PROXY_PORT_XXX/$(PROXY_PORT)/g" | sudo tee -a $(WORK_DIR)/kmg-ks.preseed
[ -d $(WORK_DIR)/isolinux ] || mkdir $(WORK_DIR)/isolinux
cp $(MY_FILES)/$(BASE_VERSION)/isolinux/lang $(WORK_DIR)/isolinux
cat $(MY_FILES)/$(BASE_VERSION)/isolinux/txt.cfg | sed -e "s!XXX_PRESEED_CHECKSUM_XXX!`md5sum -r $(WORK_DIR)/kmg-ks.preseed | cut -d" " -f 1`!" | tee $(WORK_DIR)/isolinux/txt.cfg
cat $(MY_FILES)/$(BASE_VERSION)/grub.cfg | sed -e "s!XXX_PRESEED_CHECKSUM_XXX!`md5sum -r $(WORK_DIR)/kmg-ks.preseed | cut -d" " -f 1`!" | tee $(WORK_DIR)/boot/grub/grub.cfg
cat $(WORK_DIR)/isolinux/txt.cfg
cat $(WORK_DIR)/boot/grub/grub.cfg
ifeq ($(RELEASE),20)
cp $(MY_FILES)/$(BASE_VERSION)/user-data $(WORK_DIR)/
touch $(WORK_DIR)/meta-data
else
cat $(MY_FILES)/$(BASE_VERSION)/kmg-ks.preseed | sed -e "s/XXX_USER_XXX/$(USER)/g" -e "s,XXX_PASSWORD_XXX,`cat password_hash`,g" -e "s,XXX_PUBLIC_KEY_XXX,`cat public_key`,g" -e "s,XXX_TIMEZONE_XXX,$(TIMEZONE),g" | tee $(WORK_DIR)/kmg-ks.preseed
endif
ifeq ($(OS),Darwin)
sudo mkisofs -D -r -V "Attendless_Ubuntu" -J -l -b isolinux/isolinux.bin -no-emul-boot -boot-load-size 4 -boot-info-table -z -iso-level 3 -c isolinux/isolinux.cat -o ./$(DST_IMAGE) $(WORK_DIR)
sudo chown $(CUR_USER):$(CUR_GROUP) $(DST_IMAGE)
./isohybrid.pl $(DST_IMAGE)
else
sudo mkisofs -U -A "Custom1804" -V "Custom1804" -volset "Custom1804" -J -joliet-long -r -v -T -o ./$(DST_IMAGE) -b isolinux/isolinux.bin -c isolinux/isolinux.cat -no-emul-boot -boot-load-size 4 -boot-info-table -eltorito-alt-boot -e boot/grub/efi.img -no-emul-boot $(WORK_DIR)
sudo chown $(CUR_USER):$(CUR_GROUP) $(DST_IMAGE)
isohybrid --uefi $(DST_IMAGE)
endif
sudo umount $(MNT_DIR)
#=====================================================
# Atomic rules
#=====================================================
$(MNT_DIR): $(BASE_IMAGE)
[ -d $@ ] || mkdir $@
$(MNT_DIR)/md5sum.txt: $(MNT_DIR)
ifeq ($(OS),Darwin)
#--- this is a sequence where the semicolon and backslash is extremely important
set -e ;\
ISO_DEVICE=$$(hdiutil attach -nobrowse -nomount ./$(BASE_IMAGE) | head -1 | cut -d" " -f1) ;\
echo "iso $$ISO_DEVICE" ;\
mount -t cd9660 $$ISO_DEVICE $(MNT_DIR)
else
sudo mount -o loop $(BASE_IMAGE) $(MNT_DIR)
endif
$(WORK_DIR)/md5sum.txt: $(MNT_DIR)
[ -d $(WORK_DIR) ] || mkdir $(WORK_DIR) || true
(cd mnt; sudo tar cf - .) | (cd $(WORK_DIR); pwd ; tar xf - )
chmod -R u+w $(WORK_DIR)
$(WORK_DIR): $(WORK_DIR)/md5sum.txt
$(BASE_IMAGE):
wget "$(BASE_URL)/$(BASE_IMAGE)"
clean:
[ -d $(WORK_DIR) ] && sudo rm -rf $(WORK_DIR) || true
[ -d mnt ] && sudo umount mnt || true
[ -d mnt ] && rmdir mnt || true
[ -f password_hash ] && rm password_hash || true
dist-clean: clean
[ -d work.16 ] && sudo rm -rf work.16 || true
[ -d work.18 ] && sudo rm -rf work.18 || true
sudo rm soe-ubuntu-16.04.?.iso 2>/dev/null || true
sudo rm soe-ubuntu-18.04.?.iso 2>/dev/null || true