-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup
executable file
·1309 lines (1060 loc) · 37.7 KB
/
setup
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.18.0
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.6
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 Overpass Noto "
echo "export NERDFONTS=${NERDFONTS}"
# https://zoom.us/download?os=linux
export ZOOM_VERSION=6.2.10.4983
echo "export ZOOM_VERSION=${ZOOM_VERSION}"
# https://mlv.app/
export MLVAPP_VERSION=1.14
echo "export MLVAPP_VERSION=${MLVAPP_VERSION}"
# https://beeref.org/
export BEEREF_VERSION=0.3.3
echo "export BEEREF_VERSION=${BEEREF_VERSION}"
# https://www.freac.org/downloads-mainmenu-33
export FREAC_VERSION=1.1.7
echo "export FREAC_VERSION=${FREAC_VERSION}"
# https://github.com/IsmaelMartinez/teams-for-linux/releases/latest
export TEAMS_VERSION=1.11.5
echo "export TEAMS_VERSION=${TEAMS_VERSION}"
export CAPRINE_VERSION=2.60.1
echo "export CAPRINE_VERSION=${CAPRINE_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 OPERATION=$1
echo "export OPERATION=${OPERATION}"
export TARGET_USERNAME=$2
echo "export TARGET_USERNAME=${TARGET_USERNAME}"
export TARGET_PASSWD=$3
echo "export TARGET_PASSWD=${TARGET_PASSWD}"
export AUTHSSHFILE=$4
echo "export AUTHSSHFILE=${AUTHSSHFILE}"
export INPUT_IMG=$5
echo "export INPUT_IMG=${INPUT_IMG}"
export OUTPUT_IMAGE=$6
echo "export OUTPUT_IMAGE=${OUTPUT_IMAGE}"
export DISK_SIZE=$7
echo "export DISK_SIZE=${DISK_SIZE}"
}
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() {
echo "setup users"
cat << EOF | chroot ${ROOTFS}
/usr/sbin/useradd -m -s /bin/bash $TARGET_USERNAME
mkdir -p /home/${TARGET_USERNAME}/.ssh
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
}
setpasswd() {
export TARGET_ENCRYPTED_PASSWD=$(openssl passwd -6 -salt xyz $TARGET_PASSWD)
echo "setup users"
cat << EOF | chroot ${ROOTFS}
echo '${TARGET_USERNAME}:${TARGET_ENCRYPTED_PASSWD}' | /usr/sbin/chpasswd -e
echo 'root:${TARGET_ENCRYPTED_PASSWD}' | /usr/sbin/chpasswd -e
EOF
}
authkeys() {
mkdir -p ${ROOTFS}/home/$TARGET_USERNAME/.ssh/
echo "Copy authorized_keys $AUTHSSHFILE"
cp $AUTHSSHFILE ${ROOTFS}/home/$TARGET_USERNAME/.ssh/authorized_keys
cat << EOF | chroot ${ROOTFS}
chown $TARGET_USERNAME:$TARGET_USERNAME -R /home/$TARGET_USERNAME/.ssh
EOF
echo "Copied authorized_keys"
}
rmnouveau() {
# deactivate nouveau drivers
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"
}
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() {
# 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"
}
bashaliases() {
lineinfile ${ROOTFS}/etc/bash.bashrc ".*alias.*ll.*=.*" 'alias ll="ls -larth"'
lineinfile ${ROOTFS}/etc/bash.bashrc ".*alias.*ap=.*" 'alias ap=ansible-playbook'
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}"
lineinfile ${ROOTFS}/etc/bash.bashrc ".*export.*FREAC_VERSION*=.*" "export FREAC_VERSION=${FREAC_VERSION}"
lineinfile ${ROOTFS}/etc/bash.bashrc ".*export.*TEAMS_VERSION*=.*" "export TEAMS_VERSION=${TEAMS_VERSION}"
lineinfile ${ROOTFS}/etc/bash.bashrc ".*export.*CAPRINE_VERSION*=.*" "export CAPRINE_VERSION=${CAPRINE_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
echo "sudo setup finished"
}
allowsshpwd() {
cat << EOF | chroot ${ROOTFS}
sed -i 's/PasswordAuthentication no/PasswordAuthentication yes/g' /etc/ssh/sshd_config
EOF
}
ikeyboard() {
# 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"
mkdir -p ${ROOTFS}/etc/X11/xorg.conf.d/
cat <<EOF | tee ${ROOTFS}/etc/X11/xorg.conf.d/30-touchpad.conf
Section "InputClass"
Identifier "touchpad catchall"
Driver "libinput"
Option "Tapping" "on"
EndSection
EOF
}
idocker () {
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"
}
ikube() {
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}
mkdir -p /etc/containerd
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
}
idlkubeimg() {
echo "download kube images"
cat << EOF | chroot ${ROOTFS}
kubeadm config images pull
EOF
}
invidia() {
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
# avoid screen tearing
cat << 'EOF' >> ${ROOTFS}/etc/X11/xorg.conf.d/20-intel.conf
Section "Device"
Identifier "Intel Graphics"
Driver "modesetting"
EndSection
EOF
mkdir -p ${ROOTFS}/home/$TARGET_USERNAME/.config/picom/
cat << 'EOF' >> ${ROOTFS}/home/$TARGET_USERNAME/.config/picom/picom.conf
backend = "glx";
vsync = true;
use-damage = false
EOF
chown -R $TARGET_USERNAME:$TARGET_USERNAME ${ROOTFS}/home/$TARGET_USERNAME/.config
echo 'GRUB_CMDLINE_LINUX="$GRUB_CMDLINE_LINUX nvidia-drm.modeset=1"' > ${ROOTFS}/etc/default/grub.d/nvidia-modeset.cfg
cat << EOF | chroot ${ROOTFS}
update-grub
EOF
cat << EOF | chroot ${ROOTFS}
systemctl enable nvidia-suspend.service
systemctl enable nvidia-hibernate.service
systemctl enable nvidia-resume.service
EOF
echo 'options nvidia NVreg_PreserveVideoMemoryAllocations=1' > ${ROOTFS}/etc/modprobe.d/nvidia-power-management.conf
}
igui() {
echo "install gui"
# if pulse replace by this apt install -y pulseaudio
cat << EOF | chroot ${ROOTFS}
apt install -y make gcc libx11-dev libxft-dev libfreetype-dev libxinerama-dev xorg numlockx
# apt install -y pipewire-audio wireplumber pipewire-pulse pipewire-alsa libspa-0.2-bluetooth pulseaudio-utils qpwgraph pavucontrol
apt install -y pulseaudio libspa-0.2-bluetooth pulseaudio-utils pavucontrol
apt remove -y xserver-xorg-video-intel
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 picom brightnessctl cups xsane libsane sane-utils filezilla
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=/zez.duckdns.org/
address=/zez.duckdns.org/127.0.0.1
EOF
# dunst notification
mkdir -p ${ROOTFS}/home/$TARGET_USERNAME/.config/dunst
cat << 'EOF' | tee ${ROOTFS}/home/$TARGET_USERNAME/.config/dunst/dunstrc
[global]
monitor = 2
# follow = keyboard
font = Noto Sans 11
frame_width = 2
frame_color = "#4e9a06"
offset = 20x65
[urgency_low]
background = "#4e9a06"
foreground = "#eeeeec"
[urgency_normal]
background = "#2e3436"
foreground = "#eeeeec"
[urgency_critical]
background = "#a40000"
foreground = "#eeeeec"
EOF
cat << EOF | chroot ${ROOTFS}
chown -R $TARGET_USERNAME:$TARGET_USERNAME /home/$TARGET_USERNAME/.config/dunst
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
# asoundrc
cat << 'EOF' | tee ${ROOTFS}/home/$TARGET_USERNAME/.asoundrc
pcm.pulse {
type pulse
}
ctl.pulse {
type pulse
}
EOF
# create alsa loopback
lineinfile ${ROOTFS}/etc/modules ".*snd-aloop.*" "snd-aloop"
lineinfile ${ROOTFS}/etc/modules ".*snd-dummy.*" "snd-dummy"
cat << 'EOF' | tee ${ROOTFS}/etc/modprobe.d/alsa-loopback.conf
options snd-aloop index=10 id=loop
options snd-dummy index=11 id=dummy
EOF
# avoid crackling with pulse
lineinfile ${ROOTFS}/etc/pulse/default.pa ".*load-module module-suspend-on-idle.*" "load-module module-suspend-on-idle"
lineinfile ${ROOTFS}/etc/pulse/system.pa ".*load-module module-suspend-on-idle.*" "load-module module-suspend-on-idle"
wget -O ${ROOTFS}/etc/pulse/default.pa.d/pulsepod.pa https://raw.githubusercontent.com/alainpham/debian-os-image/master/scripts/pulseaudio/pulsepod.pa
lineinfile ${ROOTFS}/etc/pulse/daemon.conf ".*default-sample-rate.*" "default-sample-rate = 48000"
lineinfile ${ROOTFS}/etc/pulse/daemon.conf ".*default-sample-format.*" "default-sample-format = s16le"
# lineinfile ${ROOTFS}/etc/pulse/daemon.conf ".*default-fragment-size-msec.*" "default-fragment-size-msec = 40"
# lineinfile ${ROOTFS}/etc/pulse/daemon.conf ".*default-fragments.*" "default-fragments = 4"
lineinfile ${ROOTFS}/etc/pulse/daemon.conf ".*resample-method.*" "resample-method = soxr-hq"
# install scripts
gitroot=https://raw.githubusercontent.com/alainpham/debian-os-image/refs/heads/master/scripts/pulseaudio/
files="snd asnd asnddef csndfoczv csndzv csndh6 csndint clrmix clrmixoff"
for file in $files ; do
curl -Lo ${ROOTFS}/usr/local/bin/$file $gitroot/$file
chmod 755 ${ROOTFS}/usr/local/bin/$file
done
# wireplumber and pipewire
curl -Lo ${ROOTFS}/etc/udev/rules.d/89-pulseaudio-udev.rules https://raw.githubusercontent.com/alainpham/debian-os-image/refs/heads/master/scripts/pulseaudio/89-pulseaudio-udev.rules
cat << EOF | chroot ${ROOTFS}
cp -R /usr/share/pipewire /home/${TARGET_USERNAME}/.config/
cp -R /usr/share/wireplumber /home/${TARGET_USERNAME}/.config/
mkdir -p /home/${TARGET_USERNAME}/.config/pipewire/pipewire.conf.d/
curl -Lo /home/$TARGET_USERNAME/.config/pipewire/pipewire.conf.d/podcast.conf https://raw.githubusercontent.com/alainpham/debian-os-image/refs/heads/master/scripts/pulseaudio/podcast.conf
curl -Lo /home/$TARGET_USERNAME/.config/pipewire/pipewire-pulse.conf https://raw.githubusercontent.com/alainpham/debian-os-image/refs/heads/master/scripts/pulseaudio/pipewire-pulse.conf
chown -R $TARGET_USERNAME:$TARGET_USERNAME /home/$TARGET_USERNAME/.config/pipewire
chown -R $TARGET_USERNAME:$TARGET_USERNAME /home/$TARGET_USERNAME/.config/wireplumber
EOF
# 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
echo 0 | tee ~/.rebootdwm
export rebootdwm=$(cat ~/.rebootdwm)
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}
picom -b --config ~/.config/picom/picom.conf
# Log stderror to a file
dwm 2> ~/.dwm.log
# No error logging
#dwm >/dev/null 2>&1
rebootdwm=$(cat ~/.rebootdwm)
if [[ "$rebootdwm" = '0' ]]; then
break
fi
done
EOF
cat << EOF | chroot ${ROOTFS}
chown $TARGET_USERNAME:$TARGET_USERNAME /home/$TARGET_USERNAME/.xsession
EOF
# picom initial config
if [ ! -f ${ROOTFS}/home/$TARGET_USERNAME/.config/picom/picom.conf ] ; then
mkdir -p ${ROOTFS}/home/$TARGET_USERNAME/.config/picom/
cat << 'EOF' >> ${ROOTFS}/home/$TARGET_USERNAME/.config/picom/picom.conf
# picom config
EOF
fi
# 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
}
iworkstation() {
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/appimages/viber.AppImage https://download.cdn.viber.com/desktop/Linux/viber.AppImage
cat << EOF | chroot ${ROOTFS}
chmod 755 /opt/appimages/viber.AppImage
ln -sf /opt/appimages/viber.AppImage /usr/local/bin/viber