Skip to content
This repository was archived by the owner on Sep 29, 2020. It is now read-only.

Commit e834e24

Browse files
authored
Merge pull request #17 from gtardif/install_script_latest_release
Install script latest release
2 parents 2167996 + f530f5a commit e834e24

File tree

3 files changed

+213
-6
lines changed

3 files changed

+213
-6
lines changed

README.md

+10-6
Original file line numberDiff line numberDiff line change
@@ -52,16 +52,12 @@ with a fresh install of Ubuntu 20.04.
5252
You can install the new CLI using the install script:
5353

5454
```console
55-
curl -L https://github.com/docker/aci-integration-beta/releases/download/v0.1.4/install.sh | sh
55+
curl -L https://github.com/docker/aci-integration-beta/blob/main/scripts/install_linux.sh | sh
5656
```
5757

5858
### Manual install
5959

60-
You can download the Docker ACI Integration CLI using the following command:
61-
62-
```console
63-
curl -Lo docker-aci https://github.com/docker/aci-integration-beta/releases/download/v0.1.4/docker-linux-amd64
64-
```
60+
You can download the Docker ACI Integration CLI from [latest release](https://github.com/docker/aci-integration-beta/releases/latest).
6561

6662
You will then need to make it executable:
6763

@@ -132,3 +128,11 @@ be done as follows:
132128
```console
133129
sudo rm /usr/local/bin/docker /usr/local/bin/com.docker.cli
134130
```
131+
132+
## Testing the install script
133+
134+
To test the install script, from a machine with docker:
135+
136+
```console
137+
docker build -t testclilinux -f scripts/Dockerfile-testInstall scripts
138+
```

scripts/Dockerfile-testInstall

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
FROM ubuntu:latest
2+
3+
RUN apt-get update
4+
RUN apt-get -y install curl grep
5+
RUN curl https://get.docker.com | sh
6+
7+
COPY install_linux.sh /scripts/install_linux.sh
8+
RUN chmod +x /scripts/install_linux.sh
9+
RUN /scripts/install_linux.sh
10+
RUN docker version | grep Azure
11+
12+
# check we can update
13+
RUN /scripts/install_linux.sh
14+
RUN docker version | grep Azure

scripts/install_linux.sh

+189
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,189 @@
1+
#!/bin/sh
2+
3+
# Script to install the Docker ACI integration CLI on Ubuntu (Beta).
4+
5+
set -eu
6+
7+
RELEASE_URL=https://api.github.com/repos/docker/aci-integration-beta/releases/latest
8+
LINK_NAME="${LINK_NAME:-com.docker.cli}"
9+
DRY_RUN="${DRY_RUN:-}"
10+
11+
desktop_install_url="https://www.docker.com/products/docker-desktop"
12+
engine_install_url="https://docs.docker.com/get-docker/"
13+
14+
link_path="/usr/local/bin/${LINK_NAME}"
15+
existing_cli_path="/usr/bin/docker"
16+
17+
manual_install() {
18+
echo "Please follow the manual install instructions"
19+
}
20+
21+
is_new_cli() {
22+
azure_version_str="$($1 version 2>/dev/null | grep 'Azure' || true)"
23+
if [ -n "$azure_version_str" ]; then
24+
echo 1
25+
else
26+
echo 0
27+
fi
28+
}
29+
30+
echo "Running checks..."
31+
32+
# Check OS
33+
if [ "$(command -v uname)" ]; then
34+
case "$(uname -s)" in
35+
"Linux")
36+
# Check for Ubuntu/Debian based distro
37+
if ! [ -f "/etc/lsb-release" ]; then
38+
echo "Warning: This script has been tested on Ubuntu and may not work on other distributions"
39+
fi
40+
# Pass
41+
;;
42+
"Darwin")
43+
echo "Error: Script not needed on macOS, please install Docker Desktop Edge: $desktop_install_url"
44+
exit 1
45+
;;
46+
"*")
47+
echo "Error: Unsupported OS, please follow manual instructions"
48+
exit 1
49+
;;
50+
esac
51+
else
52+
# Assume Windows
53+
echo "Error: Script not needed on Windows, please install Docker Desktop Edge: $desktop_install_url"
54+
exit 1
55+
fi
56+
57+
user="$(id -un 2>/dev/null || true)"
58+
sh_c='sh -c'
59+
sudo_sh_c='sh -c'
60+
if [ "$user" != 'root' ]; then
61+
if [ "$(command -v sudo)" ]; then
62+
sudo_sh_c='sudo -E sh -c'
63+
elif [ "$(command -v su)" ]; then
64+
sudo_sh_c='su -c'
65+
else
66+
echo "Error: This installer needs the ability to run commands as root."
67+
exit 1
68+
fi
69+
fi
70+
71+
if [ -n "$DRY_RUN" ]; then
72+
sh_c='echo $sh_c'
73+
sudo_sh_c='echo $sudo_sh_c'
74+
fi
75+
76+
# Check if Docker Engine is installed
77+
if ! [ "$(command -v docker)" ]; then
78+
echo "Error: Docker Engine not found"
79+
echo "You need to install Docker first: $engine_install_url"
80+
exit 1
81+
fi
82+
83+
download_cmd='curl -fsSLo'
84+
# Check that system has curl installed
85+
if ! [ "$(command -v curl)" ]; then
86+
echo "Error: curl not found"
87+
echo "Please install curl"
88+
exit 1
89+
fi
90+
91+
DOWNLOAD_URL=$(curl -s ${RELEASE_URL} | grep "browser_download_url.*docker-linux-amd64" | cut -d : -f 2,3)
92+
93+
# Check if the ACI CLI is already installed
94+
if [ $(is_new_cli "docker") -eq 1 ]; then
95+
if [ $(is_new_cli "/usr/local/bin/docker") -eq 1 ]; then
96+
echo "You already have the Docker ACI Integration CLI installed, overriding with latest version"
97+
download_dir=$($sh_c 'mktemp -d')
98+
$sh_c "${download_cmd} ${download_dir}/docker-aci ${DOWNLOAD_URL}"
99+
$sudo_sh_c "install -m 775 ${download_dir}/docker-aci /usr/local/bin/docker"
100+
exit 0
101+
fi
102+
echo "You already have the Docker ACI Integration CLI installed, in a different location."
103+
exit 1
104+
fi
105+
106+
# Check if this script has already been run
107+
if [ -f "${link_path}" ]; then
108+
echo "Error: This script appears to have been run as ${link_path} exists"
109+
echo "Please uninstall and rerun this script or follow the manual instructions"
110+
exit 1
111+
fi
112+
113+
# Check current Docker CLI is installed to /usr/bin/
114+
if ! [ -f "${existing_cli_path}" ]; then
115+
echo "Error: This script only works if the Docker CLI is installed to /usr/bin/"
116+
manual_install
117+
exit 1
118+
fi
119+
120+
# Check that PATH contains /usr/bin and /usr/local/bin and that the latter is
121+
# higher priority
122+
path_directories=$(echo "${PATH}" | tr ":" "\n")
123+
usr_bin_pos=-1
124+
usr_local_bin_pos=-1
125+
count=0
126+
for d in ${path_directories}; do
127+
if [ "${d}" = '/usr/bin' ]; then
128+
usr_bin_pos=$count
129+
fi
130+
if [ "${d}" = '/usr/local/bin' ]; then
131+
usr_local_bin_pos=$count
132+
fi
133+
count=$((count + 1))
134+
done
135+
if [ $usr_bin_pos -eq -1 ]; then
136+
echo "Error: /usr/bin not found in PATH"
137+
manual_install
138+
exit 1
139+
elif [ $usr_local_bin_pos -eq -1 ]; then
140+
echo "Error: /usr/local/bin not found in PATH"
141+
manual_install
142+
exit 1
143+
elif ! [ $usr_local_bin_pos -lt $usr_bin_pos ]; then
144+
echo "Error: /usr/local/bin is not ordered higher than /usr/bin in your PATH"
145+
manual_install
146+
exit 1
147+
fi
148+
149+
echo "Checks passed!"
150+
echo "Downloading CLI..."
151+
152+
# Download CLI to temporary directory
153+
download_dir=$($sh_c 'mktemp -d')
154+
$sh_c "${download_cmd} ${download_dir}/docker-aci ${DOWNLOAD_URL}"
155+
156+
echo "Downloaded CLI!"
157+
echo "Installing CLI..."
158+
159+
# Link existing Docker CLI
160+
$sudo_sh_c "ln -s ${existing_cli_path} ${link_path}"
161+
162+
# Install downloaded CLI
163+
$sudo_sh_c "install -m 775 ${download_dir}/docker-aci /usr/local/bin/docker"
164+
165+
# Clear cache
166+
cleared_cache=1
167+
if [ "$(command hash)" ]; then
168+
$sh_c "hash -r"
169+
elif [ "$(command rehash)" ]; then
170+
$sh_c "rehash"
171+
else
172+
cleared_cache=
173+
echo "Warning: Unable to clear command cache"
174+
fi
175+
176+
if [ -n "$DRY_RUN" ]; then
177+
exit 0
178+
fi
179+
180+
if [ -n "$cleared_cache" ]; then
181+
# Check ACI CLI is working
182+
if [ $(is_new_cli "docker") -eq 0 ]; then
183+
echo "Error: Docker ACI Integration CLI installation error"
184+
exit 1
185+
fi
186+
echo "Done!"
187+
else
188+
echo "Please log out and in again to use the Docker ACI integration CLI"
189+
fi

0 commit comments

Comments
 (0)