Files
runner-images/images/linux/scripts/helpers/install.sh
T

45 lines
1.3 KiB
Bash
Raw Normal View History

2020-05-29 12:27:33 +00:00
#!/bin/bash
################################################################################
## File: install.sh
## Desc: Helper functions for installing tools
################################################################################
download_with_retries() {
# Due to restrictions of bash functions, positional arguments are used here.
# In case if you using latest argument NAME, you should also set value to all previous parameters.
# Example: download_with_retries $ANDROID_SDK_URL "." "android_sdk.zip"
local URL="$1"
local DEST="${2:-.}"
local NAME="${3:-${URL##*/}}"
2020-07-01 13:31:41 +00:00
local COMPRESSED="$4"
if [ $COMPRESSED == "compressed" ]; then
2020-07-07 19:23:45 +03:00
COMMAND="curl $URL -4 -sL --compressed -o '$DEST/$NAME'"
2020-07-01 13:31:41 +00:00
else
2020-07-07 19:23:45 +03:00
COMMAND="curl $URL -4 -sL -o '$DEST/$NAME'"
2020-07-01 13:31:41 +00:00
fi
2020-05-29 12:27:33 +00:00
echo "Downloading $URL..."
i=20
while [ $i -gt 0 ]; do
((i--))
2020-07-01 13:31:41 +00:00
eval $COMMAND
2020-05-29 12:27:33 +00:00
if [ $? != 0 ]; then
sleep 30
else
return 0
fi
done
echo "Could not download $URL"
return 1
2020-07-08 22:28:23 +03:00
}
## Use dpkg to figure out if a package has already been installed
## Example use:
2020-07-09 15:14:28 +03:00
## if ! IsPackageInstalled packageName; then
2020-07-08 22:28:23 +03:00
## echo "packageName is not installed!"
## fi
2020-07-09 15:14:28 +03:00
function IsPackageInstalled {
2020-07-08 22:28:23 +03:00
dpkg -S $1 &> /dev/null
2020-05-29 12:27:33 +00:00
}