Skip to content

Commit 1f26e65

Browse files
authored
Merge pull request #81 from Akianonymus/fix
Add flag to limit speed | Add github action check for installation | Bugfixes | Misc
2 parents f7a0987 + 37f82b1 commit 1f26e65

File tree

5 files changed

+80
-32
lines changed

5 files changed

+80
-32
lines changed

.github/workflows/main.yml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
name: Checks
2+
on:
3+
push:
4+
branches:
5+
- '**'
6+
paths-ignore:
7+
- '*.md'
8+
pull_request:
9+
branches:
10+
- '**'
11+
paths-ignore:
12+
- '*.md'
13+
jobs:
14+
installation_and_download:
15+
name: Installation
16+
runs-on: ubuntu-latest
17+
if: "!contains(github.event.head_commit.message, '[SKIP-CI]')"
18+
steps:
19+
- uses: actions/checkout@v1
20+
- name: 'Install Google drive upload'
21+
run: |
22+
bash install.sh
23+
bash install.sh -B master -c custom_gupload
24+
sudo bash install.sh -p /usr/bin -c custom_gupload

README.md

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
<h1 align="center">Google drive upload</h1>
22
<p align="center">
3-
<a href="https://github.com/labbots/google-drive-upload/stargazers"><img src="https://img.shields.io/github/stars/labbots/google-drive-upload.svg?color=blueviolet&style=for-the-badge" alt="Stars"></a>
43
<a href="https://github.com/labbots/google-drive-upload/releases"><img src="https://img.shields.io/github/release/labbots/google-drive-upload.svg?style=for-the-badge" alt="Latest Release"></a>
4+
<a href="https://github.com/labbots/google-drive-upload/stargazers"><img src="https://img.shields.io/github/stars/labbots/google-drive-upload.svg?color=blueviolet&style=for-the-badge" alt="Stars"></a>
5+
<a href="https://github.com/labbots/google-drive-upload/blob/master/LICENSE"><img src="https://img.shields.io/github/license/labbots/google-drive-upload.svg?style=for-the-badge" alt="License"></a>
6+
</p>
7+
<p align="center">
58
<a href="https://www.codacy.com/manual/labbots/google-drive-upload?utm_source=github.com&amp;utm_medium=referral&amp;utm_content=labbots/google-drive-upload&amp;utm_campaign=Badge_Grade"><img alt="Codacy grade" src="https://img.shields.io/codacy/grade/55b1591a28af473886c8dfdb3f2c9123?style=for-the-badge"></a>
9+
<a href="https://github.com/labbots/google-drive-upload/actions"><img alt="Github Action Checks" src="https://img.shields.io/github/workflow/status/labbots/google-drive-upload/Checks?label=CI%20Checks&style=for-the-badge"></a>
10+
</p>
611
</p>
712
<p align="center">
8-
<a href="https://github.com/labbots/google-drive-upload/blob/master/LICENSE"><img src="https://img.shields.io/github/license/labbots/google-drive-upload.svg?style=for-the-badge" alt="License"></a>
913
<a href="https://plant.treeware.earth/labbots/google-drive-upload"><img alt="Buy us a tree" src="https://img.shields.io/treeware/trees/labbots/google-drive-upload?color=green&label=Buy%20us%20a%20Tree%20%F0%9F%8C%B3&style=for-the-badge"></a>
1014
</p>
1115

@@ -410,6 +414,12 @@ These are the custom flags that are currently implemented:
410414

411415
---
412416

417+
- <strong>--speed 'speed'</strong>
418+
419+
Limit the download speed, supported formats: 1K, 1M and 1G.
420+
421+
---
422+
413423
- <strong>-q | --quiet</strong>
414424

415425
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.

install.sh

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -238,12 +238,11 @@ _full_path() {
238238
# Globals: None
239239
# Arguments: 2
240240
# ${1} = repo name
241-
# ${2} = branch or release
242-
# ${3} = branch name or release name
241+
# ${2} = sha sum or branch name or tag name
243242
# Result: print fetched shas
244243
###################################################
245244
_get_files_and_commits() {
246-
declare repo="${1:-${REPO}}" type_value="${2:-${TYPE_VALUE}}"
245+
declare repo="${1:-${REPO}}" type_value="${2:-${LATEST_CURRENT_SHA}}"
247246
declare html commits files
248247

249248
# shellcheck disable=SC2086
@@ -277,14 +276,16 @@ _get_latest_sha() {
277276
case "${1:-${TYPE}}" in
278277
branch)
279278
LATEST_SHA="$(
280-
hash="$(curl --compressed -s https://github.com/"${3:-${REPO}}"/commits/"${2:-${TYPE_VALUE}}".atom -r 0-2000 | grep "Commit\\/" -m1 || :)"
281-
read -r firstline <<< "${hash}" && regex="(/.*<)" && [[ ${firstline} =~ ${regex} ]] && printf "%s\n" "${BASH_REMATCH[1]:1:-1}"
279+
: "$(curl --compressed -s https://github.com/"${3:-${REPO}}"/commits/"${2:-${TYPE_VALUE}}".atom -r 0-2000)"
280+
: "$(grep "Commit\\/" -m1 <<< "${_}" || :)"
281+
read -r firstline <<< "${_}" && regex="(/.*<)" && [[ ${firstline} =~ ${regex} ]] && printf "%s\n" "${BASH_REMATCH[1]:1:-1}"
282282
)"
283283
;;
284284
release)
285285
LATEST_SHA="$(
286-
hash="$(curl -L --compressed -s https://github.com/"${3:-${REPO}}"/releases/"${2:-${TYPE_VALUE}}" | grep "=\"/""${3:-${REPO}}""/commit" -m1 || :)"
287-
read -r firstline <<< "${hash}" && : "${hash/*commit\//}" && printf "%s\n" "${_/\"*/}"
286+
: "$(curl -L --compressed -s https://github.com/"${3:-${REPO}}"/releases/"${2:-${TYPE_VALUE}}")"
287+
: "$(grep "=\"/""${3:-${REPO}}""/commit" -m1 <<< "${_}" || :)"
288+
: "${_/*commit\//}" && printf "%s\n" "${_/\"*/}"
288289
)"
289290
;;
290291
esac

upload.sh

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ Options:\n
1818
-o | --overwrite - Overwrite the files with the same name, if present in the root folder/input folder, also works with recursive folders.\n
1919
-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
2020
-S | --share <optional_email_address>- Share the uploaded input file/folder, grant reader permission to provided email address or to everyone with the shareable link.\n
21+
--speed 'speed' - Limit the download speed, supported formats: 1K, 1M and 1G.\n
2122
-i | --save-info <file_to_save_info> - Save uploaded files info to the given filename.\n
2223
-z | --config <config_path> - 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
2324
-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() {
331332
-o- \
332333
--url "${uploadlink}" \
333334
--globoff \
335+
${CURL_SPEED} \
334336
${CURL_ARGS})" || :
335337
return 0
336338
}
@@ -404,6 +406,7 @@ _upload_file() {
404406
-T "${input}" \
405407
-o- \
406408
--url "${uploadlink}" \
409+
${CURL_SPEED} \
407410
--globoff)" || :
408411
if [[ -n ${upload_body} ]]; then
409412
_collect_file_info
@@ -567,7 +570,7 @@ _setup_arguments() {
567570
# De-initialize if any variables set already.
568571
unset FIRST_INPUT FOLDER_INPUT FOLDERNAME LOCAL_INPUT_ARRAY ID_INPUT_ARRAY
569572
unset PARALLEL NO_OF_PARALLEL_JOBS SHARE SHARE_EMAIL OVERWRITE SKIP_DUPLICATES SKIP_SUBDIRS ROOTDIR QUIET
570-
unset VERBOSE VERBOSE_PROGRESS DEBUG LOG_FILE_ID
573+
unset VERBOSE VERBOSE_PROGRESS DEBUG LOG_FILE_ID CURL_SPEED
571574
CURL_ARGS="-#"
572575
INFO_PATH="${HOME}/.google-drive-upload"
573576
INFO_FILE="${INFO_PATH}/google-drive-upload.info"
@@ -682,6 +685,16 @@ _setup_arguments() {
682685
shift
683686
fi
684687
;;
688+
--speed)
689+
_check_longoptions "${1}" "${2}"
690+
regex='^([0-9]+)([k,K]|[m,M]|[g,G])+$'
691+
if [[ ${2} =~ ${regex} ]]; then
692+
CURL_SPEED="--limit-rate ${2}" && shift
693+
else
694+
printf "Error: Wrong speed limit format, supported formats: 1K , 1M and 1G\n" 1>&2
695+
exit 1
696+
fi
697+
;;
685698
-q | --quiet)
686699
QUIET="_print_center_quiet"
687700
;;
@@ -1018,15 +1031,14 @@ _process_arguments() {
10181031
if [[ -n ${parallel} ]]; then
10191032
{ [[ ${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}"; }
10201033
# Export because xargs cannot access if it is just an internal variable.
1021-
export ID CURL_ARGS="-s" ACCESS_TOKEN OVERWRITE COLUMNS API_URL API_VERSION LOG_FILE_ID SKIP_DUPLICATES QUIET UPLOAD_METHOD TMPFILE
1034+
export ID CURL_ARGS="-s" ACCESS_TOKEN OVERWRITE COLUMNS API_URL API_VERSION LOG_FILE_ID SKIP_DUPLICATES QUIET UPLOAD_METHOD TMPFILE CURL_SPEED
10221035
export -f _upload_file _print_center _clear_line _json_value _url_encode _check_existing_file _print_center_quiet _newline _bytes_to_human
10231036

10241037
[[ -f ${TMPFILE}SUCCESS ]] && rm "${TMPFILE}"SUCCESS
10251038
[[ -f ${TMPFILE}ERROR ]] && rm "${TMPFILE}"ERROR
10261039

10271040
# shellcheck disable=SC2016
10281041
printf "\"%s\"\n" "${FILENAMES[@]}" | xargs -n1 -P"${NO_OF_PARALLEL_JOBS_FINAL}" -i bash -c '
1029-
printf "%s\n" "$$" >| "${TMPFILE}"pid"$$"
10301042
_upload_file "${UPLOAD_METHOD:-create}" "{}" "${ID}" "${ACCESS_TOKEN}" parallel
10311043
' 1>| "${TMPFILE}"SUCCESS 2>| "${TMPFILE}"ERROR &
10321044

@@ -1113,15 +1125,14 @@ _process_arguments() {
11131125
if [[ -n ${parallel} ]]; then
11141126
{ [[ ${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}"; }
11151127
# Export because xargs cannot access if it is just an internal variable.
1116-
export CURL_ARGS="-s" ACCESS_TOKEN OVERWRITE COLUMNS API_URL API_VERSION LOG_FILE_ID SKIP_DUPLICATES QUIET UPLOAD_METHOD TMPFILE
1128+
export CURL_ARGS="-s" ACCESS_TOKEN OVERWRITE COLUMNS API_URL API_VERSION LOG_FILE_ID SKIP_DUPLICATES QUIET UPLOAD_METHOD TMPFILE CURL_SPEED
11171129
export -f _upload_file _print_center _clear_line _json_value _url_encode _check_existing_file _print_center_quiet _newline _bytes_to_human
11181130

11191131
[[ -f "${TMPFILE}"SUCCESS ]] && rm "${TMPFILE}"SUCCESS
11201132
[[ -f "${TMPFILE}"ERROR ]] && rm "${TMPFILE}"ERROR
11211133

11221134
# shellcheck disable=SC2016
11231135
printf "\"%s\"\n" "${FINAL_LIST[@]}" | xargs -n1 -P"${NO_OF_PARALLEL_JOBS_FINAL}" -i bash -c '
1124-
printf "%s\n" "$$" >| "${TMPFILE}"pid"$$"
11251136
LIST="{}"
11261137
FILETOUPLOAD="${LIST//*"|:_//_:|"}"
11271138
DIRTOUPLOAD="$(: "|:_//_:|""${FILETOUPLOAD}" && : "${LIST::-${#_}}" && printf "%s\n" "${_//*"|:_//_:|"}")"
@@ -1238,21 +1249,20 @@ main() {
12381249
[[ -n ${PARALLEL_UPLOAD} ]] && _setup_tempfile
12391250

12401251
_cleanup() {
1241-
(
1242-
if [[ -n ${PARALLEL_UPLOAD} ]]; then
1243-
pid_files="$(printf "%b " "${TMPFILE}"pid* && printf "\n")"
1244-
pids="${pid_files//${TMPFILE}pid/}"
1245-
# shellcheck disable=SC2086
1246-
kill -9 ${pids} || :
1247-
rm -f "${TMPFILE:?}"*
1252+
{
1253+
[[ -n ${PARALLEL_UPLOAD} ]] && rm -f "${TMPFILE:?}"*
1254+
export abnormal_exit
1255+
if [[ -n ${abnormal_exit} ]]; then
1256+
kill -- -$$
1257+
else
1258+
_auto_update
12481259
fi
1249-
kill -9 $$ || :
1250-
) &> /dev/null &
1260+
} &> /dev/null || :
12511261
return 0
12521262
}
12531263

1254-
trap 'printf "\n" ; exit' SIGINT
1255-
trap '_auto_update ; _cleanup' SIGTERM EXIT
1264+
trap 'printf "\n" ; abnormal_exit=1; exit' SIGINT SIGTERM
1265+
trap '_cleanup' EXIT
12561266

12571267
START="$(printf "%(%s)T\\n" "-1")"
12581268
_print_center "justify" "Starting script" "-"

utils.sh

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -244,18 +244,21 @@ _full_path() {
244244
# Result: print fetched sha
245245
###################################################
246246
_get_latest_sha() {
247-
[[ $# -lt 3 ]] && printf "%s: Missing arguments\n" "${FUNCNAME[0]}" && return 1
248247
declare LATEST_SHA
249248
case "${1:-${TYPE}}" in
250249
branch)
251-
LATEST_SHA="$(hash="$(curl --compressed -s https://github.com/"${3:-${REPO}}"/commits/"${2:-${TYPE_VALUE}}".atom -r 0-2000 | grep "Commit\\/" -m1 || :)" && {
252-
read -r firstline <<< "${hash}" && regex="(/.*<)" && [[ ${firstline} =~ ${regex} ]] && printf "%s\n" "${BASH_REMATCH[1]:1:-1}"
253-
})"
250+
LATEST_SHA="$(
251+
: "$(curl --compressed -s https://github.com/"${3:-${REPO}}"/commits/"${2:-${TYPE_VALUE}}".atom -r 0-2000)"
252+
: "$(grep "Commit\\/" -m1 <<< "${_}" || :)"
253+
read -r firstline <<< "${_}" && regex="(/.*<)" && [[ ${firstline} =~ ${regex} ]] && printf "%s\n" "${BASH_REMATCH[1]:1:-1}"
254+
)"
254255
;;
255256
release)
256-
LATEST_SHA="$(hash="$(curl -L --compressed -s https://github.com/"${3:-${REPO}}"/releases/"${2:-${TYPE_VALUE}}" | grep "=\"/""${3:-${REPO}}""/commit" -m1 || :)" && {
257-
read -r firstline <<< "${hash}" && : "${hash/*commit\//}" && printf "%s\n" "${_/\"*/}"
258-
})"
257+
LATEST_SHA="$(
258+
: "$(curl -L --compressed -s https://github.com/"${3:-${REPO}}"/releases/"${2:-${TYPE_VALUE}}")"
259+
: "$(grep "=\"/""${3:-${REPO}}""/commit" -m1 <<< "${_}" || :)"
260+
: "${_/*commit\//}" && printf "%s\n" "${_/\"*/}"
261+
)"
259262
;;
260263
esac
261264
printf "%b" "${LATEST_SHA:+${LATEST_SHA}\n}"

0 commit comments

Comments
 (0)