Skip to content

Commit

Permalink
Merge pull request #1504 from openziti/linux-install-script
Browse files Browse the repository at this point in the history
add a script for installing OpenZiti packages
  • Loading branch information
qrkourier authored Nov 10, 2023
2 parents e526aba + 54f9b5d commit 308995e
Show file tree
Hide file tree
Showing 2 changed files with 149 additions and 1 deletion.
6 changes: 5 additions & 1 deletion dist/cloudfront/get.openziti.io/routes.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@
- get: /miniziti.bash
raw: /openziti/ziti/{{GITHUB_SHA}}/quickstart/kubernetes/

# Linux package install script for ziti, zrok CLI, and metapackages that are in the main release repo for generic,
# portable Linux packages, not ziti-edge-tunnel
- get: /install.bash
raw: /openziti/ziti/{{GITHUB_SHA}}/dist/dist-packages/linux/

# these are directory shortcuts, so you must supply a test file
- get: /quick/
raw: /openziti/ziti/{{GITHUB_SHA}}/quickstart/docker/image/
Expand All @@ -32,4 +37,3 @@
- get: /zdew/
raw: /openziti/desktop-edge-win/release-next/release-streams/
file: latest.json

144 changes: 144 additions & 0 deletions dist/dist-packages/linux/install.bash
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
#!/usr/bin/env bash

set -o errexit
set -o nounset
set -o pipefail

checkSum() {
for CMD in sha256sum md5sum; do
if command -v $CMD &>/dev/null; then
local SUMCMD=$CMD
break
fi
done
if [ -z "$SUMCMD" ]; then
echo "ERROR: No checksum command found. Tried 'sha256sum', 'md5sum'." >&2
exit 1
fi
$SUMCMD | awk '{print $1}'
}

installRedHat(){

for CMD in dnf yum; do
if command -v $CMD &>/dev/null; then
local PACKAGER=$CMD
break
fi
done
if [ -z "$PACKAGER" ]; then
echo "ERROR: No package manager found. Tried 'dnf', 'yum'." >&2
exit 1
fi

local REPOSRC="[OpenZitiRelease]
name=OpenZiti Release
baseurl=https://packages.openziti.org/${ZITIPAX_RPM:-zitipax-openziti-rpm-stable}/redhat/\$basearch
enabled=1
gpgcheck=0
gpgkey=https://packages.openziti.org/${ZITIPAX_RPM:-zitipax-openziti-rpm-stable}/redhat/\$basearch/repodata/repomd.xml.key
repo_gpgcheck=1"

local REPOFILE="/etc/yum.repos.d/openziti-release.repo"
if [ -s $REPOFILE ]; then
local EXISTINGSUM
local REPOSUM
EXISTINGSUM=$(checkSum < $REPOFILE)
REPOSUM=$(checkSum <<< "$REPOSRC")
if [ "$EXISTINGSUM" != "$REPOSUM" ]; then
mv -v $REPOFILE{,".$(date -Iseconds)"}
echo "$REPOSRC" > $REPOFILE

fi
else
echo "$REPOSRC" >| $REPOFILE

fi

$PACKAGER update --assumeyes
$PACKAGER install --assumeyes "$@"
for PKG in "$@"; do
$PACKAGER info "$PKG"
done
}

installDebian(){

for CMD in gpg gpg2; do
if command -v $CMD &>/dev/null; then
local GNUPGCMD=$CMD
break
fi
done
if [ -z "$GNUPGCMD" ]; then
echo "ERROR: No GnuPG CLI found. Tried 'gpg', gpg2." >&2
exit 1
fi
for CMD in wget curl; do
if command -v $CMD &>/dev/null; then
local GETTER=$CMD
break
fi
done
if [ -z "$GETTER" ]; then
echo "ERROR: No http client found. Tried 'wget', 'curl'." >&2
exit 1
else
case $GETTER in
wget)
GETTERCMD="wget -qO-"
;;
curl)
GETTERCMD="curl -fsSL"
;;
esac
fi

# always update the pubkey
$GETTERCMD https://get.openziti.io/tun/package-repos.gpg \
| $GNUPGCMD --batch --yes --dearmor --output /usr/share/keyrings/openziti.gpg
chmod +r /usr/share/keyrings/openziti.gpg

local REPOSRC="deb [signed-by=/usr/share/keyrings/openziti.gpg] https://packages.openziti.org/${ZITIPAX_DEB:-zitipax-openziti-deb-stable} debian main"

local REPOFILE="/etc/apt/sources.list.d/openziti-release.list"
if [ -s $REPOFILE ]; then
local EXISTINGSUM
local REPOSUM
EXISTINGSUM=$(checkSum < $REPOFILE)
REPOSUM=$(checkSum <<< "$REPOSRC")
if [ "$EXISTINGSUM" != "$REPOSUM" ]; then
mv -v $REPOFILE{,".$(date -Iseconds)"}
echo "$REPOSRC" > $REPOFILE

fi
else
echo "$REPOSRC" >| $REPOFILE

fi

apt-get update
apt-get install --yes "$@"
for PKG in "$@"; do
apt-cache show "$PKG=$(dpkg-query -W -f='${Version}' $PKG)"
done
}

main(){
if ! (( $# )); then
echo "ERROR: No arguments provided. Please provide a space-separated list of packages to install from the OpenZiti repo." >&2
exit 1
fi
# Detect the system's distribution family
if [ -f /etc/redhat-release ]; then
installRedHat "$@"
elif [ -f /etc/debian_version ]; then
installDebian "$@"
else
echo "ERROR: Unsupported Linux distribution family. The zrok-share package is availabe as a Debian or Red Hat package." >&2
exit 1
fi
}

# ensure the script is not executed before it is fully downloaded if curl'd to bash
main "$@"

0 comments on commit 308995e

Please sign in to comment.