Добавлен скрипт обновления репозитория
This commit is contained in:
parent
70b27adcad
commit
0c427ab773
103
rootfs_to_repo.sh
Executable file
103
rootfs_to_repo.sh
Executable file
@ -0,0 +1,103 @@
|
||||
#!/bin/sh
|
||||
set -e
|
||||
|
||||
if [ -z "$4" ]
|
||||
then
|
||||
echo "Help: $0 <rootfs archive> <directory of main ostree repository> <branch> <output archives directory>"
|
||||
echo "For example: out/acos-20210824-x86_64.tar repo acos/x86_64/sisyphus out"
|
||||
echo "You can change TMPDIR environment variable to set another directory where temporary files will be stored"
|
||||
echo "If directory of main ostree repository doesn't exists, new repository will be created"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ `id -u` -ne 0 ]
|
||||
then
|
||||
echo "ERROR: $0 needs to be run as root (uid=0) only"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
ROOTFS_ARCHIVE=$1
|
||||
MAIN_REPO=$2
|
||||
BRANCH=$3
|
||||
OUT_DIR=$4
|
||||
TMP_DIR=`mktemp --tmpdir -d rootfs_to_repo-XXXXXX`
|
||||
MAIN_ROOT=$TMP_DIR/root
|
||||
ACOS_ROOT=$TMP_DIR/acos_root
|
||||
VAR_ARCH=$OUT_DIR/var.tar.xz
|
||||
ROOT_ARCH=$OUT_DIR/acos_root.tar.xz
|
||||
|
||||
rm -rf $TMP_DIR/* $VAR_ARCH $ROOT_ARCH
|
||||
|
||||
mkdir -p $MAIN_ROOT
|
||||
tar xf $ROOTFS_ARCHIVE -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
|
||||
|
||||
#####################
|
||||
rm -f $MAIN_ROOT/etc/resolv.conf
|
||||
ln -sf /run/systemd/resolve/resolv.conf $MAIN_ROOT/etc/resolv.conf
|
||||
#####################
|
||||
|
||||
#Вынести в 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_ARCH -C $MAIN_ROOT var
|
||||
rm -rf $MAIN_ROOT/var/*
|
||||
|
||||
if [ ! -d $MAIN_REPO ]
|
||||
then
|
||||
#Создание главного ostree-репозитория
|
||||
ostree init --repo=$MAIN_REPO --mode=archive
|
||||
fi
|
||||
|
||||
ostree commit --repo=$MAIN_REPO --tree=dir=$MAIN_ROOT -b $BRANCH \
|
||||
--no-xattrs --no-bindings --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 -cf - -C $ACOS_ROOT `ls $ACOS_ROOT` | xz -9 -c -T0 - > $ROOT_ARCH
|
||||
|
||||
rm -rf $TMP_DIR
|
Loading…
Reference in New Issue
Block a user