diff --git a/scripts/create-latest-svc.sh b/scripts/create-latest-svc.sh index d7cf3b537..17da08bff 100755 --- a/scripts/create-latest-svc.sh +++ b/scripts/create-latest-svc.sh @@ -128,5 +128,3 @@ echo echo "Configuring as a service ..." ./svc.sh install ${svc_user} ./svc.sh start - - diff --git a/scripts/remove-svc.sh b/scripts/remove-svc.sh index 3ecc24965..bd8127f10 100755 --- a/scripts/remove-svc.sh +++ b/scripts/remove-svc.sh @@ -26,36 +26,43 @@ runner_name=${2:-$(hostname)} echo "Uninstalling runner ${runner_name} @ ${runner_scope}" sudo echo +function fatal() +{ + echo "error: $1" >&2 + exit 1 +} +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 #--------------------------------------- # Stop and uninstall the service #--------------------------------------- echo echo "Uninstall the service ..." +pushd ./runner ./svc.sh stop ./svc.sh uninstall -#-------------------------------------- -# Get a removal token -#-------------------------------------- -echo -echo "Generating a removal registration token..." - -# if the scope has a slash, it's an repo runner base_api_url="https://api.github.com/orgs" if [[ "$runner_scope" == *\/* ]]; then base_api_url="https://api.github.com/repos" fi -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') +#-------------------------------------- +# Get id of runner to remove +#-------------------------------------- +runner_id=$(curl -s -X GET ${base_api_url}/${runner_scope}/actions/runners -H "accept: application/vnd.github.everest-preview+json" -H "authorization: token ${RUNNER_CFG_PAT}" | jq -M -j ".runners | .[] | [select(.name == \"${runner_name}\")] | .[0].id") -if [ -z "$REMOVE_TOKEN" ]; then fatal "Failed to get a token"; fi +if [ -z "${runner_id}" ]; then + fatal "Could not find runner with name ${runner_name}" +fi + +echo "Removing id ${runner_id}" #-------------------------------------- # Remove the runner #-------------------------------------- -# DELETE /orgs/:organization/actions/runners/:runner_id -curl -s -X DELETE ${base_api_url}/${runner_scope}/actions/runners/remove-token -H "authorization: token ${REMOVE_TOKEN}" +curl -s -X DELETE ${base_api_url}/${runner_scope}/actions/runners/${runner_id} -H "authorization: token ${RUNNER_CFG_PAT}" echo "Done."