|
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 |
f6d741 |
echo "-s Strip out secrets files (CI runner can't read them)"
|
|
 |
fa45db |
echo
|
|
 |
fa45db |
}
|
|
 |
fa45db |
|
|
 |
fa45db |
[[ $1 == '--help' ]] && help && exit
|
|
 |
fa45db |
|
|
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 ;;
|
|
 |
fa45db |
s) STRIP_SECRETS=1 ;;
|
|
 |
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 |
a452cb |
$SUDO zypper -qn in --no-recommends salt ${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 |
a452cb |
printf "city:\ncountry:\ndomain: infra.opensuse.org\nosfullname:\nosmajorrelease:\nosrelease_info:\n$ROLES\nsalt_cluster: opensuse\nvirt_cluster:\nvirtual:\n" > /etc/salt/grains
|
|
Theo Chatzimichos |
a452cb |
if [[ -n $STRIP_SECRETS ]]; then
|
|
Theo Chatzimichos |
a452cb |
SECRETS=$(grep -lr "\- secrets\." pillar)
|
|
Theo Chatzimichos |
a452cb |
[[ -n $SECRETS ]] && sed -i -e "s#\- secrets\..*#- id.${ID//./_}#g" $SECRETS
|
|
Theo Chatzimichos |
a452cb |
fi
|
|
Theo Chatzimichos |
818e20 |
fi
|