Skip to content

Commit

Permalink
[gh-setup] new target
Browse files Browse the repository at this point in the history
  • Loading branch information
MatthijsBurgh committed Mar 1, 2024
1 parent af2197b commit ca8e72b
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 0 deletions.
55 changes: 55 additions & 0 deletions gh-setup/install.bash
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
arch="$(dpkg --print-architecture)"

key_file="/usr/share/keyrings/githubcli-archive-keyring.gpg"
key_folder=$(dirname ${key_file})
key_fingerprint="23F3D4EA75716059"
key_needs_to_be_added="false"
key_url="https://cli.github.com/packages/githubcli-archive-keyring.gpg"

source_file="/etc/apt/sources.list.d/github-cli.list"
source_needs_to_be_added="false"
source_url="deb [arch=${arch} signed-by=${key_file}] https://cli.github.com/packages stable main"

if [[ -z "${arch}" ]]
then
tue-install-warning "Could not retrieve the system architecture, so not installing package."
else
# Add stable docker repository source
if [[ ! -f "${key_file}" ]]
then
tue-install-debug "Keyring '${key_file}' doesn't exist yet."
key_needs_to_be_added=true
elif ! gpg --show-keys "${key_file}" | grep -q "${key_fingerprint}" &> /dev/null
then
tue-install-debug "Keyring '${key_file}' doesn't match the fingerprint '${key_fingerprint}'."
key_needs_to_be_added=true
fi

if [[ "${key_needs_to_be_added}" == "true" ]]
then
tue-install-debug "Make sure '${key_folder}' folder exists with the correct permissions."
tue-install-pipe sudo install -m 0755 -d "${key_folder}"
tue-install-debug "Downloading gpg key of GH repo with fingerprint '${key_fingerprint}'."
curl -fsSL ${key_url} | sudo gpg --dearmor --yes -o "${key_file}"
else
tue-install-debug "GPG key of GH repo with fingerprint '${key_fingerprint}' already exists, so not installing it."
fi

if [[ ! -f "${source_file}" ]]
then
tue-install-debug "Adding GH sources to apt-get"
source_needs_to_be_added=true
elif [[ $(cat "${source_file}") != "${source_url}" ]]
then
tue-install-debug "Updating GH sources to apt-get"
source_needs_to_be_added=true
else
tue-install-debug "GH sources already added to apt-get"
fi

if [[ "${source_needs_to_be_added}" == "true" ]]
then
echo "${source_url}" | sudo tee ${source_file} > /dev/null
tue-install-apt-get-update
fi
fi
2 changes: 2 additions & 0 deletions gh-setup/install.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- type: system-now
name: curl

0 comments on commit ca8e72b

Please sign in to comment.