cos/init
2024-08-11 23:11:50 +01:00

212 lines
5.2 KiB
Text
Executable file

mkfs -v -t ext4 /dev/<xxx> # on root partition
mkfs -v -t ext4 /dev/<yyy> # on home partition
export COS=/mnt/cos
mkdir -pv $COS
mount -v -t ext4 /dev/<xxx> $COS
mkdir -v $COS/home
mount -v -t ext4 /dev/<yyy> $COS/home
mkswap /dev/<zzz> # swap if you need
/sbin/swapon -v /dev/<zzz>
mkdir -pv $COS/{etc,var} $COS/usr/{bin,lib,sbin}
for i in bin lib sbin; do
ln -sv /$i $COS
done
ln -sv /usr/bin $COS/usr
case $(uname -m) in
x86_64) mkdir -pv $COS/lib64 ;;
esac
mkdir -pv $COS/{dev,proc,sys,run}
mount -v --bind /dev $COS/dev
mount -vt devpts devpts -o gid=5,mode=0620 $COS/dev/pts
mount -vt proc proc $COS/proc
mount -vt sysfs sysfs $COS/sys
mount -vt tmpfs tmpfs $COS/run
if [ -h $COS/dev/shm ]; then
install -v -d -m 1777 $COS$(realpath /dev/shm)
else
mount -vt tmpfs -o nosuid,nodev tmpfs $COS/dev/shm
fi
mkdir -pv /{boot,home,mnt,opt,srv}
mkdir -pv /etc/{opt,sysconfig}
mkdir -pv /lib/firmware
mkdir -pv /usr/{,local/}{include,src}
mkdir -pv /usr/local/{bin,lib,sbin}
mkdir -pv /usr/{,local/}share/{doc,locale,man,misc,terminfo}
mkdir -pv /usr/{,local/}share/man/man{1..8}
mkdir -pv /var/{cache,local,log,mail,opt,spool}
ln -sfv /run /var/run
ln -sfv /run/lock /var/lock
install -dv -m 0750 /root
install -dv -m 1777 /tmp /var/tmp
ln -sv /proc/self/mounts /etc/mtab
cat > /etc/hosts << EOF
127.0.0.1 localhost $(hostname)
::1 localhost
EOF
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:/dev/null:/usr/bin/false
messagebus:x:18:18:messagebus:/run/dbus:/usr/bin/false
nobody:x:65534:65534:nobody:/dev/null:/usr/bin/false
user:x:101:101::/home/user:/bin/sh
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:
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:
user:x:101:
EOF
install -o user -d /home/user
git clone https://repo.or.cz/tinycc
cd tinycc
./configure --config-musl --enable-static --disable-rpath --prefix="/mnt/cos/usr" --extra-cflags="-O3 -mtune=native -march=native -pipe -s -flto"
make
make install
git clone https://git.suckless.org/sbase
cd sbase
make
make install
git clone https://git.suckless.org/ubase
cd ubase
make
make install
git clone https://git.musl-libc.org/git/musl
cd musl
./configure
make
make install
git clone https://github.com/zlib-ng/zlib-ng
cd zlib-ng
./configure --zlib-compat
make
make install
tar -xf make-4.4.1.tar.gz
./configure --prefix=/mnt/cos/usr
make
ssu make install
tar -xf gettext-0.22.5.tar.gz
./configure --enable-threads=posix --disable-java --enable-static --prefix=/mnt/cos/usr
make
ssu make install
cat > /etc/fstab << "EOF"
/dev/nvme0n1p4 / ext4 rw,relatime 0 1
/dev/nvme0n1p5 /home ext4 rw,relatime 0 2
proc /proc proc nosuid,noexec,nodev 0 0
sysfs /sys sysfs nosuid,noexec,nodev 0 0
devpts /dev/pts devpts gid=5,mode=620 0 0
tmpfs /run tmpfs defaults 0 0
devtmpfs /dev devtmpfs mode=0755,nosuid 0 0
tmpfs /dev/shm tmpfs nosuid,nodev 0 0
cgroup2 /sys/fs/cgroup cgroup2 nosuid,noexec,nodev 0 0
EOF
echo "cos" > /etc/hostname
cat > /etc/inputrc << "EOF"
# /etc/inputrc - global inputrc for libreadline
# See readline(3readline) and `info rluserman' for more information.
# Be 8 bit clean.
set input-meta on
set output-meta on
# To allow the use of 8bit-characters like the german umlauts, uncomment
# the line below. However this makes the meta key not work as a meta key,
# which is annoying to those which don't need to type in 8-bit characters.
# set convert-meta off
# try to enable the application keypad when it is called. Some systems
# need this to enable the arrow keys.
# set enable-keypad on
# see /usr/share/doc/bash/inputrc.arrows for other codes of arrow keys
# do not bell on tab-completion
# set bell-style none
# set bell-style visible
# some defaults / modifications for the emacs mode
$if mode=emacs
# allow the use of the Home/End keys
"\e[1~": beginning-of-line
"\e[4~": end-of-line
# allow the use of the Delete/Insert keys
"\e[3~": delete-char
"\e[2~": quoted-insert
# mappings for "page up" and "page down" to step to the beginning/end
# of the history
# "\e[5~": beginning-of-history
# "\e[6~": end-of-history
# alternate mappings for "page up" and "page down" to search the history
# "\e[5~": history-search-backward
# "\e[6~": history-search-forward
# mappings for Ctrl-left-arrow and Ctrl-right-arrow for word moving
"\e[1;5C": forward-word
"\e[1;5D": backward-word
"\e[5C": forward-word
"\e[5D": backward-word
"\e\e[C": forward-word
"\e\e[D": backward-word
$if term=rxvt
"\e[7~": beginning-of-line
"\e[8~": end-of-line
"\eOc": forward-word
"\eOd": backward-word
$endif
# 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 > /etc/shells << "EOF"
/bin/sh
EOF
tar -xf git-2.46.0.tar.gz
cd git-2.46.0
# run as root
NO_GETTEXT=YesPlease NO_SVN_TESTS=YesPlease NO_REGEX=YesPlease ICONV_OMITS_BOM=Yes NO_SYS_POLL_H=1 NO_PYTHON=YesPlease NO_PERL=YesPlease NO_TCLTK=YesPlease make DESTDIR=/mnt/cos install