-
Notifications
You must be signed in to change notification settings - Fork 160
/
build
executable file
·109 lines (90 loc) · 3.38 KB
/
build
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
#!/usr/bin/env bash
is_enabled () {
echo "$1" | grep -q -i -E "^(yes|on|true|1)$"
}
is_disabled () {
echo "$1" | grep -q -i -E "^(no|off|false|0)$"
}
get_hrefs () {
local url="$1"
local regexp="$2"
local download_cmd
if command -v wget >/dev/null 2>&1; then
download_cmd="wget -q -O-"
elif command -v curl >/dev/null 2>&1; then
download_cmd="curl -s -o-"
else
echo "ERROR: Neither wget or curl is available, unable to perform download"
exit 1
fi
$download_cmd "${url}" | sed -E "s/></>\n</g" | sed -n -E "s|^.*<a href=\"(${regexp})\">.*|\1|p" | uniq
}
get_os_codename () {
local branch="$1"
local url="https://dl.winehq.org/wine-builds/ubuntu/dists/"
# Get the latest two Ubuntu version codenames that Wine is available on
local os_codenames=()
while IFS='' read -r line; do os_codenames+=("$line"); done < <(get_hrefs "${url}" "[^:]+/" | sed -E "s|/$||" | grep -v -E "^([p-z]|/)" | sort -r | head -2)
# Get the latest version of Wine available for each OS codename
local codename
local index=0
local wine_versions=()
for codename in "${os_codenames[@]}"; do
local version
version=$(get_hrefs "${url}${codename}/main/binary-amd64/" "wine-${branch}_.*\.deb" | sed -n -E "s/^wine-${branch}_([0-9]+(\.[0-9]+)*).*$/\1/p" | sort -rV | head -1)
wine_versions[${index}]="${version}"
index+=1
done
# Determine which OS codename has the latest version of Wine or use the _older_ OS if both the same
# as many issues when using latest OS. Refer to https://github.com/scottyhardy/docker-wine/issues/92
local latest_wine_ver
latest_wine_ver=$(printf '%s\n' "${wine_versions[@]}" | sort -rV | head -1)
local retval
if [ "${wine_versions[1]}" == "${latest_wine_ver}" ]; then
retval=${os_codenames[1]} # previous Ubuntu version
else
retval=${os_codenames[0]} # latest Ubuntu version
fi
# Return the OS codename to use
echo "${retval}"
}
# Array of command line args to be passed to the build command
BUILD_ARGS=("$@")
# Default values
BUILD_CMD="docker build"
DOCKER_REPO="${DOCKER_REPO:-docker-wine}"
NO_RDP="${NO_RDP:-no}"
WINE_BRANCH="${WINE_BRANCH:-stable}"
# Get the codename for latest version of wine-${WINE-BRANCH}
#UBUNTU_CODENAME="$(get_os_codename "${WINE_BRANCH}")"
# Just use latest if codename unable to be determined
if [ -n "${UBUNTU_CODENAME}" ]; then
echo "Found latest version of wine-${WINE_BRANCH} is available on Ubuntu ${UBUNTU_CODENAME}"
else
echo "WARNING: Unable to determine version of Ubuntu to use with Wine, so using latest"
UBUNTU_CODENAME="latest"
fi
# Use standard Ubuntu image if using NO_RDP
if is_enabled "${NO_RDP}"; then
BASE_IMAGE="ubuntu"
TAG="${UBUNTU_CODENAME}"
elif is_disabled "${NO_RDP}"; then
BASE_IMAGE="scottyhardy/docker-remote-desktop"
TAG="ubuntu-${UBUNTU_CODENAME}"
else
echo "ERROR: Invalid value '${NO_RDP}' used for NO_RDP"
exit 1
fi
if ! docker system info >/dev/null 2>&1; then
if buildah -v >/dev/null 2>&1; then
BUILD_CMD="buildah bud"
else
echo "ERROR: Docker is not running or not installed, unable to proceed"
exit 1
fi
fi
${BUILD_CMD} "${BUILD_ARGS[@]}" \
--build-arg="BASE_IMAGE=${BASE_IMAGE}" \
--build-arg="TAG=${TAG}" \
--build-arg="WINE_BRANCH=${WINE_BRANCH}" \
-t "${DOCKER_REPO}" .