#!/bin/sh # config-update: updates existing /etc/mock configs # and creates yum_cache/dnf_cache symlinks where necessary # Determine where the yum_cache directory should be symlinked to # Special-case EPEL-9 for now until Rocky 9 is out buildroot_to_baseos () { local buildroot="$1" local baseos=$(echo $buildroot | sed 's/^epel-9-/rhel-9-/; s/^epel-\([0-9]*\)-\([a-z_0-9]*\)$/rocky-\1-\2/') local newbaseos while [ ! -d /var/cache/mock/base-$baseos ]; do if [ -d /var/cache/mock/base-$(echo $baseos | sed s/i586/i386/) ]; then # special case for virtensys-centos-5-i586 => base-centos-5-i386 baseos=$(echo $baseos | sed s/i586/i386/) continue fi if [ -d /var/cache/mock/base-$(echo $baseos | sed s/i386/i586/) ]; then baseos=$(echo $baseos | sed s/i386/i586/) continue fi if [ -d /var/cache/mock/base-$(echo $baseos | sed s/i386/i686/) ]; then baseos=$(echo $baseos | sed s/i386/i686/) continue fi newbaseos=$(echo $baseos | sed 's/^[^-]*-//') if [ "$newbaseos" = "$baseos" ]; then echo "config-update: cannot determine base cache directory for $buildroot" 1>&2 exit 1 fi baseos=$newbaseos done echo $baseos } # Mock sudo whilst testing #sudo () { # echo 'SUDO>>> ' "$@" #} for config in *.cfg do # If no existing config, install it if [ ! -f /etc/mock/$config ]; then echo sudo cp $config /etc/mock/ sudo cp $config /etc/mock/ # If existing config is different, update it elif ! cmp -s $config /etc/mock/$config; then echo sudo cp $config /etc/mock/ sudo cp $config /etc/mock/ fi done for config in base-*.cfg do buildroot=$(grep -F "config_opts['root']" $config | tr -d "'" | awk '{ print $NF }') # Branched configs should be symlinked to the appropriate fedora config case $buildroot in *-branched-*) # Determine Fedora release number to symlink to branched_rel=$(sed -e '/^config_opts\[.dist.\]/!d; s/.*fc\([0-9]*\).*/\1/' $config) real_buildroot=$(echo $buildroot | sed -e "s/-branched-/-fedora-${branched_rel}-/") # If original buildroot exists as a directory, move it out of the way if [ ! -h /var/cache/mock/$buildroot -a -d /var/cache/mock/$buildroot ]; then echo sudo mv /var/cache/mock/${buildroot} /var/cache/mock/${buildroot}.DELETE-ME sudo mv /var/cache/mock/${buildroot} /var/cache/mock/${buildroot}.DELETE-ME fi # If there's an existing symlink, make sure it points to the right place if [ -h /var/cache/mock/$buildroot ]; then existing_cachedir=$(readlink /var/cache/mock/$buildroot) if [ "$existing_cachedir" != "$real_buildroot" ]; then echo sudo rm /var/cache/mock/$buildroot sudo rm /var/cache/mock/$buildroot fi fi # If there's no existing symlink, add it if [ ! -h /var/cache/mock/$buildroot ]; then echo sudo ln -s $real_buildroot /var/cache/mock/$buildroot sudo ln -s $real_buildroot /var/cache/mock/$buildroot fi # Now check that the real buildroot is OK buildroot=$real_buildroot ;; esac # All configs should have a real cache directory if [ ! -d /var/cache/mock/$buildroot ]; then echo sudo mkdir /var/cache/mock/$buildroot sudo mkdir /var/cache/mock/$buildroot fi # Cache directory should be group mock if [ "$(stat -c '%G' /var/cache/mock/$buildroot 2>/dev/null)" != "mock" ]; then echo sudo chgrp mock /var/cache/mock/$buildroot sudo chgrp mock /var/cache/mock/$buildroot fi # Permissions should be 2775 if [ "$(stat -c '%A' /var/cache/mock/$buildroot 2>/dev/null)" != "drwxrwsr-x" ]; then echo sudo chmod 2775 /var/cache/mock/$buildroot sudo chmod 2775 /var/cache/mock/$buildroot fi # Most configs should have a real bootstrap cache directory bootstrap_buildroot=${buildroot}-bootstrap if grep -Fx "config_opts['use_bootstrap'] = False" $config &>/dev/null; then if [ -d /var/cache/mock/$bootstrap_buildroot ]; then echo "config-update: spurious bootstrap cache directory: /var/cache/mock/$bootstrap_buildroot - please remove" 1>&2 exit 1 fi else if [ ! -d /var/cache/mock/$bootstrap_buildroot ]; then echo sudo mkdir /var/cache/mock/$bootstrap_buildroot sudo mkdir /var/cache/mock/$bootstrap_buildroot fi if [ "$(stat -c '%G' /var/cache/mock/$bootstrap_buildroot 2>/dev/null)" != "mock" ]; then echo sudo chgrp mock /var/cache/mock/$bootstrap_buildroot sudo chgrp mock /var/cache/mock/$bootstrap_buildroot fi if [ "$(stat -c '%A' /var/cache/mock/$bootstrap_buildroot 2>/dev/null)" != "drwxrwsr-x" ]; then echo sudo chmod 2775 /var/cache/mock/$bootstrap_buildroot sudo chmod 2775 /var/cache/mock/$bootstrap_buildroot fi fi # Base configs should have real yum_cache directories if [ ! -d /var/cache/mock/$buildroot/yum_cache ]; then echo sudo mkdir /var/cache/mock/$buildroot/yum_cache sudo mkdir /var/cache/mock/$buildroot/yum_cache fi if [ ! -d /var/cache/mock/$buildroot/dnf_cache ]; then echo sudo mkdir /var/cache/mock/$buildroot/dnf_cache sudo mkdir /var/cache/mock/$buildroot/dnf_cache fi # Cache directory should be group root if [ "$(stat -c '%G' /var/cache/mock/$buildroot/yum_cache 2>/dev/null)" != "root" ]; then echo sudo chgrp root /var/cache/mock/$buildroot/yum_cache sudo chgrp root /var/cache/mock/$buildroot/yum_cache fi if [ "$(stat -c '%G' /var/cache/mock/$buildroot/dnf_cache 2>/dev/null)" != "root" ]; then echo sudo chgrp root /var/cache/mock/$buildroot/dnf_cache sudo chgrp root /var/cache/mock/$buildroot/dnf_cache fi # Permissions should be 755 if [ "$(stat -c '%A' /var/cache/mock/$buildroot/yum_cache 2>/dev/null)" != "drwxr-xr-x" ]; then echo sudo chmod u=rwx,g=rx,g-s,o=rx /var/cache/mock/$buildroot/yum_cache sudo chmod u=rwx,g=rx,g-s,o=rx /var/cache/mock/$buildroot/yum_cache fi if [ "$(stat -c '%A' /var/cache/mock/$buildroot/dnf_cache 2>/dev/null)" != "drwxr-xr-x" ]; then echo sudo chmod u=rwx,g=rx,g-s,o=rx /var/cache/mock/$buildroot/dnf_cache sudo chmod u=rwx,g=rx,g-s,o=rx /var/cache/mock/$buildroot/dnf_cache fi done for config in *.cfg do # A base config should have a real cache directory already if echo $config | grep ^base- &> /dev/null; then continue fi buildroot=$(grep -F "config_opts['root']" $config | tr -d "'" | awk '{ print $NF }') # Skip configs that include templates (upstream mock configs, not ours) grep --silent '^include.*\.tpl' $config && continue # Branched configs should be symlinked to the appropriate fedora config case $buildroot in *-branched-*) # Determine Fedora release number to symlink to branched_rel=$(sed -e '/^config_opts\[.dist.\]/!d; s/.*fc\([0-9]*\).*/\1/' $config) real_buildroot=$(echo $buildroot | sed -e "s/-branched-/-fedora-${branched_rel}-/") # If original buildroot exists as a directory, move it out of the way if [ ! -h /var/cache/mock/$buildroot -a -d /var/cache/mock/$buildroot ]; then echo sudo mv /var/cache/mock/${buildroot} /var/cache/mock/${buildroot}.DELETE-ME sudo mv /var/cache/mock/${buildroot} /var/cache/mock/${buildroot}.DELETE-ME fi # If there's an existing symlink, make sure it points to the right place if [ -h /var/cache/mock/$buildroot ]; then existing_cachedir=$(readlink /var/cache/mock/$buildroot) if [ "$existing_cachedir" != "$real_buildroot" ]; then echo sudo rm /var/cache/mock/$buildroot sudo rm /var/cache/mock/$buildroot fi fi # If there's no existing symlink, add it if [ ! -h /var/cache/mock/$buildroot ]; then echo sudo ln -s $real_buildroot /var/cache/mock/$buildroot sudo ln -s $real_buildroot /var/cache/mock/$buildroot fi # Now check that the real buildroot is OK buildroot=$real_buildroot ;; esac # All configs should have a real cache directory if [ ! -d /var/cache/mock/$buildroot ]; then echo sudo mkdir /var/cache/mock/$buildroot sudo mkdir /var/cache/mock/$buildroot fi # Cache directory should be group mock if [ "$(stat -c '%G' /var/cache/mock/$buildroot 2>/dev/null)" != "mock" ]; then echo sudo chgrp mock /var/cache/mock/$buildroot sudo chgrp mock /var/cache/mock/$buildroot fi # Permissions should be 2775 if [ "$(stat -c '%A' /var/cache/mock/$buildroot 2>/dev/null)" != "drwxrwsr-x" ]; then echo sudo chmod 2775 /var/cache/mock/$buildroot sudo chmod 2775 /var/cache/mock/$buildroot fi # Non-base configs must not have real yum_cache directories if [ -d /var/cache/mock/$buildroot/yum_cache -a ! -h /var/cache/mock/$buildroot/yum_cache ]; then echo "config-update: buildroot $buildroot has real yum_cache - please merge into base config" 1>&2 exit 1 fi if [ -d /var/cache/mock/$buildroot/dnf_cache -a ! -h /var/cache/mock/$buildroot/dnf_cache ]; then echo "config-update: buildroot $buildroot has real dnf_cache - please merge into base config" 1>&2 exit 1 fi # Determine where the yum_cache directory should be symlinked to baseos=$(echo $buildroot | sed 's/^[^-]-//') while [ ! -d /var/cache/mock/base-$baseos ]; do if [ -d /var/cache/mock/base-$(echo $baseos | sed s/i586/i386/) ]; then # special case for virtensys-centos-5-i586 => base-centos-5-i386 baseos=$(echo $baseos | sed s/i586/i386/) continue fi newbaseos=$(echo $baseos | sed 's/^[^-]*-//') if [ "$newbaseos" = "$baseos" ]; then echo "config-update: cannot determine base cache directory for $buildroot" 1>&2 exit 1 fi baseos=$newbaseos done base_dnf_cachedir="../base-$baseos/dnf_cache" base_yum_cachedir="../base-$baseos/yum_cache" # If there's an existing symlink, make sure it points to the right place if [ -h /var/cache/mock/$buildroot/yum_cache ]; then existing_cachedir=$(readlink /var/cache/mock/$buildroot/yum_cache) if [ "$existing_cachedir" != "$base_yum_cachedir" ]; then echo sudo rm /var/cache/mock/$buildroot/yum_cache sudo rm /var/cache/mock/$buildroot/yum_cache fi fi if [ -h /var/cache/mock/$buildroot/dnf_cache ]; then existing_cachedir=$(readlink /var/cache/mock/$buildroot/dnf_cache) if [ "$existing_cachedir" != "$base_dnf_cachedir" ]; then echo sudo rm /var/cache/mock/$buildroot/dnf_cache sudo rm /var/cache/mock/$buildroot/dnf_cache fi fi # If there's no existing symlink, add it if [ ! -h /var/cache/mock/$buildroot/yum_cache ]; then echo sudo ln -s $base_yum_cachedir /var/cache/mock/$buildroot/yum_cache sudo ln -s $base_yum_cachedir /var/cache/mock/$buildroot/yum_cache fi if [ ! -h /var/cache/mock/$buildroot/dnf_cache ]; then echo sudo ln -s $base_dnf_cachedir /var/cache/mock/$buildroot/dnf_cache sudo ln -s $base_dnf_cachedir /var/cache/mock/$buildroot/dnf_cache fi # Most configs should have a real bootstrap cache directory bootstrap_buildroot=${buildroot}-bootstrap if grep -Fx "config_opts['use_bootstrap'] = False" $config &>/dev/null; then if [ -d /var/cache/mock/$bootstrap_buildroot ]; then echo "config-update: spurious bootstrap cache directory: /var/cache/mock/$bootstrap_buildroot - please remove" 1>&2 exit 1 fi else if [ ! -d /var/cache/mock/$bootstrap_buildroot ]; then echo sudo mkdir /var/cache/mock/$bootstrap_buildroot sudo mkdir /var/cache/mock/$bootstrap_buildroot fi if [ "$(stat -c '%G' /var/cache/mock/$bootstrap_buildroot 2>/dev/null)" != "mock" ]; then echo sudo chgrp mock /var/cache/mock/$bootstrap_buildroot sudo chgrp mock /var/cache/mock/$bootstrap_buildroot fi if [ "$(stat -c '%A' /var/cache/mock/$bootstrap_buildroot 2>/dev/null)" != "drwxrwsr-x" ]; then echo sudo chmod 2775 /var/cache/mock/$bootstrap_buildroot sudo chmod 2775 /var/cache/mock/$bootstrap_buildroot fi fi done # Now check that all configs in /etc/mock have valid cache directories # This will pick up the standard configs for config in /etc/mock/*.cfg do # A base config should have a real cache directory already if basename $config | grep ^base- &> /dev/null; then continue fi # site-defaults isn't a buildable configuration [ $config = /etc/mock/site-defaults.cfg ] && continue # Neither is chroot-aliases.cfg [ $config = /etc/mock/chroot-aliases.cfg ] && continue # Don't do anything with "alma+epel" targets if basename $config | grep ^alma+epel &> /dev/null; then continue fi # Don't do anything with "circlelinux+epel" targets if basename $config | grep ^circlelinux+epel &> /dev/null; then continue fi # Don't do anything with "rhel+epel" targets if basename $config | grep ^rhel+epel &> /dev/null; then continue fi # Don't do anything with "rocky+epel" targets if basename $config | grep ^rocky+epel &> /dev/null; then continue fi # Don't do anything with "amzn-" targets if basename $config | grep ^amzn- &> /dev/null; then continue fi # Don't do anything with "custom" targets if basename $config | grep ^custom- &> /dev/null; then continue fi # Don't do anything with "hermetic" targets if basename $config | grep ^hermetic- &> /dev/null; then continue fi # Don't do anything with "mageia" targets if basename $config | grep ^mageia- &> /dev/null; then continue fi # Don't do anything with "openmandriva" targets if basename $config | grep ^openmandriva- &> /dev/null; then continue fi # Don't do anything with "rhelbeta" targets (from mock-core-configs) if basename $config | grep -E '^(rhelepel|rhelbeta)-' &> /dev/null; then continue fi # Don't do anything with "opensuse" targets if basename $config | grep ^opensuse- &> /dev/null; then continue fi # Skip RPM Fusion upstream mock configs; we use our own if basename $config | grep rpmfusion_ &> /dev/null; then continue fi # Skip arches we can't build for target_arch=$(grep -F "config_opts['target_arch']" $config | tr -d "'\r" | awk '{ print $NF }') case "$target_arch" in aarch64|armv5tel|armv7hl|ppc|ppc64|ppc64le|s390|s390x|sparcv9|sparc64) continue ;; "") echo "Skipping broken config $config (no target_arch)" 1>&2 continue ;; *) ;; esac # Determine config's buildroot buildroot=$(grep -F "config_opts['root']" $config | tr -d "'" | awk '{ print $NF }') # Skip configs that include templates (upstream mock configs, not ours) grep --silent '^include.*\.tpl' $config && continue # A branched config will have been symlinked already case $buildroot in *-branched-*) continue ;; esac # All configs should have a real cache directory if [ ! -d /var/cache/mock/$buildroot ]; then echo sudo mkdir /var/cache/mock/$buildroot sudo mkdir /var/cache/mock/$buildroot fi # Cache directory should be group mock if [ "$(stat -c '%G' /var/cache/mock/$buildroot 2>/dev/null)" != "mock" ]; then echo sudo chgrp mock /var/cache/mock/$buildroot sudo chgrp mock /var/cache/mock/$buildroot fi # Permissions should be 2775 if [ "$(stat -c '%A' /var/cache/mock/$buildroot 2>/dev/null)" != "drwxrwsr-x" ]; then echo sudo chmod 2775 /var/cache/mock/$buildroot sudo chmod 2775 /var/cache/mock/$buildroot fi # Non-base configs must not have real yum_cache directories if [ -d /var/cache/mock/$buildroot/yum_cache -a ! -h /var/cache/mock/$buildroot/yum_cache ]; then echo "config-update: buildroot $buildroot has real yum_cache - please merge into base config" 1>&2 exit 1 fi if [ -d /var/cache/mock/$buildroot/dnf_cache -a ! -h /var/cache/mock/$buildroot/dnf_cache ]; then echo "config-update: buildroot $buildroot has real dnf_cache - please merge into base config" 1>&2 exit 1 fi # Determine where the yum_cache directory should be symlinked to baseos=$(buildroot_to_baseos $buildroot) base_dnf_cachedir="../base-$baseos/dnf_cache" base_yum_cachedir="../base-$baseos/yum_cache" # If there's an existing symlink, make sure it points to the right place if [ -h /var/cache/mock/$buildroot/yum_cache ]; then existing_cachedir=$(readlink /var/cache/mock/$buildroot/yum_cache) if [ "$existing_cachedir" != "$base_yum_cachedir" ]; then echo sudo rm /var/cache/mock/$buildroot/yum_cache sudo rm /var/cache/mock/$buildroot/yum_cache fi fi if [ -h /var/cache/mock/$buildroot/dnf_cache ]; then existing_cachedir=$(readlink /var/cache/mock/$buildroot/dnf_cache) if [ "$existing_cachedir" != "$base_dnf_cachedir" ]; then echo sudo rm /var/cache/mock/$buildroot/dnf_cache sudo rm /var/cache/mock/$buildroot/dnf_cache fi fi # If there's no existing symlink, add it if [ ! -h /var/cache/mock/$buildroot/yum_cache ]; then echo sudo ln -s $base_yum_cachedir /var/cache/mock/$buildroot/yum_cache sudo ln -s $base_yum_cachedir /var/cache/mock/$buildroot/yum_cache fi if [ ! -h /var/cache/mock/$buildroot/dnf_cache ]; then echo sudo ln -s $base_dnf_cachedir /var/cache/mock/$buildroot/dnf_cache sudo ln -s $base_dnf_cachedir /var/cache/mock/$buildroot/dnf_cache fi done # All bootstrap cache directories should have symlinked dnf and yum caches, to their respective base caches for cachedir in /var/cache/mock/*-bootstrap do bootstrap_buildroot=$(basename $cachedir) buildroot=$(echo $bootstrap_buildroot | sed -e 's|-bootstrap$||') baseos=$(buildroot_to_baseos $buildroot) base_dnf_cachedir="../base-$baseos/dnf_cache" base_yum_cachedir="../base-$baseos/yum_cache" # bootstrap caches must not have real yum_cache directories if [ -d /var/cache/mock/$bootstrap_buildroot/yum_cache -a ! -h /var/cache/mock/$bootstrap_buildroot/yum_cache ]; then echo "config-update: buildroot $bootstrap_buildroot has real yum_cache - please merge into base config" 1>&2 exit 1 fi if [ -d /var/cache/mock/$bootstrap_buildroot/dnf_cache -a ! -h /var/cache/mock/$bootstrap_buildroot/dnf_cache ]; then echo "config-update: buildroot $bootstrap_buildroot has real dnf_cache - please merge into base config" 1>&2 exit 1 fi # If there's an existing symlink, make sure it points to the right place if [ -h /var/cache/mock/$bootstrap_buildroot/yum_cache ]; then existing_cachedir=$(readlink /var/cache/mock/$bootstrap_buildroot/yum_cache) if [ "$existing_cachedir" != "$base_yum_cachedir" ]; then echo sudo rm /var/cache/mock/$bootstrap_buildroot/yum_cache sudo rm /var/cache/mock/$bootstrap_buildroot/yum_cache fi fi if [ -h /var/cache/mock/$bootstrap_buildroot/dnf_cache ]; then existing_cachedir=$(readlink /var/cache/mock/$bootstrap_buildroot/dnf_cache) if [ "$existing_cachedir" != "$base_dnf_cachedir" ]; then echo sudo rm /var/cache/mock/$bootstrap_buildroot/dnf_cache sudo rm /var/cache/mock/$bootstrap_buildroot/dnf_cache fi fi # If there's no existing symlink, add it if [ ! -h /var/cache/mock/$bootstrap_buildroot/yum_cache ]; then echo sudo ln -s $base_yum_cachedir /var/cache/mock/$bootstrap_buildroot/yum_cache sudo ln -s $base_yum_cachedir /var/cache/mock/$bootstrap_buildroot/yum_cache fi if [ ! -h /var/cache/mock/$bootstrap_buildroot/dnf_cache ]; then echo sudo ln -s $base_dnf_cachedir /var/cache/mock/$bootstrap_buildroot/dnf_cache sudo ln -s $base_dnf_cachedir /var/cache/mock/$bootstrap_buildroot/dnf_cache fi done