22
33set -e
44
5- # Read version from the environment variable (set by devcontainer feature)
5+ # Read version from the environment variable
66NGINX_VERSION=" ${VERSION:- latest} "
77
8- # Update package list and install dependencies
9- apt-get update && apt-get install -y curl gnupg2 software-properties-common ca-certificates
10-
11- # Add repository
12- echo " deb http://nginx.org/packages/ubuntu/ focal nginx
13- deb-src http://nginx.org/packages/ubuntu/ focal nginx" | tee /etc/apt/sources.list.d/nginx.list
14-
15- # Add GPG key
16- curl -fsSL https://nginx.org/keys/nginx_signing.key | apt-key add -
17-
18- # Update package list again
8+ # Update package list
199apt-get update
2010
21- # Check available versions
22- AVAILABLE_VERSIONS=$( apt-cache madison nginx | awk ' {print $3}' )
23-
24- # Install Nginx with the specified version
11+ # Install Nginx
2512if [ " $NGINX_VERSION " = " latest" ]; then
26- echo " Installing latest available Nginx version ..."
13+ echo " Installing Nginx..."
2714 apt-get install -y nginx
2815else
29- if echo " $AVAILABLE_VERSIONS " | grep -q " ^ $NGINX_VERSION $ " ; then
30- echo " Installing Nginx version $NGINX_VERSION ... "
31- apt-get install -y nginx=$NGINX_VERSION *
16+ echo " Installing Nginx version $NGINX_VERSION ... "
17+ if apt-cache show " nginx= $NGINX_VERSION " > /dev/null 2>&1 ; then
18+ apt-get install -y " nginx=$NGINX_VERSION "
3219 else
33- echo " Error: Nginx version $NGINX_VERSION is not available in APT repositories."
34- echo " Available versions: $AVAILABLE_VERSIONS "
35- exit 1
20+ echo " Requested version $NGINX_VERSION not available. Installing latest version."
21+ apt-get install -y nginx
3622 fi
3723fi
3824
3925# Start Nginx
4026service nginx start || nginx
4127
4228# Verify installation
43- nginx -v
29+ nginx -v
30+
31+ echo " Nginx installation completed."
0 commit comments