11#! /usr/bin/env bash
22
3+ if [ " $( id -u) " -ne 0 ]; then
4+ echo -e ' Scripts must be run as root. Use sudo, su, or add "USER root" to your Dockerfile before running this script.'
5+ exit 1
6+ fi
7+
38source ./utils.sh
49
510AIR_VERSION=${VERSION:- " latest" }
11+ INSTALL_DIRECTLY_FROM_GITHUB_RELEASE=${INSTALLDIRECTLYFROMGITHUBRELEASE:- " true" }
612GITHUB_REPO=https://github.com/air-verse/air/
713
814# Exit immediately if a command exits with a non-zero status.
915set -e
1016
17+ apt_get_update
18+
19+ # Clean up
20+ rm -rf /var/lib/apt/lists/*
21+
1122export DEBIAN_FRONTEND=noninteractive
1223
24+ install_using_go () {
25+ local latest_version=$1
26+ local prev_version=$2
27+
28+ set +e
29+
30+ go install github.com/air-verse/air@v${latest_version}
31+ exit_code=$?
32+
33+ set -e
34+
35+ if [ " $exit_code " != " 0" ]; then
36+ # Handle situation where git tags are ahead of what was is available to actually download
37+ echo " (!) air version ${latest_version} failed to download. Attempting to fall back to ${prev_version} to retry..."
38+ go install github.com/air-verse/air@v${prev_version}
39+ fi
40+ }
41+
42+ get_github_filename () {
43+ local version=$1
44+ local arch=$2
45+ echo " air_${version} _linux_${arch} "
46+ }
47+
48+ install_from_github () {
49+ local latest_version=$1
50+ local prev_version=$2
51+
52+ check_packages wget
53+ local arch=$( dpkg --print-architecture)
54+
55+ local filename=$( get_github_filename $latest_version $arch )
56+
57+ set +e
58+
59+ mkdir -p /tmp/air
60+ pushd /tmp/air
61+ wget ${GITHUB_REPO} /releases/download/v${latest_version} /${filename}
62+ local exit_code=$?
63+
64+ set -e
65+
66+ if [ " $exit_code " != " 0" ]; then
67+ # Handle situation where git tags are ahead of what was is available to actually download
68+ echo " (!) air version ${latest_version} failed to download. Attempting to fall back to ${prev_version} to retry..."
69+ filename=$( get_github_filename $prev_version $arch )
70+ wget ${GITHUB_REPO} /releases/download/v${prev_version} /${filename}
71+ fi
72+
73+ chmod 755 /tmp/air/${filename}
74+ mv /tmp/air/${filename} /usr/local/bin/air
75+ popd
76+ rm -rf /tmp/air
77+ }
78+
79+ # Install curl if missing
80+ check_packages curl ca-certificates
81+
82+ # Install git if missing
83+ if ! type git > /dev/null 2>&1 ; then
84+ check_packages git
85+ fi
86+
1387version_list=$( git ls-remote --tags ${GITHUB_REPO} )
1488
1589versions=($( find_latest_versions $AIR_VERSION version_list " tags/v" ) )
@@ -19,19 +93,15 @@ if [ $? -eq 1 ]; then
1993fi
2094
2195latest_version=${versions[0]}
22- prev_version=${versions[1]}
96+ prev_version=${versions[1]:- $latest_version }
2397
2498echo " Downloading air v${latest_version} ...."
2599
26- set +e
27-
28- go install github.com/air-verse/air@v${latest_version}
29- exit_code=$?
30-
31- set -e
100+ if [ " $INSTALL_DIRECTLY_FROM_GITHUB_RELEASE " = " true" ]; then
101+ install_from_github $latest_version $prev_version
102+ else
103+ install_using_go $latest_version $prev_version
104+ fi
32105
33- if [ " $exit_code " != " 0" ]; then
34- # Handle situation where git tags are ahead of what was is available to actually download
35- echo " (!) air version ${latest_version} failed to download. Attempting to fall back to ${prev_version} to retry..."
36- go install github.com/air-verse/air@v${prev_version}
37- fi
106+ # Clean up
107+ rm -rf /var/lib/apt/lists/*
0 commit comments