11#! /bin/bash
2- # Script to help check for the presence of nginx-agent packages
2+ # Usage:
3+ #
4+ # Check package v3.0.0 availability for all platforms, no auth required:
5+ # > ./package_check.sh 3.0.0
6+ #
7+ # Check pkgs and download if present, with authentication:
8+ # > CERT=<cert-path> KEY=<key-path> DL=1 ./package_check.sh 3.0.0
9+ #
10+ # Required parameters:
11+ #
12+ # version: the version of agent you wish to search for i.e 3.0.0
13+ #
14+ # Optional parameters:
15+ #
16+ # PKG_REPO: The root url for the repository you wish to check, defaults to packages.nginx.org
17+ # CERT: Path to your cert file
18+ # KEY: Path to your key file
19+ # DL: Switch to download the package if it is present, set to 1 if download required, defaults to 0
20+ #
21+ # Packages are downloaded to the local directory with the path of its corresponding repo url + uri i.e
22+ #
23+ # packages.nginx.org/nginx-agent/debian/pool/agent/n/nginx-agent/nginx-agent_3.0.0~bullseye_arm64.deb
24+ #
25+
326
427RED=' \033[0;31m'
528GREEN=' \033[0;32m'
7699 ${SUSE[@]}
77100)
78101
79- # # Check if nginx-agent packages are present and report missing or outdated files
102+ # # Check and download if nginx-agent packages are present in the repository
80103check_pkgs () {
81104 for pkg in ${uris[@]} ; do
82105 echo -n " CHECK: ${PKG_REPO_URL} /${pkg} -> "
@@ -94,18 +117,21 @@ check_pkgs () {
94117 done
95118}
96119
120+ # # Download a package
97121dl_pkg () {
98122 local url=${1}
99123 echo -n " GET: ${url} ... "
100124 mkdir -p " ${PKG_DIR} /$( dirname ${pkg} ) "
101- local ret=$( curl -s --fail ${CURL_OPTS} " ${url} " --output " ${PKG_DIR} /${pkg} " )
125+ local ret=$( curl -s ${CURL_OPTS} " ${url} " --output " ${PKG_DIR} /${pkg} " )
102126 if [[ $? != 0 ]]; then
103127 echo -e " ${RED} Download failed!${NC} "
104128 return
105129 fi
106130 echo -e " ${GREEN} Done${NC} "
131+ echo " SAVED: ${PKG_DIR} /${pkg} "
107132}
108133
134+ # # Check for the presence of an nginx-agent version matching $VERSION
109135check_repo () {
110136 echo -n " Checking package repository ${PKG_REPO_URL} ... "
111137 curl -s -I ${CURL_OPTS} " ${PKG_REPO_URL} /index.xml" > /dev/null
@@ -117,7 +143,7 @@ check_repo() {
117143 fi
118144
119145 mkdir -p ${PKG_DIR}
120- curl -s ${CURL_OPTS} " ${PKG_REPO_URL} /index.xml" --output " ${PKG_DIR} /index.xml" || exit 2
146+ curl -s ${CURL_OPTS} " ${PKG_REPO_URL} /index.xml" --output " ${PKG_DIR} /index.xml" || exit 1
121147
122148 echo -n " Checking for nginx-agent version ${VERSION} ... "
123149 grep -qnF " ver=\" ${VERSION} \" " " ${PKG_DIR} /index.xml"
0 commit comments