Theo Chatzimichos d05fd1
#!/bin/bash
Theo Chatzimichos d05fd1
Theo Chatzimichos d05fd1
# Prepares the CI runner environment to run the show_highstate tests
Theo Chatzimichos d05fd1
Theo Chatzimichos dcff80
set -e
Theo Chatzimichos dcff80
Theo Chatzimichos dcff80
if [[ $(whoami) != 'root' ]]; then
Theo Chatzimichos dcff80
    if [[ -f /usr/bin/sudo ]]; then
a5a5f7
        SUDO='/usr/bin/sudo'
a5a5f7
    else
a5a5f7
        echo 'Please install sudo first, or run this script as root'
a5a5f7
        exit 1
a5a5f7
    fi
Theo Chatzimichos dcff80
fi
Theo Chatzimichos dcff80
fa45db
help() {
fa45db
    echo "Prepares the CI runner or workstation environment to run the show_highstate tests"
fa45db
    echo
fa45db
    echo "Arguments:"
fa45db
    echo
fa45db
    echo "-s    Strip out secrets files (CI runner can't read them)"
fa45db
    echo
fa45db
}
fa45db
fa45db
[[ $1 == '--help' ]] && help && exit
fa45db
fa45db
while getopts sh arg; do
fa45db
    case ${arg} in
fa45db
        s) STRIP_SECRETS=1 ;;
fa45db
        h) help && exit ;;
fa45db
        *) help && exit 1 ;;
fa45db
    esac
fa45db
done
fa45db
Theo Chatzimichos dcff80
$SUDO zypper -qn in --no-recommends salt git python3 python3-PyYAML
Theo Chatzimichos dcff80
$SUDO rm -rf /srv/{salt,pillar}
Theo Chatzimichos dcff80
$SUDO ln -s $PWD/salt /srv/salt
Theo Chatzimichos dcff80
$SUDO ln -s $PWD/pillar /srv/pillar
d86aca
ID=$(hostname -f)
Theo Chatzimichos d05fd1
ROLES=$(bin/get_roles.py --yaml)
d86aca
printf "city:\ncountry:\ndomain: infra.opensuse.org\nosfullname:\nosmajorrelease:\nosrelease_info:\n$ROLES\nsalt_cluster: opensuse\nvirt_cluster:" | $SUDO tee /etc/salt/grains > /dev/null
d86aca
sed -i -e 's/^production:$/base:/' /srv/{salt,pillar}/top.sls
d86aca
touch pillar/id/${ID//./_}.sls
fa45db
[[ -n $STRIP_SECRETS ]] && sed -i -e "s#\- secrets\..*#- id.${ID//./_}#g" $(grep -lr "\- secrets\." pillar)