updating matter-iso and moving matter-setup to matter-base

This commit is contained in:
ngn 2024-01-17 00:05:00 +03:00
parent 1d2523589f
commit c24c99205d
8 changed files with 197 additions and 141 deletions

View File

@ -1,15 +1,15 @@
prefix = /usr
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-base/main.sh $(DESTDIR)$(prefix)/bin/matter-base
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-base
rm -v $(DESTDIR)$(prefix)/bin/matter-iso
.PHONY: install uninstall

View File

@ -13,4 +13,5 @@ make install
All tools/scripts contains usage information in README files:
- [matter-chroot](matter-chroot/README.md)
- [matter-mirror](matter-mirror/README.md)
- [matter-setup](matter-setup/README.md)
- [matter-base](matter-base/README.md)
- [matter-iso](matter-iso/README.md)

15
matter-base/README.md Normal file
View File

@ -0,0 +1,15 @@
# matter-base
This script is used for building release archives.
### Usage
Note that you will need to install and configure
[`mp`](https://git.matterlinux.xyz/matterlinux/mp) before using
`matter-base`.
To use the `matter-base` script, specify a temporary target
directory, it will be cleaned after the build. The final archive
will be named after the directory. For example:
```
matter-setup matterlinux_24.00
```
This will create an arhcive named `matterlinux_24.00.tar.gz`

View File

@ -1,6 +1,6 @@
#!/bin/bash
# matter-setup | Matterlinux System Setup Script
# matter-base | Matterlinux Release Archive Script
# Copyright (C) 2023 Matterlinux
# This program is free software: you can redistribute it and/or modify
@ -52,10 +52,16 @@ check_ret() {
## main script ##
#################
if [ $# -eq 0 ]; then
error "Please specify a directory"
error "Please specify a name for the archive"
fi
TARGET=$(realpath $1)
NAME="$1"
TARGET="$(realpath $1)"
if [ -d $TARGET ]; then
error "A directory with the specified archive name exists"
fi
mkdir $TARGET
if ! type mp > /dev/null; then
error "mp is not installed, please install and configure mp"
fi
@ -119,7 +125,7 @@ EOF
#cp ~/.gnupg/pubring.kbx root/.gnupg/pubring.kbx
popd > /dev/null
export MP_ROOT="$TARGET"
export MP_ROOT="$TARGET" MP_YES=1
info "Syncing repositories"
mp-sync
check_ret "mp-sync command failed"
@ -134,7 +140,7 @@ export MP_ROOT="$TARGET"
mp gettext iproute procps psmisc \
mandb kbd dbus vim nano libxml2
check_ret "mp-install command failed"
unset MP_ROOT
unset MP_ROOT MP_YES
success "Installed the base system"
cat > $TARGET/etc/inputrc << "EOF"
@ -187,14 +193,11 @@ matter-chroot $TARGET make-ca > /dev/null
check_ret "Failed to run make-ca, install certs manually"
rm -f "$TARGET/certdata.txt"
info "Setup complete, feel free to chroot"
# user is expected to do the following:
# - configure /etc/resolv.conf
# - install systemd
# - systemd-machine-id-setup
# - systemctl preset-all
# - add hostname
# - create fstab
# - install kernel
# - install grub
# - config grub
info "Setup complete, now creating the archive..."
pushd $TARGET > /dev/null
tar czf ../${NAME}.tar.gz *
check_ret "Failed to create the archive"
popd > /dev/null
success "Archive created, now cleaning up"
rm -rf $TARGET && success "Build completed"

View File

@ -55,6 +55,7 @@ chrt() {
PS1="$prompt" \
PATH=/usr/bin:/usr/sbin \
"$@"
RET_CODE=$?
# kill procs that may prevent umount
killall -9 dirmngr 2> /dev/null
@ -92,7 +93,8 @@ fi
if [ $# -gt 1 ]; then
chrt ${@:2}
exit 0
exit $RET_CODE
fi
chrt bash --login
exit $?

View File

@ -4,8 +4,8 @@ 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:
a configuration directory:
```
matter-setup matterlinux_24.0.tar.gz isobuild
matter-iso matterlinux_24.00.tar.gz isocfg
```
To learn more about the configuration, see the [wiki page for releases](/wiki/release).

View File

@ -25,20 +25,41 @@ GREEN="\e[32m"
BLUE="\e[34m"
GRAY="\e[37m"
RED="\e[31m"
LOG_PREFIX=">>>"
echo_color() {
echo -e "${1}"
}
success() {
echo -e "$BOLD$GREEN>>>$RESET$BOLD $1$RESET"
echo_color "${BOLD}${GREEN}${LOG_PREFIX}${RESET}${BOLD} $1 ${RESET}"
}
info() {
echo -e "$BOLD$BLUE>>>$RESET$BOLD $1$RESET"
echo_color "${BOLD}${BLUE}${LOG_PREFIX}${RESET}${BOLD} $1 ${RESET}"
}
error() {
echo -e "$BOLD$RED>>>$RESET$BOLD $1$RESET"
echo_color "${BOLD}${RED}${LOG_PREFIX}${RESET}${BOLD} $1 ${RESET}"
exit 1
}
errorne() {
echo_color "${BOLD}${RED}${LOG_PREFIX}${RESET}${BOLD} $1 ${RESET}"
}
print() {
echo_color "${BOLD}${GRAY}$1${RESET}"
}
set_indent() {
LOG_PREFIX="|>"
}
unset_indent() {
LOG_PREFIX=">>>"
}
####################
## util functions ##
####################
@ -48,20 +69,46 @@ check_ret() {
fi
}
check_retc() {
if [ $? -ne 0 ]; then
errorne "$1"
clean_tmpdir
fi
}
setup_dns() {
info "Setting up DNS"
echo "nameserver 1.1.1.1" >> "$ROOTDIR/etc/resolv.conf"
echo "nameserver 1.1.1.1" >> "$TMPDIR/etc/resolv.conf"
}
clean_dns(){
rm "$ROOTDIR/etc/resolv.conf"
rm "$TMPDIR/etc/resolv.conf"
}
clean_tmpdir(){
if [ -d $TMPDIR ]; then
info "Cleaning up temp directory"
rm -rf $TMPDIR
fi
}
check_iso_vars() {
if [ ! -n "$NAME" ]; then
return 1
elif [ ! -n "$VERSION" ]; then
return 1
elif ! type build &>/dev/null; then
return 1
fi
return 0
}
#################
## main script ##
#################
if [ $# -ne 2 ]; then
error "Please specify a release archive and an output directory"
error "Please specify a release archive and a config directory"
fi
ARCHIVE="$(realpath $1)"
@ -69,119 +116,122 @@ 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
if [[ "$(file $ARCHIVE)" != *"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
CONFDIR="$(realpath $2)"
if [ ! -d $CONFDIR ]; then
error "Config directory not found"
fi
TMPDIR="${CONFDIR}_tmp"
DISTDIR="${CONFDIR}/dist"
ROOTDIR="${DISTDIR}/root"
ISOSH="${TMPDIR}/iso.sh"
mkdir -p $ROOTDIR
success "Created root and dist directory"
info "Copying over the config directory"
cp -r $CONFDIR $TMPDIR
check_ret "Copy failed"
if [ ! -f $ISOSH ]; then
error "ISO script not found"
fi
source $ISOSH
check_retc "Cannot source the ISO script"
check_iso_vars
check_retc "ISO script is not valid"
success "Sourced the ISO script"
info "Removing excluded files"
rm -rf "$TMPDIR/dist"
set_indent
for e in "${EXCLUDE[@]}"; do
info "Removing $e"
rm -rf "$TMPDIR/$e"
done
unset_indent
info "Extracting release archive"
SECONDS=0
tar --skip-old-files -xf "$ARCHIVE" -C "$TMPDIR"
check_retc "Extract failed"
success "Extracted in ${SECONDS}s"
for k in "${KEYS[@]}"; do
if [ -z ${keys_str+x} ]; then
keys_str="$k"
else
keys_str="$keys_str $k"
fi
done
for p1 in "${PKGS1[@]}"; do
if [ -z ${pkgs1_str+x} ]; then
pkgs1_str="$p1"
else
pkgs1_str="$pkgs1_str $p1"
fi
done
for p2 in "${PKGS2[@]}"; do
if [ -z ${pkgs2_str+x} ]; then
pkgs2_str="$p2"
else
pkgs2_str="$pkgs2_str $p2"
fi
done
setup_dns
info "Adding public key"
matter-chroot "$ROOTDIR" gpg --receive-key $PUBKEY
info "Adding public keys"
matter-chroot "$TMPDIR" gpg --receive-keys $keys_str
check_retc "Failed to add public keys"
info "Installing extra packages"
matter-chroot "$ROOTDIR" mp-sync
matter-chroot "$ROOTDIR" mp-install systemd dhcpcd
check_ret "Install failed!"
if [ ! -z "${PKGS1}" ]; then
info "Installing extra packages (1)"
matter-chroot "$TMPDIR" mp-sync
check_retc "Sync failed"
matter-chroot "$TMPDIR" MP_YES=1 mp-install $pkgs1_str
check_retc "Install failed"
fi
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 .
info "Running build script"
echo "source /iso.sh && build" > "$TMPDIR/stager.sh"
matter-chroot "$TMPDIR" chmod +x /stager.sh
matter-chroot "$TMPDIR" /stager.sh
check_ret "Build script failed"
rm "$TMPDIR/stager.sh"
echo "matteriso" >> "$ROOTDIR/etc/hostname"
cat > "$ROOTDIR/etc/issue" << EOF
____________________
MMMMMMMMMMMMMMMMMMMM
MMMM MMMM MMMM
MMMM MMMM MMMM
MMMM MMMM MMMM Welcome to MatterLinux ISO!
MMMM MMMM MMMM Kernel: \r Arch: \m TTY: \l
MMMM MMMM MMMM
MMMM MMMM MMMM
- 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"
info "Cleaning up and building initrd"
rm "$ISOSH"
pushd "$TMPDIR" > /dev/null
mkdir -p "$ROOTDIR/boot"
find . | cpio --quiet -H newc -o | xz -T0 --check=crc32 > "$ROOTDIR/boot/initrd.img"
check_ret "Failed to build initrd"
popd > /dev/null
if [ ! -z "${PKGS2}" ]; then
info "Installing extra packages (2)"
setup_dns
info "Installing and copying over the kernel"
matter-chroot "$ROOTDIR" mp-install linux
cp "$ROOTDIR/boot/vmlinuz-linux" "$TMPDIR"
matter-chroot "$TMPDIR" MP_YES=1 mp-install $pkgs2_str
check_ret "Install failed"
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 'MatterLinux ISO' --class os {
insmod gzio
insmod part_msdos
linux /vmlinuz-linux loglevel=3 quiet
initrd /initrd.img
}
EOF
info "Copying over the bootdir"
cp -r "$TMPDIR/boot"/* "$ROOTDIR/boot"
info "Building the ISO"
pushd "$OUTDIR" > /dev/null
grub-mkrescue -o "matter.iso" $TMPDIR
check_ret "grub-mkrescue failed!"
info "Building the ISO..."
pushd "$DISTDIR" > /dev/null
grub-mkrescue -o "$DISTDIR/${NAME}_${VERSION}.iso" root
check_retc "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"
success "ISO is ready, cleaning up"
clean_tmpdir

View File

@ -1,15 +0,0 @@
# matter-setup
This script is used in the installation for setting up the base
system.
### Usage
Note that you will need to install and configure
[`mp`](https://git.matterlinux.xyz/matterlinux/mp) before using
`matter-setup`.
To use the `matter-setup` script, specify a target directory.
In a normal installation, this directory would most likely
be your mount directory:
```
matter-setup /mnt
```