201 lines
4.5 KiB
Bash
201 lines
4.5 KiB
Bash
#!/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"
|
|
pushd $TARGET > /dev/null
|
|
mkdir -p {dev,proc,sys,run,tmp,root,home,boot}
|
|
mkdir -p var/{log,mail,lib}
|
|
mkdir -p usr/{bin,lib,sbin}
|
|
mkdir -p etc/mp
|
|
|
|
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
|
|
#cp ~/.gnupg/pubring.kbx root/.gnupg/pubring.kbx
|
|
popd > /dev/null
|
|
|
|
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 \
|
|
mandb kbd dbus vim nano libxml2
|
|
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
|
|
|
|
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"
|
|
# 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
|