diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml
new file mode 100755
index 0000000..b9fd67e
--- /dev/null
+++ b/.github/workflows/main.yml
@@ -0,0 +1,24 @@
+name: Checks
+on:
+ push:
+ branches:
+ - '**'
+ paths-ignore:
+ - '*.md'
+ pull_request:
+ branches:
+ - '**'
+ paths-ignore:
+ - '*.md'
+jobs:
+ installation_and_download:
+ name: Installation
+ runs-on: ubuntu-latest
+ if: "!contains(github.event.head_commit.message, '[SKIP-CI]')"
+ steps:
+ - uses: actions/checkout@v1
+ - name: 'Install Google drive upload'
+ run: |
+ bash install.sh
+ bash install.sh -B master -c custom_gupload
+ sudo bash install.sh -p /usr/bin -c custom_gupload
diff --git a/README.md b/README.md
index a704854..c8bc8b4 100755
--- a/README.md
+++ b/README.md
@@ -1,11 +1,15 @@
Google drive upload
-
+
+
+
+
+
+
-
@@ -410,6 +414,12 @@ These are the custom flags that are currently implemented:
---
+- --speed 'speed'
+
+ Limit the download speed, supported formats: 1K, 1M and 1G.
+
+ ---
+
- -q | --quiet
Supress the normal output, only show success/error upload messages for files, and one extra line at the beginning for folder showing no. of files and sub folders.
diff --git a/install.sh b/install.sh
index 11fab04..b1707a5 100755
--- a/install.sh
+++ b/install.sh
@@ -238,12 +238,11 @@ _full_path() {
# Globals: None
# Arguments: 2
# ${1} = repo name
-# ${2} = branch or release
-# ${3} = branch name or release name
+# ${2} = sha sum or branch name or tag name
# Result: print fetched shas
###################################################
_get_files_and_commits() {
- declare repo="${1:-${REPO}}" type_value="${2:-${TYPE_VALUE}}"
+ declare repo="${1:-${REPO}}" type_value="${2:-${LATEST_CURRENT_SHA}}"
declare html commits files
# shellcheck disable=SC2086
@@ -277,14 +276,16 @@ _get_latest_sha() {
case "${1:-${TYPE}}" in
branch)
LATEST_SHA="$(
- hash="$(curl --compressed -s https://github.com/"${3:-${REPO}}"/commits/"${2:-${TYPE_VALUE}}".atom -r 0-2000 | grep "Commit\\/" -m1 || :)"
- read -r firstline <<< "${hash}" && regex="(/.*<)" && [[ ${firstline} =~ ${regex} ]] && printf "%s\n" "${BASH_REMATCH[1]:1:-1}"
+ : "$(curl --compressed -s https://github.com/"${3:-${REPO}}"/commits/"${2:-${TYPE_VALUE}}".atom -r 0-2000)"
+ : "$(grep "Commit\\/" -m1 <<< "${_}" || :)"
+ read -r firstline <<< "${_}" && regex="(/.*<)" && [[ ${firstline} =~ ${regex} ]] && printf "%s\n" "${BASH_REMATCH[1]:1:-1}"
)"
;;
release)
LATEST_SHA="$(
- hash="$(curl -L --compressed -s https://github.com/"${3:-${REPO}}"/releases/"${2:-${TYPE_VALUE}}" | grep "=\"/""${3:-${REPO}}""/commit" -m1 || :)"
- read -r firstline <<< "${hash}" && : "${hash/*commit\//}" && printf "%s\n" "${_/\"*/}"
+ : "$(curl -L --compressed -s https://github.com/"${3:-${REPO}}"/releases/"${2:-${TYPE_VALUE}}")"
+ : "$(grep "=\"/""${3:-${REPO}}""/commit" -m1 <<< "${_}" || :)"
+ : "${_/*commit\//}" && printf "%s\n" "${_/\"*/}"
)"
;;
esac
diff --git a/upload.sh b/upload.sh
index 1f3cd3d..6707df9 100755
--- a/upload.sh
+++ b/upload.sh
@@ -18,6 +18,7 @@ Options:\n
-o | --overwrite - Overwrite the files with the same name, if present in the root folder/input folder, also works with recursive folders.\n
-d | --skip-duplicates - Do not upload the files with the same name, if already present in the root folder/input folder, also works with recursive folders.\n
-S | --share - Share the uploaded input file/folder, grant reader permission to provided email address or to everyone with the shareable link.\n
+ --speed 'speed' - Limit the download speed, supported formats: 1K, 1M and 1G.\n
-i | --save-info - Save uploaded files info to the given filename.\n
-z | --config - Override default config file with custom config file.\nIf you want to change default value, then use this format -z/--config default=default=your_config_file_path.\n
-q | --quiet - Supress the normal output, only show success/error upload messages for files, and one extra line at the beginning for folder showing no. of files and sub folders.\n
@@ -331,6 +332,7 @@ _upload_file() {
-o- \
--url "${uploadlink}" \
--globoff \
+ ${CURL_SPEED} \
${CURL_ARGS})" || :
return 0
}
@@ -404,6 +406,7 @@ _upload_file() {
-T "${input}" \
-o- \
--url "${uploadlink}" \
+ ${CURL_SPEED} \
--globoff)" || :
if [[ -n ${upload_body} ]]; then
_collect_file_info
@@ -567,7 +570,7 @@ _setup_arguments() {
# De-initialize if any variables set already.
unset FIRST_INPUT FOLDER_INPUT FOLDERNAME LOCAL_INPUT_ARRAY ID_INPUT_ARRAY
unset PARALLEL NO_OF_PARALLEL_JOBS SHARE SHARE_EMAIL OVERWRITE SKIP_DUPLICATES SKIP_SUBDIRS ROOTDIR QUIET
- unset VERBOSE VERBOSE_PROGRESS DEBUG LOG_FILE_ID
+ unset VERBOSE VERBOSE_PROGRESS DEBUG LOG_FILE_ID CURL_SPEED
CURL_ARGS="-#"
INFO_PATH="${HOME}/.google-drive-upload"
INFO_FILE="${INFO_PATH}/google-drive-upload.info"
@@ -682,6 +685,16 @@ _setup_arguments() {
shift
fi
;;
+ --speed)
+ _check_longoptions "${1}" "${2}"
+ regex='^([0-9]+)([k,K]|[m,M]|[g,G])+$'
+ if [[ ${2} =~ ${regex} ]]; then
+ CURL_SPEED="--limit-rate ${2}" && shift
+ else
+ printf "Error: Wrong speed limit format, supported formats: 1K , 1M and 1G\n" 1>&2
+ exit 1
+ fi
+ ;;
-q | --quiet)
QUIET="_print_center_quiet"
;;
@@ -1018,7 +1031,7 @@ _process_arguments() {
if [[ -n ${parallel} ]]; then
{ [[ ${NO_OF_PARALLEL_JOBS} -gt ${NO_OF_FILES} ]] && NO_OF_PARALLEL_JOBS_FINAL="${NO_OF_FILES}"; } || { NO_OF_PARALLEL_JOBS_FINAL="${NO_OF_PARALLEL_JOBS}"; }
# Export because xargs cannot access if it is just an internal variable.
- export ID CURL_ARGS="-s" ACCESS_TOKEN OVERWRITE COLUMNS API_URL API_VERSION LOG_FILE_ID SKIP_DUPLICATES QUIET UPLOAD_METHOD TMPFILE
+ export ID CURL_ARGS="-s" ACCESS_TOKEN OVERWRITE COLUMNS API_URL API_VERSION LOG_FILE_ID SKIP_DUPLICATES QUIET UPLOAD_METHOD TMPFILE CURL_SPEED
export -f _upload_file _print_center _clear_line _json_value _url_encode _check_existing_file _print_center_quiet _newline _bytes_to_human
[[ -f ${TMPFILE}SUCCESS ]] && rm "${TMPFILE}"SUCCESS
@@ -1026,7 +1039,6 @@ _process_arguments() {
# shellcheck disable=SC2016
printf "\"%s\"\n" "${FILENAMES[@]}" | xargs -n1 -P"${NO_OF_PARALLEL_JOBS_FINAL}" -i bash -c '
- printf "%s\n" "$$" >| "${TMPFILE}"pid"$$"
_upload_file "${UPLOAD_METHOD:-create}" "{}" "${ID}" "${ACCESS_TOKEN}" parallel
' 1>| "${TMPFILE}"SUCCESS 2>| "${TMPFILE}"ERROR &
@@ -1113,7 +1125,7 @@ _process_arguments() {
if [[ -n ${parallel} ]]; then
{ [[ ${NO_OF_PARALLEL_JOBS} -gt ${NO_OF_FILES} ]] && NO_OF_PARALLEL_JOBS_FINAL="${NO_OF_FILES}"; } || { NO_OF_PARALLEL_JOBS_FINAL="${NO_OF_PARALLEL_JOBS}"; }
# Export because xargs cannot access if it is just an internal variable.
- export CURL_ARGS="-s" ACCESS_TOKEN OVERWRITE COLUMNS API_URL API_VERSION LOG_FILE_ID SKIP_DUPLICATES QUIET UPLOAD_METHOD TMPFILE
+ export CURL_ARGS="-s" ACCESS_TOKEN OVERWRITE COLUMNS API_URL API_VERSION LOG_FILE_ID SKIP_DUPLICATES QUIET UPLOAD_METHOD TMPFILE CURL_SPEED
export -f _upload_file _print_center _clear_line _json_value _url_encode _check_existing_file _print_center_quiet _newline _bytes_to_human
[[ -f "${TMPFILE}"SUCCESS ]] && rm "${TMPFILE}"SUCCESS
@@ -1121,7 +1133,6 @@ _process_arguments() {
# shellcheck disable=SC2016
printf "\"%s\"\n" "${FINAL_LIST[@]}" | xargs -n1 -P"${NO_OF_PARALLEL_JOBS_FINAL}" -i bash -c '
- printf "%s\n" "$$" >| "${TMPFILE}"pid"$$"
LIST="{}"
FILETOUPLOAD="${LIST//*"|:_//_:|"}"
DIRTOUPLOAD="$(: "|:_//_:|""${FILETOUPLOAD}" && : "${LIST::-${#_}}" && printf "%s\n" "${_//*"|:_//_:|"}")"
@@ -1238,21 +1249,20 @@ main() {
[[ -n ${PARALLEL_UPLOAD} ]] && _setup_tempfile
_cleanup() {
- (
- if [[ -n ${PARALLEL_UPLOAD} ]]; then
- pid_files="$(printf "%b " "${TMPFILE}"pid* && printf "\n")"
- pids="${pid_files//${TMPFILE}pid/}"
- # shellcheck disable=SC2086
- kill -9 ${pids} || :
- rm -f "${TMPFILE:?}"*
+ {
+ [[ -n ${PARALLEL_UPLOAD} ]] && rm -f "${TMPFILE:?}"*
+ export abnormal_exit
+ if [[ -n ${abnormal_exit} ]]; then
+ kill -- -$$
+ else
+ _auto_update
fi
- kill -9 $$ || :
- ) &> /dev/null &
+ } &> /dev/null || :
return 0
}
- trap 'printf "\n" ; exit' SIGINT
- trap '_auto_update ; _cleanup' SIGTERM EXIT
+ trap 'printf "\n" ; abnormal_exit=1; exit' SIGINT SIGTERM
+ trap '_cleanup' EXIT
START="$(printf "%(%s)T\\n" "-1")"
_print_center "justify" "Starting script" "-"
diff --git a/utils.sh b/utils.sh
index 80e09b1..3530b80 100755
--- a/utils.sh
+++ b/utils.sh
@@ -244,18 +244,21 @@ _full_path() {
# Result: print fetched sha
###################################################
_get_latest_sha() {
- [[ $# -lt 3 ]] && printf "%s: Missing arguments\n" "${FUNCNAME[0]}" && return 1
declare LATEST_SHA
case "${1:-${TYPE}}" in
branch)
- LATEST_SHA="$(hash="$(curl --compressed -s https://github.com/"${3:-${REPO}}"/commits/"${2:-${TYPE_VALUE}}".atom -r 0-2000 | grep "Commit\\/" -m1 || :)" && {
- read -r firstline <<< "${hash}" && regex="(/.*<)" && [[ ${firstline} =~ ${regex} ]] && printf "%s\n" "${BASH_REMATCH[1]:1:-1}"
- })"
+ LATEST_SHA="$(
+ : "$(curl --compressed -s https://github.com/"${3:-${REPO}}"/commits/"${2:-${TYPE_VALUE}}".atom -r 0-2000)"
+ : "$(grep "Commit\\/" -m1 <<< "${_}" || :)"
+ read -r firstline <<< "${_}" && regex="(/.*<)" && [[ ${firstline} =~ ${regex} ]] && printf "%s\n" "${BASH_REMATCH[1]:1:-1}"
+ )"
;;
release)
- LATEST_SHA="$(hash="$(curl -L --compressed -s https://github.com/"${3:-${REPO}}"/releases/"${2:-${TYPE_VALUE}}" | grep "=\"/""${3:-${REPO}}""/commit" -m1 || :)" && {
- read -r firstline <<< "${hash}" && : "${hash/*commit\//}" && printf "%s\n" "${_/\"*/}"
- })"
+ LATEST_SHA="$(
+ : "$(curl -L --compressed -s https://github.com/"${3:-${REPO}}"/releases/"${2:-${TYPE_VALUE}}")"
+ : "$(grep "=\"/""${3:-${REPO}}""/commit" -m1 <<< "${_}" || :)"
+ : "${_/*commit\//}" && printf "%s\n" "${_/\"*/}"
+ )"
;;
esac
printf "%b" "${LATEST_SHA:+${LATEST_SHA}\n}"