Theo Chatzimichos d05fd1
#!/bin/bash
Theo Chatzimichos d05fd1
Theo Chatzimichos f6d741
# See the description at the help()
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() {
Theo Chatzimichos f6d741
    echo "Prepares the CI runner or workstation environment to run highstate or show_highstate tests"
fa45db
    echo
fa45db
    echo "Arguments:"
fa45db
    echo
Theo Chatzimichos f6d741
    echo "-p <pkg1,pkg2> Comma-separated list of additional packages to be installed"
Theo Chatzimichos a452cb
    echo "-g             Make preparation for show_highstate"
Theo Chatzimichos 754b1a
    echo "-s             Include secrets files (disabed because CI runner can't decrypt them due to lack of GPG key)"
fa45db
    echo
fa45db
}
fa45db
fa45db
[[ $1 == '--help' ]] && help && exit
fa45db
Theo Chatzimichos 754b1a
SECRETS="False"
Theo Chatzimichos 754b1a
Theo Chatzimichos a452cb
while getopts p:gsh arg; do
fa45db
    case ${arg} in
Theo Chatzimichos f6d741
        p) PKG=(${OPTARG//,/ }) ;;
Theo Chatzimichos a452cb
        g) HIGHSTATE=1 ;;
Theo Chatzimichos 754b1a
        s) SECRETS="True" ;;
fa45db
        h) help && exit ;;
fa45db
        *) help && exit 1 ;;
fa45db
    esac
fa45db
done
fa45db
Theo Chatzimichos a452cb
[[ -n $HIGHSTATE ]] && HIGHSTATE_PKGS=( git python3-PyYAML )
Theo Chatzimichos a452cb
Theo Chatzimichos 042b5b
$SUDO zypper -qn in --no-recommends salt python3-pygit2 ca-certificates-freeipa-opensuse ${HIGHSTATE_PKGS[@]} ${PKG[@]}
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 e0ba5d
printf "grains:\n  city: nuremberg\n  country: de\n  hostusage: test\n  salt_cluster: opensuse\n  virt_cluster: atreju\n" > pillar/id/${ID//./_}.sls
Theo Chatzimichos a452cb
if [[ -n $HIGHSTATE ]]; then
Theo Chatzimichos a452cb
    ROLES=$(bin/get_roles.py -o yaml)
Theo Chatzimichos 754b1a
    printf "city:\ncountry:\ndomain: infra.opensuse.org\ninclude_secrets: $SECRETS\nosfullname:\nosmajorrelease:\nosrelease_info:\n$ROLES\nsalt_cluster: opensuse\nvirt_cluster:\nvirtual:\n" > /etc/salt/grains
Theo Chatzimichos 818e20
fi