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 prefix = /usr
install: 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-mirror/main.py $(DESTDIR)$(prefix)/bin/matter-mirror
install -v -m755 matter-chroot/main.sh $(DESTDIR)$(prefix)/bin/matter-chroot 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 install -v -m755 matter-iso/main.sh $(DESTDIR)$(prefix)/bin/matter-iso
uninstall: uninstall:
rm -v $(DESTDIR)$(prefix)/bin/matter-setup
rm -v $(DESTDIR)$(prefix)/bin/matter-mirror rm -v $(DESTDIR)$(prefix)/bin/matter-mirror
rm -v $(DESTDIR)$(prefix)/bin/matter-chroot rm -v $(DESTDIR)$(prefix)/bin/matter-chroot
rm -v $(DESTDIR)$(prefix)/bin/matter-base
rm -v $(DESTDIR)$(prefix)/bin/matter-iso rm -v $(DESTDIR)$(prefix)/bin/matter-iso
.PHONY: install uninstall .PHONY: install uninstall

View File

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

View File

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

View File

@ -4,8 +4,8 @@ release archives.
### Usage ### Usage
To use the `matter-iso` script, specify a release archive and To use the `matter-iso` script, specify a release archive and
an output directory. You can specify a local file or a remote a configuration directory:
file as the archive:
``` ```
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" BLUE="\e[34m"
GRAY="\e[37m" GRAY="\e[37m"
RED="\e[31m" RED="\e[31m"
LOG_PREFIX=">>>"
echo_color() {
echo -e "${1}"
}
success() { success() {
echo -e "$BOLD$GREEN>>>$RESET$BOLD $1$RESET" echo_color "${BOLD}${GREEN}${LOG_PREFIX}${RESET}${BOLD} $1 ${RESET}"
} }
info() { info() {
echo -e "$BOLD$BLUE>>>$RESET$BOLD $1$RESET" echo_color "${BOLD}${BLUE}${LOG_PREFIX}${RESET}${BOLD} $1 ${RESET}"
} }
error() { error() {
echo -e "$BOLD$RED>>>$RESET$BOLD $1$RESET" echo_color "${BOLD}${RED}${LOG_PREFIX}${RESET}${BOLD} $1 ${RESET}"
exit 1 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 ## ## util functions ##
#################### ####################
@ -48,20 +69,46 @@ check_ret() {
fi fi
} }
check_retc() {
if [ $? -ne 0 ]; then
errorne "$1"
clean_tmpdir
fi
}
setup_dns() { setup_dns() {
info "Setting up 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(){ 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 ## ## main script ##
################# #################
if [ $# -ne 2 ]; then 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 fi
ARCHIVE="$(realpath $1)" ARCHIVE="$(realpath $1)"
@ -69,119 +116,122 @@ if [ ! -f $ARCHIVE ]; then
error "Archive file not found" error "Archive file not found"
fi fi
PUBKEY="F9E70878C2FB389AEC2BA34CA3654DF5AD9F641D" if [[ "$(file $ARCHIVE)" != *"gzip compressed data"* ]]; then
OUTDIR="$(realpath $2)" error "Bad archive format"
ROOTDIR="$OUTDIR/root"
TMPDIR="$OUTDIR/tmp"
mkdir -p $TMPDIR
if [ -d $ROOTDIR ]; then
rm -rf $ROOTDIR
fi fi
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 mkdir -p $ROOTDIR
success "Created root and dist directory"
pushd $OUTDIR > /dev/null info "Copying over the config directory"
cp $ARCHIVE release.tar.gz cp -r $CONFDIR $TMPDIR
check_ret "Failed to copy the archive!" check_ret "Copy failed"
if [[ "$(file release.tar.gz)" != *"gzip compressed data"* ]]; then if [ ! -f $ISOSH ]; then
error "Bad archive format" 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 fi
done
info "Extracting archive..." for p1 in "${PKGS1[@]}"; do
tar xf release.tar.gz -C "$ROOTDIR" if [ -z ${pkgs1_str+x} ]; then
check_ret "Extract failed!" pkgs1_str="$p1"
popd > /dev/nul 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 setup_dns
info "Adding public key" info "Adding public keys"
matter-chroot "$ROOTDIR" gpg --receive-key $PUBKEY matter-chroot "$TMPDIR" gpg --receive-keys $keys_str
check_retc "Failed to add public keys"
info "Installing extra packages" if [ ! -z "${PKGS1}" ]; then
matter-chroot "$ROOTDIR" mp-sync info "Installing extra packages (1)"
matter-chroot "$ROOTDIR" mp-install systemd dhcpcd matter-chroot "$TMPDIR" mp-sync
check_ret "Install failed!" check_retc "Sync failed"
matter-chroot "$TMPDIR" MP_YES=1 mp-install $pkgs1_str
check_retc "Install failed"
fi
clean_dns clean_dns
info "Configuring base system" info "Running build script"
matter-chroot "$ROOTDIR" systemd-machine-id-setup echo "source /iso.sh && build" > "$TMPDIR/stager.sh"
matter-chroot "$ROOTDIR" systemctl preset-all matter-chroot "$TMPDIR" chmod +x /stager.sh
matter-chroot "$ROOTDIR" cp /etc/skel/.* /root matter-chroot "$TMPDIR" /stager.sh
matter-chroot "$ROOTDIR" cp /usr/sbin/init . check_ret "Build script failed"
rm "$TMPDIR/stager.sh"
echo "matteriso" >> "$ROOTDIR/etc/hostname" info "Cleaning up and building initrd"
cat > "$ROOTDIR/etc/issue" << EOF rm "$ISOSH"
____________________ pushd "$TMPDIR" > /dev/null
MMMMMMMMMMMMMMMMMMMM mkdir -p "$ROOTDIR/boot"
MMMM MMMM MMMM find . | cpio --quiet -H newc -o | xz -T0 --check=crc32 > "$ROOTDIR/boot/initrd.img"
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"
check_ret "Failed to build initrd" check_ret "Failed to build initrd"
popd > /dev/null popd > /dev/null
setup_dns if [ ! -z "${PKGS2}" ]; then
info "Installing and copying over the kernel" info "Installing extra packages (2)"
matter-chroot "$ROOTDIR" mp-install linux setup_dns
cp "$ROOTDIR/boot/vmlinuz-linux" "$TMPDIR" matter-chroot "$TMPDIR" MP_YES=1 mp-install $pkgs2_str
clean_dns 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 fi
menuentry 'MatterLinux ISO' --class os { info "Copying over the bootdir"
insmod gzio cp -r "$TMPDIR/boot"/* "$ROOTDIR/boot"
insmod part_msdos
linux /vmlinuz-linux loglevel=3 quiet
initrd /initrd.img
}
EOF
info "Building the ISO" info "Building the ISO..."
pushd "$OUTDIR" > /dev/null pushd "$DISTDIR" > /dev/null
grub-mkrescue -o "matter.iso" $TMPDIR grub-mkrescue -o "$DISTDIR/${NAME}_${VERSION}.iso" root
check_ret "grub-mkrescue failed!" check_retc "grub-mkrescue failed"
popd > /dev/null popd > /dev/null
success "ISO is ready for boot" success "ISO is ready, cleaning up"
clean_tmpdir
info "Cleaning up"
rm -rf $TMPDIR
rm "$OUTDIR/release.tar.gz"
success "Build completed"

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
```