2023-12-22 17:44:46 +00:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
# matter-setup | Matterlinux System Setup 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
|
|
|
|
}
|
|
|
|
|
|
|
|
#################
|
|
|
|
## main script ##
|
|
|
|
#################
|
|
|
|
if [ $# -eq 0 ]; then
|
|
|
|
error "Please specify a directory"
|
|
|
|
fi
|
|
|
|
|
|
|
|
TARGET=$(realpath $1)
|
|
|
|
if ! type mp > /dev/null; then
|
|
|
|
error "mp is not installed, please install and configure mp"
|
|
|
|
fi
|
|
|
|
|
|
|
|
info "Creating directory structure"
|
2024-01-06 15:23:08 +00:00
|
|
|
pushd $TARGET > /dev/null
|
|
|
|
mkdir -p {dev,proc,sys,run,tmp,root,home,boot}
|
2023-12-22 17:44:46 +00:00
|
|
|
mkdir -p var/{log,mail,lib}
|
|
|
|
mkdir -p usr/{bin,lib,sbin}
|
2024-01-06 15:23:08 +00:00
|
|
|
mkdir -p etc/mp
|
2023-12-22 17:44:46 +00:00
|
|
|
|
|
|
|
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:x: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
|
|
|
|
|
|
|
|
cp /etc/mp/cfg etc/mp/cfg
|
2024-01-06 15:23:08 +00:00
|
|
|
#cp ~/.gnupg/pubring.kbx root/.gnupg/pubring.kbx
|
|
|
|
popd > /dev/null
|
2023-12-22 17:44:46 +00:00
|
|
|
|
|
|
|
export MP_ROOT="$TARGET"
|
|
|
|
info "Syncing repositories"
|
|
|
|
mp-sync
|
|
|
|
check_ret "mp-sync command failed"
|
|
|
|
|
|
|
|
info "Installing base system packages"
|
|
|
|
mp-install acl attr coreutils binutils \
|
|
|
|
bash e2fsprogs udev file release \
|
|
|
|
findutils gawk grep gzip iana-etc \
|
|
|
|
inetutils intltool iproute kmod less \
|
|
|
|
openssl sed shadow tar tcl mandb \
|
|
|
|
man-pages tzdata util-linux which \
|
|
|
|
mp gettext iproute procps psmisc \
|
2024-01-11 19:25:41 +00:00
|
|
|
mandb kbd dbus vim nano libxml2
|
2023-12-22 17:44:46 +00:00
|
|
|
check_ret "mp-install command failed"
|
|
|
|
unset MP_ROOT
|
|
|
|
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
|
|
|
|
|
2024-01-06 15:23:08 +00:00
|
|
|
info "Installing certs"
|
|
|
|
wget -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, feel free to chroot"
|
2023-12-22 17:44:46 +00:00
|
|
|
# user is expected to do the following:
|
2024-01-06 15:23:08 +00:00
|
|
|
# - configure /etc/resolv.conf
|
2023-12-22 17:44:46 +00:00
|
|
|
# - install systemd
|
|
|
|
# - systemd-machine-id-setup
|
|
|
|
# - systemctl preset-all
|
|
|
|
# - add hostname
|
|
|
|
# - create fstab
|
|
|
|
# - install kernel
|
|
|
|
# - install grub
|
|
|
|
# - config grub
|