#!/usr/bin/env bash

apt install -y curl apt-transport-https gnupg 

OS=debian
DIST=stretch
GPG_KEY_URL="https://packages.gitlab.com/runner/gitlab-runner/gpgkey"

cat > /etc/apt/sources.list-available/runner_gitlab-runner.list <<EOF
deb https://packages.gitlab.com/runner/gitlab-runner/${OS}/ ${DIST} main
deb-src https://packages.gitlab.com/runner/gitlab-runner/${OS}/ ${DIST} main
EOF

cat <<EOF | sudo tee /etc/apt/preferences.d/pin-gitlab-runner.pref
Explanation: Prefer GitLab provided packages over the Debian native ones
Package: gitlab-runner
Pin: origin packages.gitlab.com
Pin-Priority: 1001
EOF


ln -s /etc/apt/sources.list-available/runner_gitlab-runner.list /etc/apt/sources.list.d/runner_gitlab-runner.list

curl -L "${GPG_KEY_URL}" 2> /dev/null | apt-key add - &>/dev/null

apt update

apt install -y gitlab-runner
