ostree_on_alt/mk_acos_repo.sh

87 lines
3.4 KiB
Bash
Raw Permalink Normal View History

2021-08-24 10:30:51 +03:00
#!/bin/sh
set -e
if [ `id -u` -ne 0 ]
then
echo "Запуск скрипта $0 возможет только от пользователя root (uid=0)"
exit 1
fi
MAIN_ROOT=root
MAIN_REPO=repo
BRANCH=alt/x86_64/containeros/stable
ACOS_ROOT=acos_root
mkdir $MAIN_ROOT
tar xf out/acos-latest-x86_64.tar -C $MAIN_ROOT --exclude=./dev/tty --exclude=./dev/tty0 --exclude=./dev/console --exclude=./dev/urandom --exclude=./dev/random --exclude=./dev/full --exclude=./dev/zero --exclude=/dev/null --exclude=./dev/pts/ptmx --exclude=./dev/null
#####################
apt-get remove -y -o "RPM::RootDir=$PWD/root" NetworkManager-daemon openresolv etcnet
rm -rf $MAIN_ROOT/etc/net/
rm -f $MAIN_ROOT/etc/resolv.conf
ln -sf /run/systemd/resolve/resolv.conf $MAIN_ROOT/etc/resolv.conf
apt-get install -o "RPM::RootDir=$PWD/root" dracut-network-055-alt2.noarch.rpm
apt-get install -o "RPM::RootDir=$PWD/root" ignition
#####################
#Вынести в m-i-p
chroot $MAIN_ROOT systemctl enable ignition-firstboot-complete.service ostree-remount.service sshd docker
sed -i 's/^LABEL=ROOT\t/LABEL=boot\t/g' $MAIN_ROOT/etc/fstab
sed -i 's/^AcceptEnv /#AcceptEnv /g' $MAIN_ROOT/etc/openssh/sshd_config
sed -i 's/^# WHEEL_USERS ALL=(ALL) ALL$/WHEEL_USERS ALL=(ALL) ALL/g' $MAIN_ROOT/etc/sudoers
sed -i 's|^HOME=/home$|HOME=/var/home|g' $MAIN_ROOT/etc/default/useradd
echo "blacklist floppy" > $MAIN_ROOT/etc/modprobe.d/blacklist-floppy.conf
mkdir $MAIN_ROOT/sysroot
ln -s sysroot/ostree $MAIN_ROOT/ostree
mv -f $MAIN_ROOT/home $MAIN_ROOT/opt $MAIN_ROOT/srv $MAIN_ROOT/mnt $MAIN_ROOT/var/
mv -f $MAIN_ROOT/root $MAIN_ROOT/var/roothome
mv -f $MAIN_ROOT/usr/local $MAIN_ROOT/var/usrlocal
ln -sf var/home $MAIN_ROOT/home
ln -sf var/opt $MAIN_ROOT/opt
ln -sf var/srv $MAIN_ROOT/srv
ln -sf var/roothome $MAIN_ROOT/root
ln -sf ../var/usrlocal $MAIN_ROOT/usr/local
ln -sf var/mnt $MAIN_ROOT/mnt
chroot $MAIN_ROOT chgrp wheel /usr/bin/sudo /bin/su
chroot $MAIN_ROOT chmod 710 /usr/bin/sudo /bin/su
chroot $MAIN_ROOT chmod ug+s /usr/bin/sudo /bin/su
KERNEL=`find $MAIN_ROOT/boot/ -type f -name "vmlinuz-*"`
SHA=`sha256sum "$KERNEL" | awk '{print $1;}'`
mv "$KERNEL" "$KERNEL-$SHA"
rm -f $MAIN_ROOT/boot/vmlinuz
rm -f $MAIN_ROOT/boot/initrd*
cat <<EOF > $MAIN_ROOT/ostree.conf
d /run/ostree 0755 root root -
f /run/ostree/initramfs-mount-var 0755 root root -
EOF
chroot $MAIN_ROOT dracut --reproducible --gzip -v --no-hostonly \
-f /boot/initramfs-$SHA \
--add ignition --add ostree \
--include /ostree.conf /etc/tmpfiles.d/ostree.conf \
--include /etc/systemd/network/eth0.network /etc/systemd/network/eth0.network \
--omit-drivers=floppy --omit=nfs --omit=lvm --omit=iscsi \
--kver `ls $MAIN_ROOT/lib/modules`
rm -f $MAIN_ROOT/ostree.conf
rm -rf $MAIN_ROOT/usr/etc
mv $MAIN_ROOT/etc $MAIN_ROOT/usr/etc
tar -cJf var.tar.xz -C $MAIN_ROOT var
rm -rf $MAIN_ROOT/var/*
#Создание главного ostree-репозитория и коммита в нем
ostree init --repo=$MAIN_REPO --mode=archive
ostree commit --repo=$MAIN_REPO --tree=dir=$MAIN_ROOT -b $BRANCH \
--no-xattrs --no-bindings --parent=none --mode-ro-executables \
--add-metadata-string=version=sisyphus.`date +%Y%m%d`.0.0
mkdir $ACOS_ROOT
ostree admin init-fs --modern $ACOS_ROOT
ostree pull-local --repo $ACOS_ROOT/ostree/repo $MAIN_REPO $BRANCH
tar -cJf acos_root.tar.xz -C $ACOS_ROOT `ls $ACOS_ROOT`
#rm -rf root repo var.tar.xz acos_root acos_root.tar.xz