summaryrefslogtreecommitdiffstats
path: root/linhes/linhes-dev/LinHES9_iso/build_iso.sh
blob: 51aba98cbae427f7d6a0b80937e8c4411bf83c54 (plain)
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
#!/bin/bash

# Revision: 2022.06.15
# (GNU/General Public License version 3.0)
# by Cecil Watson for LinHES.
# based on work by eznix (https://sourceforge.net/projects/ezarch/)

# ----------------------------------------
# Define Variables
# ----------------------------------------

LCLST="en_US"
# Format is language_COUNTRY where language is lower case two letter code
# and country is upper case two letter code, separated with an underscore

KEYMP="us"
# Use lower case two letter country code

KEYMOD="pc105"
# pc105 and pc104 are modern standards, all others need to be researched

MYUSERNM="km"
# use all lowercase letters only

MYUSRPASSWD="mtv"
# Pick a password of your choice

RTPASSWD="roto"
# Pick a root password

MYHOSTNM="linhes"
# Pick a hostname for the machine

# ----------------------------------------
# Functions
# ----------------------------------------

# Test for root user
rootuser () {
  if [[ "$EUID" = 0 ]]; then
    continue
  else
    echo "Please Run As Root or sudo"
    sleep 2
    exit
  fi
}

# Display line error
handlerror () {
clear
set -uo pipefail
trap 's=$?; echo "$0: Error on line "$LINENO": $BASH_COMMAND"; exit $s' ERR
}

# Clean up working directories
cleanup () {
[[ -d ./arch_skel ]] && rm -r ./arch_skel
[[ -d ./work ]] && rm -r ./work
sleep 2
}

# Requirements and preparation
_isInstalled() {
    package="$1";
    check="$(sudo pacman -Qs --color always "${package}" | grep "local" | grep "${package} ")";
    if [ -n "${check}" ] ; then
        echo 0; #'0' means 'true' in Bash
        return; #true
    fi;
    echo 1; #'1' means 'false' in Bash
    return; #false
}

prereqs() {

    # The packages that are not installed will be added to this array.
    toInstall=();

    for pkg; do
        # If the package IS installed, skip it.
        if [[ $(_isInstalled "${pkg}") == 0 ]]; then
            echo "${pkg} is already installed.";
            continue;
        fi;

        #Otherwise, add it to the list of packages to install.
        toInstall+=("${pkg}");
    done;

    # If no packages were added to the "${toInstall[@]}" array,
    #     don't do anything and stop this function.
    if [[ "${toInstall[@]}" == "" ]] ; then
        echo "All packages are already installed.";
        return;
    fi;

    # Otherwise, install all the packages that have been added to the "${toInstall[@]}" array.
    printf "Packages not installed:\n%s\n" "${toInstall[@]}";
    sudo pacman -S --needed --noconfirm "${toInstall[@]}";
}

# Copy Arch profile to working directory
cp_releng () {
cp -r /usr/share/archiso/configs/releng/ ./arch_skel
rm -r ./arch_skel/efiboot
rm -r ./arch_skel/syslinux
}

# Copy cust_repo to opt
cp_repo () {
if [ -d "./cust_repo" ]
then
    cp -r ./cust_repo /opt/repo
fi
}

# Remove ezrepo from opt
rm_repo () {
if [ -d "/opt/repo" ]
then
    rm -r /opt/repo
fi
}

# Delete automatic login
nalogin () {
rm -r ./arch_skel/airootfs/etc/systemd/system/getty@tty1.service.d
}

# Remove cloud-init, hyper-v, qemu-guest, vmtoolsd, sshd, systemd-networkd & iwd services
rmunitsd () {
rm ./arch_skel/airootfs/etc/systemd/system/multi-user.target.wants/hv_fcopy_daemon.service
rm ./arch_skel/airootfs/etc/systemd/system/multi-user.target.wants/hv_kvp_daemon.service
rm ./arch_skel/airootfs/etc/systemd/system/multi-user.target.wants/hv_vss_daemon.service
rm ./arch_skel/airootfs/etc/systemd/system/multi-user.target.wants/qemu-guest-agent.service
rm ./arch_skel/airootfs/etc/systemd/system/multi-user.target.wants/vmtoolsd.service
rm ./arch_skel/airootfs/etc/systemd/system/multi-user.target.wants/vmware-vmblock-fuse.service
rm ./arch_skel/airootfs/etc/systemd/system/multi-user.target.wants/sshd.service
rm ./arch_skel/airootfs/etc/systemd/system/multi-user.target.wants/systemd-networkd.service
rm ./arch_skel/airootfs/etc/systemd/system/network-online.target.wants/systemd-networkd-wait-online.service
rm ./arch_skel/airootfs/etc/systemd/system/sockets.target.wants/systemd-networkd.socket
rm ./arch_skel/airootfs/etc/systemd/system/dbus-org.freedesktop.network1.service
rm ./arch_skel/airootfs/etc/systemd/system/multi-user.target.wants/iwd.service
rm -r ./arch_skel/airootfs/etc/systemd/system/cloud-init.target.wants
}

# Add Bluetooth, cups, haveged, NetworkManager, & sddm systemd links
addnmlinks () {
mkdir -p ./arch_skel/airootfs/etc/systemd/system/network-online.target.wants
mkdir -p ./arch_skel/airootfs/etc/systemd/system/multi-user.target.wants
mkdir -p ./arch_skel/airootfs/etc/systemd/system/bluetooth.target.wants
mkdir -p ./arch_skel/airootfs/etc/systemd/system/printer.target.wants
mkdir -p ./arch_skel/airootfs/etc/systemd/system/sockets.target.wants
mkdir -p ./arch_skel/airootfs/etc/systemd/system/timers.target.wants
mkdir -p ./arch_skel/airootfs/etc/systemd/system/sysinit.target.wants
ln -sf /usr/lib/systemd/system/NetworkManager-wait-online.service ./arch_skel/airootfs/etc/systemd/system/network-online.target.wants/NetworkManager-wait-online.service
ln -sf /usr/lib/systemd/system/NetworkManager-dispatcher.service ./arch_skel/airootfs/etc/systemd/system/dbus-org.freedesktop.nm-dispatcher.service
ln -sf /usr/lib/systemd/system/NetworkManager.service ./arch_skel/airootfs/etc/systemd/system/multi-user.target.wants/NetworkManager.service
ln -sf /usr/lib/systemd/system/bluetooth.service ./arch_skel/airootfs/etc/systemd/system/bluetooth.target.wants/bluetooth.service
ln -sf /usr/lib/systemd/system/haveged.service ./arch_skel/airootfs/etc/systemd/system/sysinit.target.wants/haveged.service
ln -sf /usr/lib/systemd/system/cups.service ./arch_skel/airootfs/etc/systemd/system/printer.target.wants/cups.service
ln -sf /usr/lib/systemd/system/cups.socket ./arch_skel/airootfs/etc/systemd/system/sockets.target.wants/cups.socket
ln -sf /usr/lib/systemd/system/cups.path ./arch_skel/airootfs/etc/systemd/system/multi-user.target.wants/cups.path
ln -sf /usr/lib/systemd/system/bluetooth.service ./arch_skel/airootfs/etc/systemd/system/dbus-org.bluez.service
ln -sf /usr/lib/systemd/system/lightdm.service ./arch_skel/airootfs/etc/systemd/system/display-manager.service
}

# Copy files to customize the ISO
cpmyfiles () {
cp ./cust_skel/packages.x86_64 ./arch_skel/
cp ./cust_skel/pacman.conf ./arch_skel/
cp ./cust_skel/profiledef.sh ./arch_skel/
cp -r ./cust_skel/grub ./arch_skel/
cp -r ./cust_skel/efiboot ./arch_skel/
cp -r ./cust_skel/syslinux ./arch_skel/
cp -r ./cust_skel/airootfs ./arch_skel/
}

# Set hostname
sethostname () {
echo "${MYHOSTNM}" > ./arch_skel/airootfs/etc/hostname
}

# Create passwd file
# Changed user to 1000 from 1010
crtpasswd () {
echo "root:x:0:0:root:/root:/usr/bin/bash
"${MYUSERNM}":x:1000:1000::/home/"${MYUSERNM}":/bin/bash" > ./arch_skel/airootfs/etc/passwd
}

# Create group file
# Changed user to 1000 from 1010
crtgroup () {
echo "root:x:0:root
sys:x:3:"${MYUSERNM}"
adm:x:4:"${MYUSERNM}"
wheel:x:10:"${MYUSERNM}"
log:x:19:"${MYUSERNM}"
network:x:90:"${MYUSERNM}"
floppy:x:94:"${MYUSERNM}"
scanner:x:96:"${MYUSERNM}"
power:x:98:"${MYUSERNM}"
rfkill:x:850:"${MYUSERNM}"
users:x:985:"${MYUSERNM}"
video:x:860:"${MYUSERNM}"
storage:x:870:"${MYUSERNM}"
optical:x:880:"${MYUSERNM}"
lp:x:840:"${MYUSERNM}"
audio:x:890:"${MYUSERNM}"
autologin:x:965:"${MYUSERNM}"
"${MYUSERNM}":x:1000:" > ./arch_skel/airootfs/etc/group
}

# Create shadow file
crtshadow () {
usr_hash=$(openssl passwd -6 "${MYUSRPASSWD}")
root_hash=$(openssl passwd -6 "${RTPASSWD}")
echo "root:"${root_hash}":14871::::::
"${MYUSERNM}":"${usr_hash}":14871::::::" > ./arch_skel/airootfs/etc/shadow
}

# create gshadow file
crtgshadow () {
echo "root:!*::root
"${MYUSERNM}":!*::" > ./arch_skel/airootfs/etc/gshadow
}

# Set the keyboard layout
setkeylayout () {
echo "KEYMAP="${KEYMP}"" > ./arch_skel/airootfs/etc/vconsole.conf
}

# Create 00-keyboard.conf file
crtkeyboard () {
mkdir -p ./arch_skel/airootfs/etc/X11/xorg.conf.d
echo "Section \"InputClass\"
        Identifier \"system-keyboard\"
        MatchIsKeyboard \"on\"
        Option \"XkbLayout\" \""${KEYMP}"\"
        Option \"XkbModel\" \""${KEYMOD}"\"
EndSection" > ./arch_skel/airootfs/etc/X11/xorg.conf.d/00-keyboard.conf
}

# Fix 40-locale-gen.hook and create locale.conf
crtlocalec () {
sed -i "s/en_US/"${LCLST}"/g" ./arch_skel/airootfs/etc/pacman.d/hooks/40-locale-gen.hook
echo "LANG="${LCLST}".UTF-8" > ./arch_skel/airootfs/etc/locale.conf
}

# Start mkarchiso
runmkarchiso () {
mkarchiso -v -w ./work -o ./out ./arch_skel
}

# ----------------------------------------
# Run Functions
# ----------------------------------------

rootuser
handlerror
prereqs "archlinux-keyring" "archiso" "mkinitcpio-archiso"
cleanup
cp_releng
addnmlinks
cp_repo
nalogin
rmunitsd
cpmyfiles
sethostname
crtpasswd
crtgroup
crtshadow
crtgshadow
setkeylayout
crtkeyboard
crtlocalec
runmkarchiso
rm_repo


# Disclaimer:
#
# THIS SOFTWARE IS PROVIDED BY EZNIX “AS IS” AND ANY EXPRESS OR IMPLIED
# WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
# EVENT SHALL EZNIX BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
# BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
# IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
#
# END
#