Files
runner/scripts/remove-svc.sh
T

68 lines
1.9 KiB
Bash
Raw Normal View History

2020-04-15 09:51:53 -04:00
#
# Removes a runner running as a service
# Must be run on the machine where the service is run
#
# Examples:
# RUNNER_CFG_PAT=<yourPAT> ./remove-svc.sh myuser/myrepo
# RUNNER_CFG_PAT=<yourPAT> ./remove-svc.sh myorg
#
# Usage:
# export RUNNER_CFG_PAT=<yourPAT>
# ./remove-svc scope name
#
# scope required repo (:owner/:repo) or org (:organization)
# name optional defaults to hostname. name to uninstall and remove
#
# Notes:
# PATS over envvars are more secure
# Should be used on VMs and not containers
# Works on OSX and Linux
# Assumes x64 arch
#
runner_scope=${1}
runner_name=${2:-$(hostname)}
echo "Uninstalling runner ${runner_name} @ ${runner_scope}"
sudo echo
2020-04-15 11:35:52 -04:00
function fatal()
{
echo "error: $1" >&2
exit 1
}
2020-04-15 09:51:53 -04:00
2020-04-15 11:35:52 -04:00
if [ -z "${runner_scope}" ]; then fatal "supply scope as argument 1"; fi
if [ -z "${RUNNER_CFG_PAT}" ]; then fatal "RUNNER_CFG_PAT must be set before calling"; fi
2020-04-15 09:51:53 -04:00
2020-04-15 13:51:34 -04:00
which curl || fatal "curl required. Please install in PATH with apt-get, brew, etc"
which jq || fatal "jq required. Please install in PATH with apt-get, brew, etc"
2020-04-15 12:35:17 -04:00
#--------------------------------------
# Get a remove token
#--------------------------------------
2020-04-15 09:51:53 -04:00
echo
2020-04-15 12:35:17 -04:00
echo "Generating a registration token..."
2020-04-15 09:51:53 -04:00
2020-04-15 12:35:17 -04:00
# if the scope has a slash, it's an repo runner
2020-04-15 09:51:53 -04:00
base_api_url="https://api.github.com/orgs"
if [[ "$runner_scope" == *\/* ]]; then
base_api_url="https://api.github.com/repos"
fi
2020-04-15 12:35:17 -04:00
export REMOVE_TOKEN=$(curl -s -X POST ${base_api_url}/${runner_scope}/actions/runners/remove-token -H "accept: application/vnd.github.everest-preview+json" -H "authorization: token ${RUNNER_CFG_PAT}" | jq -r '.token')
2020-04-15 09:51:53 -04:00
2020-04-15 12:35:17 -04:00
if [ -z "$REMOVE_TOKEN" ]; then fatal "Failed to get a token"; fi
2020-04-15 09:51:53 -04:00
2020-04-15 12:35:17 -04:00
echo $REMOVE_TOKEN
2020-04-15 09:51:53 -04:00
2020-04-15 12:35:17 -04:00
#---------------------------------------
# Stop and uninstall the service
#---------------------------------------
echo
echo "Uninstall the service ..."
pushd ./runner
./svc.sh stop
./svc.sh uninstall
./config.sh remove --token $REMOVE_TOKEN