Skip to content

Commit ac2b7a3

Browse files
authored
Fix subshell variable bugs and optimize build performance
2 parents ffa4cf4 + 30fefda commit ac2b7a3

File tree

3 files changed

+16
-17
lines changed

3 files changed

+16
-17
lines changed

04-customize-desktop.sh

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,8 @@ export DEBIAN_FRONTEND=noninteractive
44

55
echo "--> Removing unwanted packages..."
66
PACKAGES_TO_REMOVE="kmahjongg kmines kpat ksnake kmail kontact akregator"
7-
for pkg in $PACKAGES_TO_REMOVE; do
8-
apt-get purge -y "$pkg" || true
9-
done
7+
# Batch removal is more efficient than sequential
8+
apt-get purge -y $PACKAGES_TO_REMOVE || true
109
apt-get autoremove -y
1110

1211
echo "--> Setting up global assets..."

05-install-ai.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,15 @@ chmod 444 "${MODELFILE}"
1717
cat > /usr/local/bin/luminos-reassemble.sh << "EOF"
1818
#!/bin/bash
1919
# Find files marked as split
20-
find /usr/share/ollama/.ollama -name "*.is_split" | while read marker; do
20+
while IFS= read -r -d '' marker; do
2121
ORIG_FILE="${marker%.is_split}"
2222
if [ ! -f "$ORIG_FILE" ]; then
2323
echo "Reassembling $ORIG_FILE..."
2424
# Combine parts .partaa, .partab...
2525
cat "${ORIG_FILE}.part"* > "$ORIG_FILE"
2626
chown ollama:ollama "$ORIG_FILE"
2727
fi
28-
done
28+
done < <(find /usr/share/ollama/.ollama -name "*.is_split" -print0)
2929
EOF
3030
chmod +x /usr/local/bin/luminos-reassemble.sh
3131

build.sh

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@ AI_BUILD_DIR="${WORK_DIR}/ai_build"
1313
ISO_NAME="LuminOS-0.2.1-amd64.iso"
1414

1515
# Cleanup
16-
sudo umount "${CHROOT_DIR}/sys" &>/dev/null || true
17-
sudo umount "${CHROOT_DIR}/proc" &>/dev/null || true
18-
sudo umount "${CHROOT_DIR}/dev/pts" &>/dev/null || true
19-
sudo umount "${CHROOT_DIR}/dev" &>/dev/null || true
16+
# Unmount in reverse order if they exist
17+
for mount_point in "${CHROOT_DIR}/sys" "${CHROOT_DIR}/proc" "${CHROOT_DIR}/dev/pts" "${CHROOT_DIR}/dev"; do
18+
mountpoint -q "$mount_point" 2>/dev/null && sudo umount "$mount_point" || true
19+
done
2020
pkill -f "ollama serve" || true
2121
sudo rm -rf "${WORK_DIR}"
2222
sudo rm -f "${BASE_DIR}/${ISO_NAME}"
@@ -69,15 +69,15 @@ fi
6969
# 3b. CUT LARGE FILES (The Key Fix)
7070
echo "--> Cutting large AI files into 1GB chunks..."
7171
# Find files > 900MB (safety margin) inside the models directory
72-
find "${TARGET_MODEL_DIR}" -type f -size +900M | while read file; do
72+
while IFS= read -r -d '' file; do
7373
echo "Splitting $file ..."
7474
# Split into chunks named .partaa, .partab, etc.
7575
split -b 900M "$file" "$file.part"
7676
# Create a marker file to tell the OS this file needs reassembly
7777
touch "$file.is_split"
7878
# Remove the original giant file so it doesn't get into the ISO
7979
rm "$file"
80-
done
80+
done < <(find "${TARGET_MODEL_DIR}" -type f -size +900M -print0)
8181

8282
# --- 4. Bootstrap System ---
8383
echo "--> Bootstrapping Debian..."
@@ -131,7 +131,7 @@ echo "--> Creating Layers..."
131131

132132
# Layer 1: OS (Excluding models path)
133133
echo " Layer 1 (OS)..."
134-
mksquashfs "${CHROOT_DIR}" "${ISO_DIR}/live/01-filesystem.squashfs" -e boot -e usr/share/ollama/.ollama -comp zstd
134+
mksquashfs "${CHROOT_DIR}" "${ISO_DIR}/live/01-filesystem.squashfs" -e boot -e usr/share/ollama/.ollama -comp zstd -processors "$(nproc)"
135135

136136
# Prepare distribution directories
137137
L2="${WORK_DIR}/layer2"
@@ -152,7 +152,7 @@ mkdir -p "$L3/usr/share/ollama/.ollama/blobs"
152152
mkdir -p "$L4/usr/share/ollama/.ollama/blobs"
153153

154154
COUNT=0
155-
find "${TARGET_MODEL_DIR}/blobs" -type f | while read file; do
155+
while IFS= read -r -d '' file; do
156156
MOD=$((COUNT % 3))
157157
if [ $MOD -eq 0 ]; then
158158
cp "$file" "$L2/usr/share/ollama/.ollama/blobs/"
@@ -162,14 +162,14 @@ find "${TARGET_MODEL_DIR}/blobs" -type f | while read file; do
162162
cp "$file" "$L4/usr/share/ollama/.ollama/blobs/"
163163
fi
164164
COUNT=$((COUNT + 1))
165-
done
165+
done < <(find "${TARGET_MODEL_DIR}/blobs" -type f -print0)
166166

167167
echo " Layer 2..."
168-
mksquashfs "$L2" "${ISO_DIR}/live/02-ai-part1.squashfs" -comp zstd
168+
mksquashfs "$L2" "${ISO_DIR}/live/02-ai-part1.squashfs" -comp zstd -processors "$(nproc)"
169169
echo " Layer 3..."
170-
mksquashfs "$L3" "${ISO_DIR}/live/03-ai-part2.squashfs" -comp zstd
170+
mksquashfs "$L3" "${ISO_DIR}/live/03-ai-part2.squashfs" -comp zstd -processors "$(nproc)"
171171
echo " Layer 4..."
172-
mksquashfs "$L4" "${ISO_DIR}/live/04-ai-part3.squashfs" -comp zstd
172+
mksquashfs "$L4" "${ISO_DIR}/live/04-ai-part3.squashfs" -comp zstd -processors "$(nproc)"
173173

174174
# --- 7. Bootloader & Final ISO ---
175175
echo "--> Bootloader..."

0 commit comments

Comments
 (0)