-
Notifications
You must be signed in to change notification settings - Fork 0
/
mac
executable file
·1013 lines (814 loc) · 30.5 KB
/
mac
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
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/bin/sh
set -e
inputversions() {
# https://github.com/docker/buildx/releases
export DOCKER_BUILDX_VERSION=v0.17.1
echo "export DOCKER_BUILDX_VERSION=${DOCKER_BUILDX_VERSION}"
# https://kubernetes.io/releases/ https://cloud.google.com/kubernetes-engine/docs/release-notes
export MAJOR_KUBE_VERSION=v1.30
echo "export MAJOR_KUBE_VERSION=${MAJOR_KUBE_VERSION}"
# https://github.com/derailed/k9s/releases
export K9S_VERSION=v0.32.5
echo "export K9S_VERSION=${K9S_VERSION}"
# https://maven.apache.org/download.cgi
export MVN_VERSION=3.9.9
echo "export MVN_VERSION=${MVN_VERSION}"
export NERDFONTS="ComicShannsMono FiraMono JetBrainsMono"
echo "export NERDFONTS=${NERDFONTS}"
export ZOOM_VERSION=6.2.0.1855
echo "export ZOOM_VERSION=${ZOOM_VERSION}"
export MLVAPP_VERSION=1.14
echo "export MLVAPP_VERSION=${MLVAPP_VERSION}"
export BEEREF_VERSION=0.3.3
echo "export BEEREF_VERSION=${BEEREF_VERSION}"
export FREAC_VERSION=1.1.7
echo "export FREAC_VERSION=${FREAC_VERSION}"
}
inputkeyboard() {
export KEYBOARD_LAYOUT=fr
echo "export KEYBOARD_LAYOUT=${KEYBOARD_LAYOUT}"
export NEEDRESTART_MODE=a
echo "export NEEDRESTART_MODE=a"
}
inputtasks() {
#default root
export ROOTFS=/
echo "export ROOTFS=${ROOTFS}"
# Map input parameters
export INSIDE_MACHINE=$1
echo "export INSIDE_MACHINE=${INSIDE_MACHINE}"
export CREATE_USER=$2
echo "export CREATE_USER=${CREATE_USER}"
export TARGET_USERNAME=$3
echo "export TARGET_USERNAME=${TARGET_USERNAME}"
export TARGET_PASSWD=$4
echo "export TARGET_PASSWD=${TARGET_PASSWD}"
export AUTHSSHFILE=$5
echo "export AUTHSSHFILE=${AUTHSSHFILE}"
export INPUT_IMG=$6
echo "export INPUT_IMG=${INPUT_IMG}"
export OUTPUT_IMAGE=$7
echo "export OUTPUT_IMAGE=${OUTPUT_IMAGE}"
export DISK_SIZE=$8
echo "export DISK_SIZE=${DISK_SIZE}"
export DOCKER_HOST=$9
echo "export DOCKER_HOST=${DOCKER_HOST}"
export KUBE_HOST=${10}
echo "export KUBE_HOST=${KUBE_HOST}"
export GUI=${11}
echo "export GUI=${GUI}"
export BLACKLIST_NOUVEAU=${12}
echo "export BLACKLIST_NOUVEAU=${BLACKLIST_NOUVEAU}"
export NVIDIA_DRIVERS=${13}
echo "export NVIDIA_DRIVERS=${NVIDIA_DRIVERS}"
export WSTATION=${14}
echo "export WSTATION=${WSTATION}"
export VIRTL=${14}
echo "export VIRTL=${VIRTL}"
}
lineinfile() {
local file_path="$1" # First argument: file path
local regex="$2" # Second argument: regex to search for
local new_line="$3" # Third argument: new line to replace or add
local create_file="$4" # Fourth argument: create file if not found
if [ -z "$create_file" ]; then
create_file=0
fi
# Check if the file exists
if [ ! -f "$file_path" ]; then
if [ $create_file -eq 1 ]; then
echo "File not found creating file !"
touch "$file_path"
else
return 1
fi
fi
# Check if the line matching the regex exists in the file
if grep -qE "$regex" "$file_path"; then
# If found, replace the matching line
sed -i "s]$regex]$new_line]" "$file_path"
echo "Line matching '$regex' was replaced."
else
# If not found, append the new line at the end of the file
echo "$new_line" >> "$file_path"
echo "New line added : $new_line"
fi
}
mountraw() {
# Only execute when working with a raw image
if [ $INSIDE_MACHINE -eq 0 ]; then
# name devices
export DEVICE=/dev/loop0
export ROOTFS="/tmp/installing-rootfs"
# resize image
cp $INPUT_IMG $OUTPUT_IMAGE
qemu-img resize -f raw $OUTPUT_IMAGE $DISK_SIZE
# setup loopback
losetup -D
losetup -fP $OUTPUT_IMAGE
# fix partition
printf "fix\n" | parted ---pretend-input-tty $DEVICE print
growpart ${DEVICE} 1
resize2fs ${DEVICE}p1
# mount image for chroot
echo "Mount OS partition"
mkdir -p ${ROOTFS}
mount ${DEVICE}p1 ${ROOTFS}
mount ${DEVICE}p15 ${ROOTFS}/boot/efi
echo "Get ready for chroot"
mount --bind /dev ${ROOTFS}/dev
mount --bind /run ${ROOTFS}/run
mount -t devpts /dev/pts ${ROOTFS}/dev/pts
mount -t proc proc ${ROOTFS}/proc
mount -t sysfs sysfs ${ROOTFS}/sys
mount -t tmpfs tmpfs ${ROOTFS}/tmp
fi
}
createuser() {
if [ $CREATE_USER -eq 1 ]; then
export TARGET_ENCRYPTED_PASSWD=$(openssl passwd -6 -salt xyz $TARGET_PASSWD)
echo "setup users"
cat << EOF | chroot ${ROOTFS}
/usr/sbin/useradd -m -s /bin/bash $TARGET_USERNAME
echo '${TARGET_USERNAME}:${TARGET_ENCRYPTED_PASSWD}' | /usr/sbin/chpasswd -e
echo 'root:${TARGET_ENCRYPTED_PASSWD}' | /usr/sbin/chpasswd -e
EOF
fi
}
authkeys() {
if [ -f $AUTHSSHFILE ]; then
mkdir -p ${ROOTFS}/home/$TARGET_USERNAME/.ssh/
cp $AUTHSSHFILE ${ROOTFS}/home/$TARGET_USERNAME/.ssh/
cat << EOF | chroot ${ROOTFS}
chown $TARGET_USERNAME:$TARGET_USERNAME -R /home/$TARGET_USERNAME/.ssh
EOF
echo "Copied authorized_keys"
fi
}
rmnouveau() {
# deactivate nouveau drivers
if [ $BLACKLIST_NOUVEAU -eq 1 ]; then
sed -i '/GRUB_CMDLINE_LINUX_DEFAULT/ {/modprobe.blacklist=nouveau/! s/"$/ modprobe.blacklist=nouveau"/}' ${ROOTFS}/etc/default/grub
cat << EOF | chroot ${ROOTFS}
update-grub
EOF
echo "Deactivated nouveau drivers"
fi
}
fastboot() {
# accelerate grub startup
echo 'GRUB_TIMEOUT=0' | tee -a ${ROOTFS}/etc/default/grub.d/15_timeout.cfg
cat << EOF | chroot ${ROOTFS}
update-grub
EOF
echo "fastboot activated"
}
disableturbo() {
# disable turbo boost
cat <<'EOF' | tee ${ROOTFS}/usr/local/bin/turboboost.sh
#!/bin/bash
input=$1
if [ "$input" = "no" ]; then
state=1
else
state=0
fi
echo "no_turbo=$state"
if [ -f /sys/devices/system/cpu/intel_pstate/no_turbo ]; then
echo $state > /sys/devices/system/cpu/intel_pstate/no_turbo
fi
EOF
chmod 755 ${ROOTFS}/usr/local/bin/turboboost.sh
cat <<EOF | tee ${ROOTFS}/etc/systemd/system/disable-intel-turboboost.service
[Unit]
Description=Disable Intel Turbo Boost using pstate driver
[Service]
ExecStart=/bin/sh -c "/usr/local/bin/turboboost.sh no"
ExecStop=/bin/sh -c "/usr/local/bin/turboboost.sh yes"
RemainAfterExit=yes
[Install]
WantedBy=sysinit.target
EOF
cat << EOF | chroot ${ROOTFS}
systemctl enable disable-intel-turboboost.service
EOF
}
firstbootexpandfs() {
if [ $INSIDE_MACHINE -eq 0 ]; then
# first boot script
cat <<EOF | tee ${ROOTFS}/usr/local/bin/firstboot.sh
#!/bin/bash
if [ ! -f /var/log/firstboot.log ]; then
# Code to execute if log file does not exist
echo "First boot script has run">/var/log/firstboot.log
growpart /dev/sda 1
resize2fs /dev/sda1
fi
EOF
chmod 755 ${ROOTFS}/usr/local/bin/firstboot.sh
cat <<EOF | tee ${ROOTFS}/etc/systemd/system/firstboot.service
[Unit]
Description=firstboot
Requires=network.target
After=network.target
[Service]
Type=oneshot
User=root
ExecStart=/usr/local/bin/firstboot.sh
RemainAfterExit=yes
[Install]
WantedBy=multi-user.target
EOF
cat << EOF | chroot ${ROOTFS}
systemctl enable firstboot.service
EOF
echo "firstboot script activated"
fi
}
bashaliases() {
lineinfile ${ROOTFS}/etc/bash.bashrc ".*alias.*ll.*=.*" 'alias ll="ls -larth"'
lineinfile ${ROOTFS}/etc/bash.bashrc ".*export.*ROOTFS*=.*" 'export ROOTFS=\/'
lineinfile ${ROOTFS}/etc/bash.bashrc ".*export.*TARGET_USERNAME*=.*" "export TARGET_USERNAME=${TARGET_USERNAME}"
lineinfile ${ROOTFS}/etc/bash.bashrc ".*export.*DOCKER_BUILDX_VERSION*=.*" "export DOCKER_BUILDX_VERSION=${DOCKER_BUILDX_VERSION}"
lineinfile ${ROOTFS}/etc/bash.bashrc ".*export.*MAJOR_KUBE_VERSION*=.*" "export MAJOR_KUBE_VERSION=${MAJOR_KUBE_VERSION}"
lineinfile ${ROOTFS}/etc/bash.bashrc ".*export.*K9S_VERSION*=.*" "export K9S_VERSION=${K9S_VERSION}"
lineinfile ${ROOTFS}/etc/bash.bashrc ".*export.*MVN_VERSION*=.*" "export MVN_VERSION=${MVN_VERSION}"
lineinfile ${ROOTFS}/etc/bash.bashrc ".*export.*NERDFONTS*=.*" "export NERDFONTS=${NERDFONTS}"
lineinfile ${ROOTFS}/etc/bash.bashrc ".*export.*ZOOM_VERSION*=.*" "export ZOOM_VERSION=${ZOOM_VERSION}"
lineinfile ${ROOTFS}/etc/bash.bashrc ".*export.*MLVAPP_VERSION*=.*" "export MLVAPP_VERSION=${MLVAPP_VERSION}"
lineinfile ${ROOTFS}/etc/bash.bashrc ".*export.*BEEREF_VERSION*=.*" "export BEEREF_VERSION=${BEEREF_VERSION}"
lineinfile ${ROOTFS}/etc/bash.bashrc ".*export.*FREAC_VERSION*=.*" "export FREAC_VERSION=${FREAC_VERSION}"
echo "bash aliases setup finished"
}
smalllogs() {
lineinfile ${ROOTFS}/etc/systemd/journald.conf ".*SystemMaxUse=.*" "SystemMaxUse=50M"
echo "lower log volume activated"
}
aptsrc() {
echo "setup apt"
cat <<EOF > ${ROOTFS}/etc/apt/sources.list
deb http://deb.debian.org/debian bookworm main contrib non-free non-free-firmware
deb http://deb.debian.org/debian-security/ bookworm-security main contrib non-free non-free-firmware
deb http://deb.debian.org/debian bookworm-updates main contrib non-free non-free-firmware
EOF
echo "apt sources setup finished"
}
iessentials() {
# Essentials packages
echo "install essentials"
cat << EOF | chroot ${ROOTFS}
apt update && apt upgrade -y
apt install -y sudo git tmux vim curl wget rsync ncdu dnsutils bmon systemd-timesyncd htop bash-completion gpg whois haveged zip unzip virt-what wireguard iptables jq
DEBIAN_FRONTEND=noninteractive apt install -y cloud-guest-utils openssh-server console-setup iperf3
EOF
echo "essentials installed"
cat << EOF | chroot ${ROOTFS}
git config --global core.editor "vim"
EOF
}
isudo() {
cat << EOF | chroot ${ROOTFS}
echo '${TARGET_USERNAME} ALL=(ALL) NOPASSWD:ALL' | sudo EDITOR='tee -a' visudo -f /etc/sudoers.d/nopwd
EOF
cat << EOF | chroot ${ROOTFS}
sed -i 's/PasswordAuthentication no/PasswordAuthentication yes/g' /etc/ssh/sshd_config
EOF
cat << EOF | chroot ${ROOTFS}
if [ ! -f /home/${TARGET_USERNAME}/.ssh/id_rsa ]; then
ssh-keygen -N "" -f /home/${TARGET_USERNAME}/.ssh/id_rsa
fi
chown -R ${TARGET_USERNAME}:${TARGET_USERNAME} /home/${TARGET_USERNAME}/.ssh
EOF
echo "sudo & ssh key setup finished"
}
ikeyboard() {
if [ $INSIDE_MACHINE -eq 0 ]; then
# setup keyboard
cat <<EOF | tee ${ROOTFS}/etc/default/keyboard
# KEYBOARD CONFIGURATION FILE
# Consult the keyboard(5) manual page.
XKBMODEL="pc105"
XKBLAYOUT="${KEYBOARD_LAYOUT}"
# XKBVARIANT=""
# XKBOPTIONS=""
# BACKSPACE="guess"
EOF
echo "keyboard setup finished"
cat <<EOF | tee ${ROOTFS}/etc/X11/xorg.conf.d/30-touchpad.conf
Section "InputClass"
Identifier "touchpad catchall"
Driver "libinput"
Option "Tapping" "on"
EndSection
EOF
fi
}
idocker () {
if [ $DOCKER_HOST -eq 1 ]; then
echo "install docker"
cat << EOF | chroot ${ROOTFS}
apt install -y docker.io python3-docker docker-compose skopeo
apt install -y ansible openjdk-17-jdk-headless npm golang-go
EOF
cat <<EOF | tee ${ROOTFS}/etc/docker/daemon.json
{
"log-opts": {
"max-size": "10m",
"max-file": "2"
}
}
EOF
echo "docker logs configured"
mkdir -p ${ROOTFS}/usr/lib/docker/cli-plugins
curl -SL https://github.com/docker/buildx/releases/download/${DOCKER_BUILDX_VERSION}/buildx-${DOCKER_BUILDX_VERSION}.linux-amd64 -o ${ROOTFS}/usr/lib/docker/cli-plugins/docker-buildx
chmod 755 ${ROOTFS}/usr/lib/docker/cli-plugins/docker-buildx
cat << EOF | chroot ${ROOTFS}
adduser $TARGET_USERNAME docker
EOF
echo "docker build x installed"
export JAVA_HOME_TARGET=$(echo 'readlink -f /usr/bin/javac | sed "s:/bin/javac::"' | chroot ${ROOTFS})
lineinfile ${ROOTFS}/etc/bash.bashrc ".*export.*JAVA_HOME*=.*" "export JAVA_HOME=${JAVA_HOME_TARGET}"
echo "java home setup finished"
# cat << EOF | chroot ${ROOTFS}
# echo "export JAVA_HOME=${JAVA_HOME_TARGET}" | tee /etc/profile.d/java_home.sh
# EOF
# install maven
mkdir -p ${ROOTFS}/opt/appimages/
curl -L -o /tmp/maven.tar.gz https://dlcdn.apache.org/maven/maven-3/${MVN_VERSION}/binaries/apache-maven-${MVN_VERSION}-bin.tar.gz
tar xzvf /tmp/maven.tar.gz -C ${ROOTFS}/opt/appimages/
cat << EOF | chroot ${ROOTFS}
ln -sf /opt/appimages/apache-maven-${MVN_VERSION}/bin/mvn /usr/local/bin/mvn
EOF
rm /tmp/maven.tar.gz
echo "maven installed"
cat <<EOF | tee ${ROOTFS}/usr/local/bin/firstboot-dockernet.sh
#!/bin/bash
echo "Setting up dedicated network bridge.."
if [[ -z "\$(docker network ls | grep primenet)" ]] then
docker network create --driver=bridge --subnet=172.18.0.0/16 --gateway=172.18.0.1 primenet
echo "net created"
echo "✅ primenet docker network created !">/var/log/firstboot-dockernet.log
else
echo "net exists"
echo "✅ primenet already exisits ! ">/var/log/firstboot-dockernet.log
fi
EOF
cat <<EOF | tee ${ROOTFS}/usr/local/bin/firstboot-dockerbuildx.sh
#!/bin/bash
echo "Setting up builder"
if [[ -z "\$(docker buildx ls | grep multibuilder.*linux)" ]] then
docker buildx create --name multibuilder --platform linux/amd64,linux/arm/v7,linux/arm64/v8 --use
echo "✅ multibuilder docker buildx created !">~/firstboot-dockerbuildx.log
else
echo "build exists"
echo "✅ multibuilder already exisits ! ">~/firstboot-dockerbuildx.log
fi
EOF
chmod 755 ${ROOTFS}/usr/local/bin/firstboot-dockernet.sh
chmod 755 ${ROOTFS}/usr/local/bin/firstboot-dockerbuildx.sh
cat <<EOF | tee ${ROOTFS}/etc/systemd/system/firstboot-dockernet.service
[Unit]
Description=firstboot-dockernet
Requires=network.target docker.service
After=network.target docker.service
[Service]
Type=oneshot
User=root
ExecStart=/usr/local/bin/firstboot-dockernet.sh
RemainAfterExit=yes
[Install]
WantedBy=multi-user.target
EOF
cat <<EOF | tee ${ROOTFS}/etc/systemd/system/firstboot-dockerbuildx.service
[Unit]
Description=firstboot-dockerbuildx
Requires=network.target docker.service
After=network.target docker.service
[Service]
Type=oneshot
User=${TARGET_USERNAME}
ExecStart=/usr/local/bin/firstboot-dockerbuildx.sh
RemainAfterExit=yes
[Install]
WantedBy=multi-user.target
EOF
cat << EOF | chroot ${ROOTFS}
systemctl enable firstboot-dockernet.service
systemctl enable firstboot-dockerbuildx.service
EOF
echo "docker network and buildx on first boot service configured"
fi
}
ikube() {
if [ $KUBE_HOST -eq 1 ]; then
echo "install kube readiness"
cat <<EOF | tee ${ROOTFS}/etc/modules-load.d/containerd.conf
overlay
br_netfilter
EOF
cat <<EOF | tee ${ROOTFS}/etc/sysctl.d/99-kubernetes-k8s.conf
net.bridge.bridge-nf-call-iptables = 1
net.ipv4.ip_forward = 1
net.bridge.bridge-nf-call-ip6tables = 1
EOF
echo "kube readiness setup finished"
cat << EOF | chroot ${ROOTFS}
apt install -y containerd
EOF
echo "containerd setup"
cat << EOF | chroot ${ROOTFS}
containerd config default | tee /etc/containerd/config.toml >/dev/null 2>&1
sed -i 's/SystemdCgroup = false/SystemdCgroup = true/g' /etc/containerd/config.toml
EOF
echo "install kube bins"
cat << EOF | chroot ${ROOTFS}
curl -fsSL https://pkgs.k8s.io/core:/stable:/$MAJOR_KUBE_VERSION/deb/Release.key | gpg --batch --yes --dearmor -o /etc/apt/keyrings/kubernetes-apt-keyring.gpg
echo 'deb [signed-by=/etc/apt/keyrings/kubernetes-apt-keyring.gpg] https://pkgs.k8s.io/core:/stable:/$MAJOR_KUBE_VERSION/deb/ /' | tee /etc/apt/sources.list.d/kubernetes.list
apt update
apt install -y kubelet kubeadm kubectl
kubectl completion bash | tee /etc/bash_completion.d/kubectl > /dev/null
EOF
echo "install helm"
cat << EOF | chroot ${ROOTFS}
curl https://baltocdn.com/helm/signing.asc | gpg --dearmor | tee /usr/share/keyrings/helm.gpg > /dev/null
echo "deb [arch=amd64 signed-by=/usr/share/keyrings/helm.gpg] https://baltocdn.com/helm/stable/debian/ all main" | tee /etc/apt/sources.list.d/helm-stable-debian.list
apt update
apt install helm -y
helm completion bash | tee /etc/bash_completion.d/helm > /dev/null
EOF
cat << EOF | chroot ${ROOTFS}
curl -LO https://github.com/derailed/k9s/releases/download/${K9S_VERSION}/k9s_Linux_amd64.tar.gz
tar -xzvf k9s_Linux_amd64.tar.gz -C /usr/local/bin/ k9s
chown root:root /usr/local/bin/k9s
rm k9s_Linux_amd64.tar.gz
EOF
fi
}
idlkubeimg() {
if [ $KUBE_HOST -eq 1 ]; then
echo "download kube images"
cat << EOF | chroot ${ROOTFS}
kubeadm config images pull
EOF
fi
}
invidia() {
if [ $NVIDIA_DRIVERS -eq 1 ]; then
echo "install nvidia drivers"
cat << EOF | chroot ${ROOTFS}
apt install -y nvidia-detect
EOF
export NV_VERSION=$(echo "nvidia-detect | grep nvidia.*driver | xargs" | chroot ${ROOTFS})
cat << EOF | chroot ${ROOTFS}
apt install -y $NV_VERSION
EOF
fi
}
igui() {
if [ $GUI -eq 1 ]; then
echo "install gui"
cat << EOF | chroot ${ROOTFS}
apt install -y make gcc libx11-dev libxft-dev libfreetype-dev libxinerama-dev xorg pulseaudio pavucontrol numlockx
EOF
echo "install nerdfonts"
for font in ${NERDFONTS} ; do
echo "installing $font"
wget -O ${ROOTFS}/tmp/${font}.zip "https://github.com/ryanoasis/nerd-fonts/releases/latest/download/${font}.zip"
mkdir -p ${ROOTFS}/usr/share/fonts/nerd-fonts/
unzip -o /tmp/${font}.zip -d ${ROOTFS}/usr/share/fonts/nerd-fonts/
rm /tmp/${font}.zip
echo "installed $font"
done
echo "additional gui packages"
cat << EOF | chroot ${ROOTFS}
apt install -y ntfs-3g ifuse mpv haruna vlc cmatrix nmon mesa-utils neofetch feh network-manager dnsmasq acpitool lm-sensors fonts-noto libnotify-bin dunst ffmpeg python3-mutagen imagemagick mediainfo-gui arandr
EOF
cat << EOF | chroot ${ROOTFS}
systemctl disable dnsmasq
EOF
cat << 'EOF' | tee ${ROOTFS}/etc/network/interfaces
# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).
source /etc/network/interfaces.d/*
# The loopback network interface
auto lo
iface lo inet loopback
EOF
cat << 'EOF' | tee ${ROOTFS}/etc/NetworkManager/conf.d/00-use-dnsmasq.conf
[main]
dns=dnsmasq
EOF
cat << 'EOF' | tee ${ROOTFS}/etc/NetworkManager/dnsmasq.d/dev.conf
#/etc/NetworkManager/dnsmasq.d/dev.conf
local=/zrz.duckdns.org/
address=/zrz.duckdns.org/127.0.0.1
EOF
#YT-DLP latest
curl -L https://github.com/yt-dlp/yt-dlp/releases/latest/download/yt-dlp -o ${ROOTFS}/usr/local/bin/yt-dlp
cat << EOF | chroot ${ROOTFS}
chmod 755 /usr/local/bin/yt-dlp
EOF
# ffmpeg scripts
ffmpegscripts="vconv-archive-lossless-h264-vaapi.sh vconv-extract-audio.sh vconv-h264-vaapi-qp.sh vconv-h264-vaapi-vbr.sh vconv-hevc-vaapi-qp.sh vconv-make-mkv.sh vconv-make-mp4.sh vconv-mp3-hq.sh vconv-vp9-vaapi-qp.sh vconv-x264-crf.sh vconv-x264-lowres-lowvbr-2pass.sh vconv-x264-lowres-vbr-2pass.sh vconv-x264-vbr-2pass.sh"
for script in $ffmpegscripts ; do
curl -Lo ${ROOTFS}/usr/local/bin/$script https://raw.githubusercontent.com/alainpham/debian-os-image/master/scripts/ffmpeg/$script
cat << EOF | chroot ${ROOTFS}
chmod 755 /usr/local/bin/$script
EOF
done
# pulseaudio podcast setup
cat << 'EOF' | tee ${ROOTFS}/etc/pulse/default.pa.d/pulsepod.pa
# audio sink from desktop
load-module module-null-sink sink_name=from-desktop sink_properties=device.description="from-desktop"
set-default-sink from-desktop
# audio sink from caller
load-module module-null-sink sink_name=from-caller sink_properties=device.description="from-caller"
set-sink-volume from-desktop 62260
set-sink-volume from-caller 62260
# audio sink mix to caller
load-module module-null-sink sink_name=to-caller-sink sink_properties=device.description="to-caller-sink"
load-module module-remap-source source_name=to-caller master=to-caller-sink.monitor source_properties=device.description="to-caller"
set-default-source to-caller-src
# connect from-desktop to to-caller-sink
load-module module-loopback source=from-desktop.monitor sink=to-caller-sink latency_msec=1 source_dont_move=true sink_dont_move=true rate=48000 adjust_time=0
EOF
lineinfile ${ROOTFS}/etc/pulse/daemon.conf ".*default-sample-rate.*" "default-sample-rate = 48000"
# install chrome browser
mkdir -p ${ROOTFS}/opt/debs/
wget -O /opt/debs/google-chrome-stable_current_amd64.deb https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
cat << EOF | chroot ${ROOTFS}
apt install -y /opt/debs/google-chrome-stable_current_amd64.deb
EOF
#begin dwm
if [ ! -d ${ROOTFS}/home/$TARGET_USERNAME/wm ] ; then
echo "The does not exist, installing dwm"
cat << EOF | chroot ${ROOTFS}
mkdir -p /home/$TARGET_USERNAME/wm
cd /home/$TARGET_USERNAME/wm
git clone https://github.com/alainpham/dwm-flexipatch.git
git clone https://github.com/alainpham/st-flexipatch.git
git clone https://github.com/alainpham/dmenu-flexipatch.git
git clone https://github.com/alainpham/dwmblocks.git
cd /home/$TARGET_USERNAME/wm/dwm-flexipatch && make clean install
cd /home/$TARGET_USERNAME/wm/st-flexipatch && make clean install
cd /home/$TARGET_USERNAME/wm/dmenu-flexipatch && make clean install
cd /home/$TARGET_USERNAME/wm/dwmblocks && make clean install
chown -R $TARGET_USERNAME:$TARGET_USERNAME /home/$TARGET_USERNAME/wm
EOF
# end dwm
fi
# wallpaper
mkdir -p ${ROOTFS}/usr/share/backgrounds/
wget -O ${ROOTFS}/usr/share/backgrounds/01.jpg https://free-images.com/or/8606/canyon_antelope_canyon_usa_1.jpg
wget -O ${ROOTFS}/usr/share/backgrounds/02.jpg https://free-images.com/or/9cf1/city_overcast_buildings_skyline.jpg
wget -O ${ROOTFS}/usr/share/backgrounds/03.jpg https://free-images.com/lg/f1b3/sunset_on_seine.jpg
wget -O ${ROOTFS}/usr/share/backgrounds/04.jpg https://free-images.com/lg/e216/parrots_macaw_bird_parrot.jpg
wget -O ${ROOTFS}/usr/share/backgrounds/05.jpg https://free-images.com/lg/ac18/city_night_light_bokeh.jpg
wget -O ${ROOTFS}/usr/share/backgrounds/06.jpg https://free-images.com/lg/5cc4/lights_night_city_night.jpg
wget -O ${ROOTFS}/usr/share/backgrounds/07.jpg https://free-images.com/lg/64e0/heavens_peek.jpg
wget -O ${ROOTFS}/usr/share/backgrounds/08.jpg https://free-images.com/lg/5d7d/painting_watercolor_wax_stains.jpg
wget -O ${ROOTFS}/usr/share/backgrounds/09.jpg https://raw.githubusercontent.com/simple-sunrise/Light-and-Dark-Wallpapers-for-Gnome/main/Wallpapers/LakesideDeer/LakesideDeer-1.png
wget -O ${ROOTFS}/usr/share/backgrounds/10.jpg https://raw.githubusercontent.com/simple-sunrise/Light-and-Dark-Wallpapers-for-Gnome/main/Wallpapers/LakesideDeer/LakesideDeer-2.png
cat << EOF | tee ${ROOTFS}/home/$TARGET_USERNAME/.xsession
#!/bin/sh
setxkbmap ${KEYBOARD_LAYOUT}
EOF
cat << 'EOF' >> ${ROOTFS}/home/$TARGET_USERNAME/.xsession
numlockx
while true; do
piddwmblocks=$(pgrep dwmblocks)
if [ -z "$piddwmblocks" ]; then
dwmblocks &
else
kill -9 $piddwmblocks
dwmblocks &
fi
bgfile=$(ls /usr/share/backgrounds/ | shuf -n 1)
feh --bg-fill /usr/share/backgrounds/${bgfile}
# Log stderror to a file
dwm 2> ~/.dwm.log
# No error logging
#dwm >/dev/null 2>&1
done
EOF
cat << EOF | chroot ${ROOTFS}
chown $TARGET_USERNAME:$TARGET_USERNAME /home/$TARGET_USERNAME/.xsession
EOF
# if inside virtual machine
# video=Virtual-1:1600x900
export hypervisor=$(echo "virt-what" | chroot ${ROOTFS})
# Hyperv
if [ "$hypervisor" = "hyperv" ]; then
sed -i '/GRUB_CMDLINE_LINUX_DEFAULT/ {/video=Virtual-1:1600x900/! s/"$/ video=Virtual-1:1600x900"/}' ${ROOTFS}/etc/default/grub
cat << EOF | chroot ${ROOTFS}
update-grub
EOF
cat <<EOF | tee ${ROOTFS}/etc/X11/xorg.conf.d/30-hyperv.conf
Section "Device"
Identifier "HYPER_V Framebuffer"
Driver "fbdev"
EndSection
EOF
#end hyperv
fi
# end gui
fi
}
iworkstation() {
if [ $WSTATION -eq 1 ]; then
echo "additional workstation tools"
cat << EOF | chroot ${ROOTFS}
apt install -y handbrake gimp rawtherapee krita mypaint inkscape blender obs-studio mgba-qt v4l2loopback-utils kdenlive flameshot maim xclip xdotool thunar thunar-archive-plugin easytag
EOF
mkdir -p ${ROOTFS}/home/workdrive/recordings
cat << EOF | chroot ${ROOTFS}
chown -R $TARGET_USERNAME:$TARGET_USERNAME /home/workdrive
EOF
cat << 'EOF' | tee ${ROOTFS}/usr/local/bin/winshot.sh
maim -i $(xdotool getactivewindow) | xclip -selection clipboard -t image/png
EOF
cat << EOF | chroot ${ROOTFS}
chmod 755 /usr/local/bin/winshot.sh
EOF
# configure Thunar
mkdir -p ${ROOTFS}/home/$TARGET_USERNAME/.config/Thunar/
cat << 'EOF' | tee ${ROOTFS}/home/$TARGET_USERNAME/.config/Thunar/uca.xml
<?xml version="1.0" encoding="UTF-8"?>
<actions>
<action>
<icon>utilities-terminal</icon>
<name>Open Terminal Here</name>
<submenu></submenu>
<unique-id>1727457442655389-1</unique-id>
<command>st -d %f</command>
<description>Open Terminal here</description>
<range></range>
<patterns>*</patterns>
<startup-notify/>
<directories/>
</action>
<action>
<icon>utilities-terminal</icon>
<name>VSCode</name>
<submenu></submenu>
<unique-id>1727457442655389-1</unique-id>
<command>code %f</command>
<description>Open VSCode here</description>
<range></range>
<patterns>*</patterns>
<startup-notify/>
<directories/>
</action>
</actions>
EOF
cat << EOF | chroot ${ROOTFS}
chown -R $TARGET_USERNAME:$TARGET_USERNAME /home/$TARGET_USERNAME/.config
EOF
cat << EOF | chroot ${ROOTFS}
DEBIAN_FRONTEND=noninteractive apt install -y libdvd-pkg
EOF
echo "dpkg libdvd-pkg"
cat << EOF | chroot ${ROOTFS}
DEBIAN_FRONTEND=noninteractive dpkg-reconfigure libdvd-pkg
EOF
# cat << EOF | chroot ${ROOTFS}
# apt install -y snapd
# snap install pinta
# snap install rpi-imager
# EOF
#vscode
mkdir -p ${ROOTFS}/opt/debs/
wget -O ${ROOTFS}/opt/debs/vscode.deb "https://code.visualstudio.com/sha/download?build=stable&os=linux-deb-x64"
cat << EOF | chroot ${ROOTFS}
DEBIAN_FRONTEND=noninteractive apt install -y /opt/debs/vscode.deb
EOF
# install zoom
mkdir -p ${ROOTFS}/opt/debs/
wget -O ${ROOTFS}/opt/debs/zoom_amd64.deb https://zoom.us/client/${ZOOM_VERSION}/zoom_amd64.deb
cat << EOF | chroot ${ROOTFS}
apt install -y /opt/debs/zoom_amd64.deb
EOF
mkdir -p ${ROOTFS}/opt/debs/
wget -O ${ROOTFS}/opt/debs/slack.deb https://downloads.slack-edge.com/desktop-releases/linux/x64/4.39.95/slack-desktop-4.39.95-amd64.deb
cat << EOF | chroot ${ROOTFS}
apt install -y /opt/debs/slack.deb
EOF
# install onlyoffice
mkdir -p ${ROOTFS}/opt/debs/
wget -O /opt/debs/onlyoffice-desktopeditors_amd64.deb https://download.onlyoffice.com/install/desktop/editors/linux/onlyoffice-desktopeditors_amd64.deb
cat << EOF | chroot ${ROOTFS}
apt install -y /opt/debs/onlyoffice-desktopeditors_amd64.deb
EOF
# install dbeaver
mkdir -p ${ROOTFS}/opt/debs/
wget -O ${ROOTFS}/opt/debs/dbeaver.deb https://dbeaver.io/files/dbeaver-ce_latest_amd64.deb
cat << EOF | chroot ${ROOTFS}
apt install -y /opt/debs/dbeaver.deb
EOF
# APPimages
# MLVP APP
wget -O ${ROOTFS}/opt/appimages/mlvapp.AppImage https://github.com/ilia3101/MLV-App/releases/download/QTv${MLVAPP_VERSION}/MLV.App.v${MLVAPP_VERSION}.Linux.x86_64.AppImage
cat << EOF | chroot ${ROOTFS}
chmod 755 /opt/appimages/mlvapp.AppImage
ln -s /opt/appimages/mlvapp.AppImage /usr/local/bin/mlvapp
EOF
#viber
wget -O ${ROOTFS}/opt/debs/viber.AppImage https://download.cdn.viber.com/desktop/Linux/viber.AppImage
cat << EOF | chroot ${ROOTFS}
chmod 755 /opt/debs/viber.AppImage
ln -s /opt/debs/viber.AppImage /usr/local/bin/viber
EOF
# beeref
wget -O ${ROOTFS}/opt/debs/beeref.AppImage https://github.com/rbreu/beeref/releases/download/v${BEEREF_VERSION}/BeeRef-${BEEREF_VERSION}.appimage
cat << EOF | chroot ${ROOTFS}
chmod 755 /opt/debs/beeref.AppImage
ln -s /opt/debs/beeref.AppImage /usr/local/bin/beeref
EOF
#freac
wget -O ${ROOTFS}/opt/debs/freac.AppImage https://github.com/enzo1982/freac/releases/download/v${FREAC_VERSION}/freac-${FREAC_VERSION}-linux-x86_64.AppImage
cat << EOF | chroot ${ROOTFS}
chmod 755 /opt/debs/freac.AppImage
ln -s /opt/debs/freac.AppImage /usr/local/bin/freac
EOF
fi
}
ivirt(){
if [ $VIRTL -eq 1 ]; then
echo "virtualization tools"
cat << EOF | chroot ${ROOTFS}
apt install qemu-system qemu-utils virtinst libvirt-clients libvirt-daemon-system libguestfs-tools bridge-utils libosinfo-bin virt-manager genisoimage
adduser $TARGET_USERNAME libvirt
EOF
curl -Lo ${ROOTFS}/usr/local/bin/vmcr https://raw.githubusercontent.com/alainpham/debian-os-image/master/scripts/vms/vmcr
curl -Lo ${ROOTFS}/usr/local/bin/vmdl https://raw.githubusercontent.com/alainpham/debian-os-image/master/scripts/vms/vmdl
curl -Lo ${ROOTFS}/usr/local/bin/vmls https://raw.githubusercontent.com/alainpham/debian-os-image/master/scripts/vms/vmls
curl -Lo ${ROOTFS}/usr/local/bin/vmsh https://raw.githubusercontent.com/alainpham/debian-os-image/master/scripts/vms/vmsh
cat << EOF | chroot ${ROOTFS}
chmod 755 /usr/local/bin/vmcr /usr/local/bin/vmdl /usr/local/bin/vmls /usr/local/bin/vmsh
if [ ! -f /home/${TARGET_USERNAME}/.ssh/vm ]; then
ssh-keygen -f /home/${TARGET_USERNAME}/.ssh/vm -N ""
fi
chown -R ${TARGET_USERNAME}:${TARGET_USERNAME} /home/${TARGET_USERNAME}/.ssh/vm*
mkdir -p /home/workdrive/virt/images
mkdir -p /home/workdrive/virt/runtime
chown -R ${TARGET_USERNAME}:${TARGET_USERNAME} /home/workdrive
EOF
fi
}
cleanupapt() {
echo "cleaning up"
cat << EOF | chroot ${ROOTFS}
apt-get clean && rm -rf /var/lib/apt/lists/*
EOF
}
unmountraw() {
if [ $INSIDE_MACHINE -eq 0 ]; then
echo "Unmounting filesystems"
umount ${ROOTFS}/{dev/pts,boot/efi,dev,run,proc,sys,tmp,}
losetup -D
fi
}
init() {
# Set the default values
inputversions
inputkeyboard
inputtasks $@
}
if ! [ $# -eq 15 ]; then
echo "make sure to download debian cloud image : rm debian-12-nocloud-amd64.raw && wget https://cloud.debian.org/images/cloud/bookworm/latest/debian-12-nocloud-amd64.raw"
echo "Usage: sudo $0 <1_INSIDE_MACHINE> <2_CREATE_USER> <3_TARGET_USERNAME> <4_TARGET_PASSWD> <5_AUTHSSHFILE> <6_INPUT_IMG> <7_OUTPUT_IMAGE> <8_DISK_SIZE> <9_DOCKER_HOST> <10_KUBE_HOST> <11_GUI> <12_BLACKLIST_NOUVEAU> <13_NVIDIA_DRIVERS> <14_WSTATION> <15_VIRT>"
echo "baremetal wkstatvrt: sudo $0 1 0 apham ps authorized_keys debian-12-nocloud-amd64.raw d12-fgui.raw 5G 1 1 1 1 1 1 1"
echo "baremetal wkstation: sudo $0 1 0 apham ps authorized_keys debian-12-nocloud-amd64.raw d12-fgui.raw 5G 1 1 1 1 1 1 0"
echo "baremetal fullguivrt: sudo $0 1 0 apham ps authorized_keys debian-12-nocloud-amd64.raw d12-fgui.raw 5G 1 1 1 1 0 0 1"
echo "baremetal fullgui: sudo $0 1 0 apham ps authorized_keys debian-12-nocloud-amd64.raw d12-fgui.raw 5G 1 1 1 1 0 0 0"
echo "cloud fullgui: sudo $0 0 1 apham ps authorized_keys debian-12-nocloud-amd64.raw d12-fgui.raw 5G 1 1 1 1 0 0 0"
echo "cloud full: sudo $0 0 1 apham ps authorized_keys debian-12-nocloud-amd64.raw d12-full.raw 5G 1 1 0 1 0 0 0"
echo "cloud image min: sudo $0 0 1 apham ps authorized_keys debian-12-nocloud-amd64.raw d12-mini.raw 3G 0 0 0 1 0 0 0"
echo "cloud image kube: sudo $0 0 1 apham ps authorized_keys debian-12-nocloud-amd64.raw d12-kube.raw 4G 0 1 0 1 0 0 0"
return
fi
# Run all the script
init $@
mountraw
createuser
authkeys
rmnouveau
fastboot
disableturbo
firstbootexpandfs
bashaliases
smalllogs
aptsrc
iessentials