196 lines
4.6 KiB
Bash
Executable File
196 lines
4.6 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
# matter-base | MatterLinux release archive build script
|
|
# MatterLinux 2023-2024 (https://matterlinux.xyz)
|
|
|
|
# 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/>.
|
|
|
|
#############################
|
|
## import common functions ##
|
|
#############################
|
|
location="$(dirname "${0}")"
|
|
location="$(realpath "${location}")"
|
|
commonsh="$(echo "${location}" | sed 's/\/bin/\/lib/g')/mtsc-common.sh"
|
|
|
|
source "${commonsh}"
|
|
|
|
if [ "${?}" != "0" ]; then
|
|
echo "Failed to import mtsc-common"
|
|
exit 1
|
|
fi
|
|
|
|
#################
|
|
## main script ##
|
|
#################
|
|
if [ "$EUID" -ne 0 ]; then
|
|
error "You should run this script as root"
|
|
exit 1
|
|
fi
|
|
|
|
if [ $# -eq 0 ]; then
|
|
error "Please specify a name for the archive"
|
|
exit 1
|
|
fi
|
|
|
|
name="${1}"
|
|
target="$(realpath "${1}")"
|
|
|
|
if [ -d "${target}" ]; then
|
|
error "A directory with the specified archive name exists"
|
|
exit 1
|
|
fi
|
|
mkdir "${target}"
|
|
|
|
if ! type matt > /dev/null; then
|
|
error "matt is not installed, please install and configure matt"
|
|
exit 1
|
|
fi
|
|
|
|
info "Creating directory structure"
|
|
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
|
|
|
|
ln -sf usr/lib lib
|
|
ln -sf usr/lib lib64
|
|
|
|
ln -sf usr/bin bin
|
|
ln -sf usr/sbin sbin
|
|
|
|
cat > etc/passwd << "EOF"
|
|
root:!:0:0:root:/root:/bin/bash
|
|
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
|
|
127.0.0.1 localhost
|
|
::1 localhost
|
|
EOF
|
|
popd > /dev/null
|
|
|
|
info "Syncing repositories"
|
|
matt sync --root "${target}" --yes
|
|
check_ret "matt command failed"
|
|
|
|
info "Installing base system packages"
|
|
matt install --root "${target}" --yes \
|
|
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
|
|
check_ret "matt command failed"
|
|
success "Installed the base system"
|
|
|
|
cat > "${target}/etc/inputrc" << "EOF"
|
|
# 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
|
|
|
|
cat > "${target}/etc/shells" << "EOF"
|
|
/bin/sh
|
|
/bin/bash
|
|
EOF
|
|
|
|
cp "${target}/etc/skel/."* "${target}/root"
|
|
|
|
info "Installing certs"
|
|
wget --show-progress -q https://hg.mozilla.org/projects/nss/raw-file/tip/lib/ckfw/builtins/certdata.txt -O "${target}/certdata.txt"
|
|
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, 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"
|