File mkrootfs.sh of Package altimagebuild

#!/bin/sh
# this runs as root to create the root file system
# which includes creating default configs
# 
# by Bernhard M. Wiedemann
# License: MIT

if ! [ `whoami` = root ] ; then
    echo need to run this as root in osc chroot --root
    exit 77
fi
chkstat --set --fscaps /etc/permissions{,.easy} # fix /etc/shadow perms
#zypper ar http://download.opensuse.org/ports/armv6hl/factory/repo/oss/ factory
[ "$sle_version" = 120200 ] && leapv=42.2
[ "$sle_version" = 120300 ] && leapv=42.3
[ "$sle_version" = 150000 ] && leapv=15.0
[ "$sle_version" = 150100 ] && leapv=15.1
[ "$sle_version" = 150200 ] && leapv=15.2
[ "$sle_version" = 150300 ] && leapv=15.3
[ "$sle_version" = 150400 ] && leapv=15.4
[ "$sle_version" = 150500 ] && leapv=15.5
[ "$sle_version" = 150600 ] && leapv=15.6
if [ -n "$leapv" ] ; then
    zypper ar http://download.opensuse.org/distribution/leap/$leapv/repo/oss/ repo-oss
    zypper ar --refresh http://download.opensuse.org/update/leap/$leapv/oss/ repo-update
else
    zypper ar --refresh http://download.opensuse.org/tumbleweed/repo/oss/ repo-oss
fi
for k in /usr/lib/rpm/gnupg/keys/*.asc ; do rpmkeys --import $k ; done
systemctl enable getty@tty1.service
chkconfig sshd on
#chkconfig ntpd on
#chkconfig network on
#mkinitrd

r=/.root
rm -rf $r ; mkdir $r
cp -a /[a-ort-z]* /s[a-xz]* $r
cd $r
mkdir -p dev proc sys ; cd dev
ln -s /proc/self/fd
ln -s fd/0 stdin
ln -s fd/1 stdout
ln -s fd/2 stderr
mknod null c 1 3 || true
mknod zero c 1 5 || true
mknod full c 1 7 || true
mknod random c 1 8 || true
mknod urandom c 1 9 || true
mknod tty1 c 4 1 || true
mknod ttyS0 c 4 64 || true
mknod tty c 5 0 || true
mknod console c 5 1 || true
mknod ptmx c 5 2 || true
for i in $(seq 0 7) ; do
    mknod loop$i b 7 $i || true
done

cd $r
rm -f usr/bin/qemu-*
# fallback without DHCP server
mkdir -p var/lib/dhcpcd
cat >var/lib/dhcpcd/dhcpcd-eth0.info <<EOF
IPADDR='192.168.99.99'
NETMASK='255.255.255.0'
NETWORK='192.168.99.0'
BROADCAST='192.168.99.255'
GATEWAYS='192.168.99.1'
DNSDOMAIN='zq1.de'
DNSSERVERS='192.168.99.1'
INTERFACE='eth0'
EOF

cd $r/etc
ln -fs /proc/self/mounts mtab
cat >fstab <<EOF
LABEL=root /     ext4 noatime  1 1
#LABEL=swap swap  swap defaults
#LABEL=BOOT /boot ext2 defaults 2 1
EOF

echo "STARTMODE=auto
BOOTPROTO=dhcp4" > sysconfig/network/ifcfg-eth0
echo 'LOADER_TYPE="grub2"' > sysconfig/bootloader
echo 'SECURE_BOOT="0"' >> /etc/sysconfig/bootloader
echo -e '(hd0)\t/dev/vda' > /boot/grub2/device.map
echo /dev/vda > /etc/default/grub_installdevice
sed -i -e 's/#\(GRUB_TERMINAL=.*\)/\1/' default/grub
sed -i -e 's/\(GRUB_TIMEOUT\)=.*/\1=3/' default/grub

# set root password to nots3cr3t
sed -i 's,^root:,root:$6$xDh070x658H0KIIx$yAMvQt4U/ioBNg3vupgZH2xJTVswKFO5y/wId.ISohHFs4CmJ1sjGs5WD8K4KcSd3770jOc9Z8mQD9MjKIoP6/,' shadow
echo altimagebuild.opensuse.org > HOSTNAME

grep ^server ntp.conf || cat >>ntp.conf <<EOF
server 2.opensuse.pool.ntp.org iburst
server ntp.zq1.de iburst minpoll 4
EOF

# specific to raspberry:
# have a serial console login:
ln -sf /usr/lib/systemd/system/getty@.service systemd/system/getty.target.wants/getty@ttyS0.service
#echo 'S0:S12345:respawn:/sbin/agetty -L 115200 ttyS0 vt102' >> etc/inittab
ln -s /usr/lib/systemd/system/multi-user.target $r/etc/systemd/system/default.target

#echo blacklist bochs_drm > modprobe.d/51-blacklist-bochs_drm.conf
rm -f $r/lib/modules/*/kernel/drivers/gpu/drm/drm_kms_helper.ko
# for VMs we dont need most hardware drivers
rm -rf $r/lib/modules/*/kernel/{sound,drivers/{gpu,media,staging,usb,infiniband,isdn,hwmon,mtd,hid,target,net/{wireless,usb,irda,can,wan,wimax,fddi}}}

# use framebuffer graphics
mkdir -p X11/xorg.conf.d/
#cat >X11/xorg.conf.d/50-device.conf <<EOF
#Section "Device"
#  Identifier "Default Device"
#  Driver "fbdev"
#EndSection
#EOF

# set default windowmanager - once for startx and once for xdm
echo export WINDOWMANAGER=/usr/bin/icewm > profile.d/windowmanager.sh
sed -i -e 's/DEFAULT_WM=.*/DEFAULT_WM="icewm"/' sysconfig/windowmanager

rpm --root . -e rpm-build glibc-locale

# reduce space usage:
rm -rf $r/usr/share/{doc,man,locale}

cd $r/boot
#echo "dwc_otg.lpm_enable=0 console=ttyAMA0,115200 kgdboc=ttyAMA0,115200 console=tty1 root=/dev/mmcblk0p3 rootfstype=ext2 rootflags= rootwait rw" > cmdline.txt
#echo "disable_overscan=1" > config.txt

# because FAT does not support symlinks, we rather move
#ln -f $(readlink vmlinuz) vmlinuz
#ln -f $(readlink initrd) initrd
mkdir -p extlinux
cd extlinux
cp -a /usr/share/syslinux/*.c32 .
cat > syslinux.cfg <<EOF
PROMPT 1  
TIMEOUT 20
DEFAULT grub

LABEL linux
	LINUX ../vmlinuz
	INITRD ../initrd
	APPEND root=/dev/vda rw nomodeset

LABEL grub
	COM32 chain.c32
	APPEND file=../grub2/i386-pc/core.img seg=0x800::0x200
EOF
openSUSE Build Service is sponsored by