Added matter-iso script and fixed few issues in matter-chroot
This commit is contained in:
parent
bc4e2c0fb4
commit
69a85ffd48
2
Makefile
2
Makefile
@ -4,10 +4,12 @@ install:
|
||||
install -v -m755 matter-setup/main.sh $(DESTDIR)$(prefix)/bin/matter-setup
|
||||
install -v -m755 matter-mirror/main.py $(DESTDIR)$(prefix)/bin/matter-mirror
|
||||
install -v -m755 matter-chroot/main.sh $(DESTDIR)$(prefix)/bin/matter-chroot
|
||||
install -v -m755 matter-iso/main.sh $(DESTDIR)$(prefix)/bin/matter-iso
|
||||
|
||||
uninstall:
|
||||
rm -v $(DESTDIR)$(prefix)/bin/matter-setup
|
||||
rm -v $(DESTDIR)$(prefix)/bin/matter-mirror
|
||||
rm -v $(DESTDIR)$(prefix)/bin/matter-chroot
|
||||
rm -v $(DESTDIR)$(prefix)/bin/matter-iso
|
||||
|
||||
.PHONY: install uninstall
|
||||
|
@ -32,37 +32,51 @@ error() {
|
||||
## util functions ##
|
||||
####################
|
||||
chrt() {
|
||||
mount --bind /dev $TARGET/dev
|
||||
mount --bind /dev/pts $TARGET/dev/pts
|
||||
mount -t proc proc $TARGET/proc
|
||||
mount -t sysfs sysfs $TARGET/sys
|
||||
mount -t tmpfs tmpfs $TARGET/run
|
||||
mount -t proc proc "$TARGET/proc"
|
||||
mount -t sysfs sysfs "$TARGET/sys"
|
||||
if [[ -d "$TARGET/sys/firmware/efi/efivars" ]]; then
|
||||
mount -t efivarfs efivarfs "$TARGET/sys/firmware/efi/efivars"
|
||||
fi
|
||||
|
||||
mount -o bind /dev "$TARGET/dev"
|
||||
mount -t devpts none "$TARGET/dev/pts"
|
||||
mount -t tmpfs tmpfs "$TARGET/run"
|
||||
|
||||
if [ -h $TARGET/dev/shm ]; then
|
||||
mkdir -p $TARGET/$(readlink $TARGET/dev/shm)
|
||||
else
|
||||
mount -t tmpfs -o nosuid,nodev tmpfs $TARGET/dev/shm
|
||||
mount -t tmpfs -o nosuid,nodev tmpfs "$TARGET/dev/shm"
|
||||
fi
|
||||
|
||||
|
||||
local prompt='\['$BOLD'\['$RED'(chroot)\['$RESET'\['$BOLD' \u@\h:\w#\['$RESET' '
|
||||
chroot $TARGET /usr/bin/env -i \
|
||||
chroot "$TARGET" /usr/bin/env -i \
|
||||
HOME=/root \
|
||||
TERM="$TERM" \
|
||||
PS1="$prompt" \
|
||||
PATH=/usr/bin:/usr/sbin \
|
||||
$@
|
||||
"$@"
|
||||
|
||||
umount $TARGET/dev/pts
|
||||
mountpoint -q $TARGET/dev/shm && umount $TARGET/dev/shm
|
||||
umount $TARGET/dev
|
||||
umount $TARGET/run
|
||||
umount $TARGET/proc
|
||||
umount $TARGET/sys
|
||||
# kill procs that may prevent umount
|
||||
killall -9 dirmngr 2> /dev/null
|
||||
killall -9 gpg-agent 2> /dev/null
|
||||
|
||||
umount "$TARGET/proc"
|
||||
mountpoint -q "$TARGET/sys/firmware/efi/efivars" && umount "$TARGET/sys/firmware/efi/efivars"
|
||||
umount "$TARGET/sys"
|
||||
|
||||
umount "$TARGET/dev/pts"
|
||||
mountpoint -q "$TARGET/dev/shm" && umount "$TARGET/dev/shm"
|
||||
umount "$TARGET/dev"
|
||||
umount "$TARGET/run"
|
||||
}
|
||||
|
||||
#################
|
||||
## main script ##
|
||||
#################
|
||||
if [ "$EUID" -ne 0 ]; then
|
||||
error "Cannot chroot without root"
|
||||
fi
|
||||
|
||||
if [ $# -eq 0 ]; then
|
||||
error "Please specify a directory"
|
||||
fi
|
||||
@ -81,4 +95,4 @@ if [ $# -gt 1 ]; then
|
||||
exit 0
|
||||
fi
|
||||
|
||||
chrt bash --login
|
||||
chrt bash --login
|
||||
|
3
matter-iso/.gitignore
vendored
Normal file
3
matter-iso/.gitignore
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
*.tar.gz.sig
|
||||
*.tar.gz
|
||||
test/
|
11
matter-iso/README.md
Normal file
11
matter-iso/README.md
Normal file
@ -0,0 +1,11 @@
|
||||
# matter-iso
|
||||
This script is used for creating release ISO images from
|
||||
release archives.
|
||||
|
||||
### Usage
|
||||
To use the `matter-iso` script, specify a release archive and
|
||||
an output directory. You can specify a local file or a remote
|
||||
file as the archive:
|
||||
```
|
||||
matter-setup matterlinux_24.0.tar.gz isobuild
|
||||
```
|
180
matter-iso/main.sh
Executable file
180
matter-iso/main.sh
Executable file
@ -0,0 +1,180 @@
|
||||
#!/bin/bash
|
||||
|
||||
# matter-iso | MatterLinux ISO Build Script
|
||||
# Copyright (C) 2023 Matterlinux
|
||||
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
############################
|
||||
## logging functions/vars ##
|
||||
############################
|
||||
BOLD="\e[1m"
|
||||
RESET="\e[0m"
|
||||
GREEN="\e[32m"
|
||||
BLUE="\e[34m"
|
||||
GRAY="\e[37m"
|
||||
RED="\e[31m"
|
||||
|
||||
success() {
|
||||
echo -e "$BOLD$GREEN>>>$RESET$BOLD $1$RESET"
|
||||
}
|
||||
|
||||
info() {
|
||||
echo -e "$BOLD$BLUE>>>$RESET$BOLD $1$RESET"
|
||||
}
|
||||
|
||||
error() {
|
||||
echo -e "$BOLD$RED>>>$RESET$BOLD $1$RESET"
|
||||
exit 1
|
||||
}
|
||||
|
||||
####################
|
||||
## util functions ##
|
||||
####################
|
||||
check_ret() {
|
||||
if [ $? -ne 0 ]; then
|
||||
error "$1"
|
||||
fi
|
||||
}
|
||||
|
||||
setup_dns() {
|
||||
info "Setting up DNS"
|
||||
echo "nameserver 1.1.1.1" >> "$ROOTDIR/etc/resolv.conf"
|
||||
}
|
||||
|
||||
clean_dns(){
|
||||
rm "$ROOTDIR/etc/resolv.conf"
|
||||
}
|
||||
|
||||
#################
|
||||
## main script ##
|
||||
#################
|
||||
if [ $# -ne 2 ]; then
|
||||
error "Please specify a release archive and an output directory"
|
||||
fi
|
||||
|
||||
ARCHIVE="$(realpath $1)"
|
||||
if [ ! -f $ARCHIVE ]; then
|
||||
error "Archive file not found"
|
||||
fi
|
||||
|
||||
PUBKEY="F9E70878C2FB389AEC2BA34CA3654DF5AD9F641D"
|
||||
OUTDIR="$(realpath $2)"
|
||||
ROOTDIR="$OUTDIR/root"
|
||||
TMPDIR="$OUTDIR/tmp"
|
||||
|
||||
mkdir -p $TMPDIR
|
||||
if [ -d $ROOTDIR ]; then
|
||||
rm -rf $ROOTDIR
|
||||
fi
|
||||
mkdir -p $ROOTDIR
|
||||
|
||||
pushd $OUTDIR > /dev/null
|
||||
cp $ARCHIVE release.tar.gz
|
||||
check_ret "Failed to copy the archive!"
|
||||
|
||||
if [[ "$(file release.tar.gz)" != *"gzip compressed data"* ]]; then
|
||||
error "Bad archive format"
|
||||
fi
|
||||
|
||||
info "Extracting archive..."
|
||||
tar xf release.tar.gz -C "$ROOTDIR"
|
||||
check_ret "Extract failed!"
|
||||
popd > /dev/nul
|
||||
|
||||
setup_dns
|
||||
info "Adding public key"
|
||||
matter-chroot "$ROOTDIR" gpg --receive-key $PUBKEY
|
||||
|
||||
info "Installing extra packages"
|
||||
matter-chroot "$ROOTDIR" mp-sync
|
||||
matter-chroot "$ROOTDIR" mp-install systemd dhcpcd
|
||||
check_ret "Install failed!"
|
||||
clean_dns
|
||||
|
||||
info "Configuring base system"
|
||||
matter-chroot "$ROOTDIR" systemd-machine-id-setup
|
||||
matter-chroot "$ROOTDIR" systemctl preset-all
|
||||
matter-chroot "$ROOTDIR" cp /etc/skel/.* /root
|
||||
matter-chroot "$ROOTDIR" cp /usr/sbin/init .
|
||||
|
||||
echo "matteriso" >> "$ROOTDIR/etc/hostname"
|
||||
cat > "$ROOTDIR/etc/issue" << EOF
|
||||
Welcome to MatterLinux ISO!
|
||||
|
||||
- Login with root:root
|
||||
- Sync before installing packages: mp-sync
|
||||
- For installation: https://matterlinux.xyz/wiki/install
|
||||
- Join XMPP for questions: general@conf.matterlinux.xyz
|
||||
|
||||
Happy hacking!
|
||||
|
||||
EOF
|
||||
|
||||
info "Changing password"
|
||||
cat > "$ROOTDIR/passwd.sh" << EOF
|
||||
echo "root:root" | chpasswd
|
||||
EOF
|
||||
matter-chroot "$ROOTDIR" bash /passwd.sh
|
||||
rm "$ROOTDIR/passwd.sh"
|
||||
|
||||
success "Setup completed, now creating the ISO"
|
||||
pushd "$ROOTDIR" > /dev/null
|
||||
info "Building initrd..."
|
||||
find . | cpio --quiet -H newc -o | xz -T0 --check=crc32 > "$TMPDIR/initrd.img"
|
||||
check_ret "Failed to build initrd"
|
||||
popd > /dev/null
|
||||
|
||||
setup_dns
|
||||
info "Installing and copying over the kernel"
|
||||
matter-chroot "$ROOTDIR" mp-install linux
|
||||
cp "$ROOTDIR/boot/vmlinuz-linux" "$TMPDIR"
|
||||
clean_dns
|
||||
|
||||
info "Saving the grub configuration"
|
||||
mkdir -p "$TMPDIR/boot/grub"
|
||||
cat > "$TMPDIR/boot/grub/grub.cfg" << EOF
|
||||
set default=0
|
||||
set timeout=10
|
||||
insmod efi_gop
|
||||
insmod font
|
||||
if loadfont /boot/grub/fonts/unicode.pf2
|
||||
then
|
||||
insmod gfxterm
|
||||
set gfxmode-auto
|
||||
set gfxpayload=keep
|
||||
terminal_output gfxterm
|
||||
fi
|
||||
|
||||
menuentry 'Matter GNU/Linux ISO' --class os {
|
||||
insmod gzio
|
||||
insmod part_msdos
|
||||
linux /vmlinuz-linux
|
||||
initrd /initrd.img
|
||||
}
|
||||
EOF
|
||||
|
||||
info "Building the ISO"
|
||||
pushd "$OUTDIR" > /dev/null
|
||||
grub-mkrescue -o "matter.iso" $TMPDIR
|
||||
check_ret "grub-mkrescue failed!"
|
||||
popd > /dev/null
|
||||
|
||||
success "ISO is ready for boot"
|
||||
|
||||
info "Cleaning up"
|
||||
rm -rf $TMPDIR
|
||||
rm "$OUTDIR/release.tar.gz"
|
||||
|
||||
success "Build completed"
|
Loading…
Reference in New Issue
Block a user