Made sure dynamic config (url paths) dont overrwite eachother.
This commit is contained in:
parent
ae9d304c0b
commit
f3f17fd68a
@ -545,7 +545,7 @@ function getFileByRelease() {
|
|||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
# get the file by tag
|
# get the file by key
|
||||||
function getFileByKey() {
|
function getFileByKey() {
|
||||||
# get the name
|
# get the name
|
||||||
VDM_ZIP_NAME="${VDM_MODE}"
|
VDM_ZIP_NAME="${VDM_MODE}"
|
||||||
@ -1054,6 +1054,13 @@ function setRepositoryNewFiles() {
|
|||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# gives us a unique file name for any url
|
||||||
|
function getUniqueFileName() {
|
||||||
|
local url="$1"
|
||||||
|
local hash=$(echo "$url" | sha256sum | awk '{print $1}')
|
||||||
|
echo "${hash:0:10}"
|
||||||
|
}
|
||||||
|
|
||||||
# give the echo messages
|
# give the echo messages
|
||||||
# only if not set to be quiet
|
# only if not set to be quiet
|
||||||
function _echo() {
|
function _echo() {
|
||||||
@ -1062,7 +1069,7 @@ function _echo() {
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
# remove the program if installed
|
# uninstalls the octojpack program.
|
||||||
function runUninstall() {
|
function runUninstall() {
|
||||||
# now remove the script
|
# now remove the script
|
||||||
if [ -f "/usr/local/bin/${PROGRAM_CODE}" ]; then
|
if [ -f "/usr/local/bin/${PROGRAM_CODE}" ]; then
|
||||||
@ -1099,7 +1106,7 @@ function getProjectEnvironment() {
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
# update the script with the latest version
|
# updates the octojpack program to the latest version.
|
||||||
function runUpdate() {
|
function runUpdate() {
|
||||||
# remove the current version
|
# remove the current version
|
||||||
if [ -f "/usr/local/bin/${PROGRAM_CODE}" ]; then
|
if [ -f "/usr/local/bin/${PROGRAM_CODE}" ]; then
|
||||||
@ -1315,14 +1322,22 @@ fi
|
|||||||
tmp_path="$PWD/.${PROGRAM_CODE}"
|
tmp_path="$PWD/.${PROGRAM_CODE}"
|
||||||
VDM_PACKAGE_CONF_FILE=${VDM_PACKAGE_CONF_FILE:-$tmp_path}
|
VDM_PACKAGE_CONF_FILE=${VDM_PACKAGE_CONF_FILE:-$tmp_path}
|
||||||
|
|
||||||
# check if the config is passed via a URL
|
# Check if the config file is passed as a URL
|
||||||
if [[ "$VDM_PACKAGE_CONF_FILE" =~ ^"http:" ]] || [[ "$VDM_PACKAGE_CONF_FILE" =~ ^"https:" ]]; then
|
if [[ "$VDM_PACKAGE_CONF_FILE" =~ ^http: ]] || [[ "$VDM_PACKAGE_CONF_FILE" =~ ^https: ]]; then
|
||||||
if [[ $(wget -S --spider "$VDM_PACKAGE_CONF_FILE" 2>&1 | grep 'HTTP/1.1 200 OK') ]]; then
|
# Check if the URL is valid
|
||||||
mkdir -p "/home/$USER/.config/${PROGRAM_CODE}"
|
if curl --output /dev/null --silent --head --fail "$VDM_PACKAGE_CONF_FILE"; then
|
||||||
wget --quiet "$VDM_PACKAGE_CONF_FILE" -O "/home/$USER/.config/${PROGRAM_CODE}/conf.json"
|
# Create the directory for the configuration file if it doesn't exist
|
||||||
VDM_PACKAGE_CONF_FILE="/home/$USER/.config/${PROGRAM_CODE}/conf.json"
|
mkdir -p "$HOME/.config/$PROGRAM_CODE"
|
||||||
|
|
||||||
|
# get a file name
|
||||||
|
file_name=$(getUniqueFileName "$VDM_PACKAGE_CONF_FILE")
|
||||||
|
|
||||||
|
# Download the configuration file
|
||||||
|
curl --silent "$VDM_PACKAGE_CONF_FILE" -o "$HOME/.config/$PROGRAM_CODE/${file_name}_conf.json"
|
||||||
|
VDM_PACKAGE_CONF_FILE="$HOME/.config/$PROGRAM_CODE/${file_name}_conf.json"
|
||||||
else
|
else
|
||||||
echo >&2 "[error] The config:$VDM_PACKAGE_CONF_FILE is not a valid URL. Aborting."
|
# Print an error message and exit if the URL is invalid
|
||||||
|
echo >&2 "[error] The config file at $VDM_PACKAGE_CONF_FILE is not a valid URL. Aborting."
|
||||||
exit 18
|
exit 18
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
Loading…
Reference in New Issue
Block a user