2023-12-22 17:44:46 +00:00
|
|
|
#!/bin/bash
|
|
|
|
|
2024-08-11 14:45:54 +00:00
|
|
|
# matter-base | MatterLinux release archive build script
|
2024-05-01 20:56:27 +00:00
|
|
|
# MatterLinux 2023-2024 (https://matterlinux.xyz)
|
2023-12-22 17:44:46 +00:00
|
|
|
|
|
|
|
# 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/>.
|
|
|
|
|
2024-08-11 14:45:54 +00:00
|
|
|
#############################
|
|
|
|
## import common functions ##
|
|
|
|
#############################
|
|
|
|
location="$(dirname "${0}")"
|
|
|
|
location="$(realpath "${location}")"
|
|
|
|
commonsh="$(echo "${location}" | sed 's/\/bin/\/lib/g')/mtsc-common.sh"
|
2023-12-22 17:44:46 +00:00
|
|
|
|
2024-08-11 14:45:54 +00:00
|
|
|
source "${commonsh}"
|
|
|
|
|
|
|
|
if [ "${?}" != "0" ]; then
|
|
|
|
echo "Failed to import mtsc-common"
|
|
|
|
exit 1
|
|
|
|
fi
|
2023-12-22 17:44:46 +00:00
|
|
|
|
|
|
|
#################
|
|
|
|
## main script ##
|
|
|
|
#################
|
2024-02-22 19:19:01 +00:00
|
|
|
if [ "$EUID" -ne 0 ]; then
|
|
|
|
error "You should run this script as root"
|
2024-08-11 14:45:54 +00:00
|
|
|
exit 1
|
2024-02-22 19:19:01 +00:00
|
|
|
fi
|
|
|
|
|
2023-12-22 17:44:46 +00:00
|
|
|
if [ $# -eq 0 ]; then
|
2024-01-16 21:05:00 +00:00
|
|
|
error "Please specify a name for the archive"
|
2024-08-11 14:45:54 +00:00
|
|
|
exit 1
|
2023-12-22 17:44:46 +00:00
|
|
|
fi
|
|
|
|
|
2024-08-11 14:45:54 +00:00
|
|
|
name="${1}"
|
2024-08-12 00:07:34 +00:00
|
|
|
target="$(realpath "${1}")"
|
2024-08-11 14:45:54 +00:00
|
|
|
|
|
|
|
if [ -d "${target}" ]; then
|
2024-01-16 21:05:00 +00:00
|
|
|
error "A directory with the specified archive name exists"
|
2024-08-11 14:45:54 +00:00
|
|
|
exit 1
|
2024-01-16 21:05:00 +00:00
|
|
|
fi
|
2024-08-11 14:45:54 +00:00
|
|
|
mkdir "${target}"
|
2024-01-16 21:05:00 +00:00
|
|
|
|
2024-08-11 14:45:54 +00:00
|
|
|
if ! type matt > /dev/null; then
|
|
|
|
error "matt is not installed, please install and configure matt"
|
|
|
|
exit 1
|
2023-12-22 17:44:46 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
info "Creating directory structure"
|
2024-08-11 14:45:54 +00:00
|
|
|
pushd "${target}" > /dev/null
|
|
|
|
install -Ddm755 {dev,proc,sys,run,tmp,root,home,boot,mnt}
|
|
|
|
install -Ddm755 var/{log,mail,lib}
|
|
|
|
install -Ddm755 usr/{bin,lib,sbin}
|
|
|
|
install -Ddm755 var/lib/matt
|
|
|
|
install -Ddm755 etc/matt
|
2023-12-22 17:44:46 +00:00
|
|
|
|
|
|
|
ln -sf usr/lib lib
|
|
|
|
ln -sf usr/lib lib64
|
2024-08-12 00:07:34 +00:00
|
|
|
|
2023-12-22 17:44:46 +00:00
|
|
|
ln -sf usr/bin bin
|
|
|
|
ln -sf usr/sbin sbin
|
|
|
|
|
|
|
|
cat > etc/passwd << "EOF"
|
2024-02-23 17:11:55 +00:00
|
|
|
root:!:0:0:root:/root:/bin/bash
|
2023-12-22 17:44:46 +00:00
|
|
|
bin:x:1:1:bin:/dev/null:/usr/bin/false
|
|
|
|
daemon:x:6:6:Daemon User:/dev/null:/usr/bin/false
|
|
|
|
messagebus:x:18:18:D-Bus Message Daemon User:/run/dbus:/usr/bin/false
|
|
|
|
uuidd:x:80:80:UUID Generation Daemon User:/dev/null:/usr/bin/false
|
|
|
|
nobody:x:65534:65534:Unprivileged User:/dev/null:/usr/bin/false
|
|
|
|
EOF
|
|
|
|
|
|
|
|
cat > etc/group << "EOF"
|
|
|
|
root:x:0:
|
|
|
|
bin:x:1:daemon
|
|
|
|
sys:x:2:
|
|
|
|
kmem:x:3:
|
|
|
|
tape:x:4:
|
|
|
|
tty:x:5:
|
|
|
|
daemon:x:6:
|
|
|
|
floppy:x:7:
|
|
|
|
disk:x:8:
|
|
|
|
lp:x:9:
|
|
|
|
dialout:x:10:
|
|
|
|
audio:x:11:
|
|
|
|
video:x:12:
|
|
|
|
utmp:x:13:
|
|
|
|
usb:x:14:
|
|
|
|
cdrom:x:15:
|
|
|
|
adm:x:16:
|
|
|
|
messagebus:x:18:
|
|
|
|
input:x:24:
|
|
|
|
mail:x:34:
|
|
|
|
kvm:x:61:
|
|
|
|
uuidd:x:80:
|
|
|
|
wheel:x:97:
|
|
|
|
users:x:999:
|
|
|
|
nogroup:x:65534:
|
|
|
|
EOF
|
|
|
|
|
|
|
|
cat > etc/hosts << EOF
|
2024-08-12 00:07:34 +00:00
|
|
|
127.0.0.1 localhost
|
2023-12-22 17:44:46 +00:00
|
|
|
::1 localhost
|
|
|
|
EOF
|
2024-01-06 15:23:08 +00:00
|
|
|
popd > /dev/null
|
2023-12-22 17:44:46 +00:00
|
|
|
|
2024-08-11 14:45:54 +00:00
|
|
|
info "Syncing repositories"
|
2024-08-15 18:59:35 +00:00
|
|
|
matt sync --root "${target}"
|
2024-08-11 14:45:54 +00:00
|
|
|
check_ret "matt command failed"
|
|
|
|
|
|
|
|
info "Installing base system packages"
|
|
|
|
matt install --root "${target}" --yes \
|
2024-08-12 00:07:34 +00:00
|
|
|
acl attr coreutils binutils \
|
|
|
|
bash e2fsprogs file release \
|
|
|
|
findutils gawk grep gzip \
|
|
|
|
iana-etc inetutils intltool \
|
|
|
|
kmod less openssl sed shadow \
|
|
|
|
tar tcl man-pages tzdata \
|
|
|
|
util-linux which matt \
|
|
|
|
gettext procps-ng psmisc kbd \
|
|
|
|
dbus vim nano libxml2 \
|
|
|
|
iproute2 man-db
|
2024-08-11 14:45:54 +00:00
|
|
|
check_ret "matt command failed"
|
2023-12-22 17:44:46 +00:00
|
|
|
success "Installed the base system"
|
|
|
|
|
2024-08-11 14:45:54 +00:00
|
|
|
cat > "${target}/etc/inputrc" << "EOF"
|
2023-12-22 17:44:46 +00:00
|
|
|
# do not bell on tab-completion
|
|
|
|
#set bell-style none
|
|
|
|
|
|
|
|
set meta-flag on
|
|
|
|
set input-meta on
|
|
|
|
set convert-meta off
|
|
|
|
set output-meta on
|
|
|
|
|
|
|
|
$if mode=emacs
|
|
|
|
|
|
|
|
# for linux console and RH/Debian xterm
|
|
|
|
"\e[1~": beginning-of-line
|
|
|
|
"\e[4~": end-of-line
|
|
|
|
"\e[5~": beginning-of-history
|
|
|
|
"\e[6~": end-of-history
|
|
|
|
"\e[7~": beginning-of-line
|
|
|
|
"\e[3~": delete-char
|
|
|
|
"\e[2~": quoted-insert
|
|
|
|
"\e[5C": forward-word
|
|
|
|
"\e[5D": backward-word
|
|
|
|
"\e\e[C": forward-word
|
|
|
|
"\e\e[D": backward-word
|
|
|
|
"\e[1;5C": forward-word
|
|
|
|
"\e[1;5D": backward-word
|
|
|
|
|
|
|
|
# for rxvt
|
|
|
|
"\e[8~": end-of-line
|
|
|
|
|
|
|
|
# for non RH/Debian xterm, can't hurt for RH/DEbian xterm
|
|
|
|
"\eOH": beginning-of-line
|
|
|
|
"\eOF": end-of-line
|
|
|
|
|
|
|
|
# for freebsd console
|
|
|
|
"\e[H": beginning-of-line
|
|
|
|
"\e[F": end-of-line
|
|
|
|
$endif
|
|
|
|
EOF
|
|
|
|
|
2024-08-11 14:45:54 +00:00
|
|
|
cat > "${target}/etc/shells" << "EOF"
|
2023-12-22 17:44:46 +00:00
|
|
|
/bin/sh
|
2024-08-12 00:07:34 +00:00
|
|
|
/bin/bash
|
2023-12-22 17:44:46 +00:00
|
|
|
EOF
|
|
|
|
|
2024-08-11 14:45:54 +00:00
|
|
|
cp "${target}/etc/skel/."* "${target}/root"
|
2024-01-18 15:02:56 +00:00
|
|
|
|
2024-01-06 15:23:08 +00:00
|
|
|
info "Installing certs"
|
2024-08-11 14:45:54 +00:00
|
|
|
wget --show-progress -q https://hg.mozilla.org/projects/nss/raw-file/tip/lib/ckfw/builtins/certdata.txt -O "${target}/certdata.txt"
|
2024-08-12 00:07:34 +00:00
|
|
|
matter-chroot "${target}" make-ca > /dev/null
|
2024-01-06 15:23:08 +00:00
|
|
|
check_ret "Failed to run make-ca, install certs manually"
|
2024-08-11 14:45:54 +00:00
|
|
|
rm -f "${target}/certdata.txt"
|
2024-01-06 15:23:08 +00:00
|
|
|
|
2024-08-12 00:18:48 +00:00
|
|
|
info "Running install scripts"
|
2024-08-15 18:59:35 +00:00
|
|
|
echo 'bash /var/lib/matt/data/scripts/*' > "${target}/install_scripts"
|
|
|
|
matter-chroot "${target}" bash /install_scripts > /dev/null
|
2024-08-12 00:18:48 +00:00
|
|
|
check_ret "Failed to run install scripts"
|
2024-08-12 00:19:54 +00:00
|
|
|
rm -r "${target}/var/lib/matt/data/scripts"
|
2024-08-15 18:59:35 +00:00
|
|
|
rm "${target}/install_scripts"
|
2024-08-12 00:18:48 +00:00
|
|
|
|
2024-01-16 21:05:00 +00:00
|
|
|
info "Setup complete, now creating the archive..."
|
2024-08-11 14:45:54 +00:00
|
|
|
pushd "${target}" > /dev/null
|
|
|
|
tar czf ../${name}.tar.gz *
|
2024-01-16 21:05:00 +00:00
|
|
|
check_ret "Failed to create the archive"
|
|
|
|
popd > /dev/null
|
|
|
|
|
|
|
|
success "Archive created, now cleaning up"
|
2024-08-11 14:45:54 +00:00
|
|
|
rm -rf "${target}" && success "Build completed"
|