131 lines
2.7 KiB
Bash
131 lines
2.7 KiB
Bash
mo() {
|
|
local root="${1}"
|
|
if [ -z "${root}" ]; then
|
|
log_error "No root target directory"
|
|
return 1
|
|
fi
|
|
root="$(realpath "${root}")"
|
|
if ! mkdir "overlay"; then
|
|
log_error "Unable to make overlay directory"
|
|
return 2
|
|
fi
|
|
(
|
|
if ! cd "overlay"; then
|
|
log_error "Unable to move into overlay directory"
|
|
return 3
|
|
fi
|
|
local directory
|
|
for directory in "lower" "upper" "work" "mount"; do
|
|
if ! mkdir --parents "${directory}"; then
|
|
log_error "Unable to make directory: ${directory}"
|
|
return 4
|
|
fi
|
|
done
|
|
local file="${root}/filesystem.squashfs"
|
|
if ! mount "${file}" "lower"; then
|
|
log_error "Unable to lower mount: ${file}"
|
|
return 5
|
|
fi
|
|
if ! mount \
|
|
-o "lowerdir=lower,upperdir=upper,workdir=work" \
|
|
-t "overlay" \
|
|
"overlay" "mount"; then
|
|
log_error "Unable to overlay mount"
|
|
return 6
|
|
fi
|
|
)
|
|
}
|
|
|
|
uo() {
|
|
(
|
|
if ! cd "overlay"; then
|
|
log_error "Unable to move into overlay directory"
|
|
return 1
|
|
fi
|
|
if ! umount "mount"; then
|
|
log_error "Unable to unmount mount directory"
|
|
return 2
|
|
fi
|
|
if ! rmdir "mount"; then
|
|
log_error "Unable to remove mount directory"
|
|
return 3
|
|
fi
|
|
local directory
|
|
for directory in "upper" "work"; do
|
|
if ! rm --force --recursive "${directory}"; then
|
|
log_error "Unable to remove directory: ${directory}"
|
|
return 4
|
|
fi
|
|
done
|
|
if ! umount "lower"; then
|
|
log_error "Unable to unmount lower directory"
|
|
return 5
|
|
fi
|
|
if ! rmdir "lower"; then
|
|
log_error "Unable to remove lower directory"
|
|
return 6
|
|
fi
|
|
)
|
|
if ! rmdir "overlay"; then
|
|
log_error "Unable to remove overlay directory"
|
|
return 7
|
|
fi
|
|
}
|
|
|
|
mr() {
|
|
local directory
|
|
for directory in "dev" "dev/pts" "proc" "sys"; do
|
|
if ! mount --bind "/${directory}" "overlay/mount/${directory}"; then
|
|
log_error "Unable to bind mount directory: ${directory}"
|
|
return 1
|
|
fi
|
|
done
|
|
}
|
|
|
|
cr() {
|
|
chroot \
|
|
"overlay/mount" "${@}"
|
|
}
|
|
|
|
cru() {
|
|
chroot \
|
|
--userspec "1000:1000" \
|
|
"overlay/mount" "${@}"
|
|
}
|
|
|
|
ur() {
|
|
local directory
|
|
for directory in "sys" "proc" "dev/pts" "dev"; do
|
|
if ! umount --lazy "overlay/mount/${directory}"; then
|
|
log_error "Unable to bind unmount directory: ${directory}"
|
|
return 1
|
|
fi
|
|
done
|
|
}
|
|
|
|
mm() {
|
|
mount --make-rslave --rbind "/deb" "overlay/mount/deb"
|
|
}
|
|
|
|
um() {
|
|
umount --recursive "overlay/mount/deb"
|
|
}
|
|
|
|
ms() {
|
|
local directory="${1}"
|
|
local file
|
|
local level="${2}"
|
|
if [ -n "${directory}" ]; then
|
|
if mkdir "${directory}"; then
|
|
[ -n "${level}" ] || level="18"
|
|
for file in "vmlinuz" "initrd.img"; do
|
|
cp "overlay/mount/${file}" "${directory}"
|
|
done
|
|
mksquashfs \
|
|
"overlay/mount" "${directory}/filesystem.squashfs" \
|
|
-noappend \
|
|
-comp "zstd" -Xcompression-level "${level}"
|
|
chown --recursive 1000:1000 "${directory}"
|
|
fi
|
|
fi
|
|
}
|