@@ -964,10 +964,10 @@ Options:\n
964
964
--hide - This flag will prevent the script to print sensitive information like root folder id or drivelink.\n
965
965
-v | --verbose - Display detailed message (only for non-parallel uploads).\n
966
966
-V | --verbose-progress - Display detailed message and detailed upload progress(only for non-parallel uploads).\n
967
- --skip-internet-check - Do not check for internet connection, recommended to use in sync jobs.\n
968
- -u | --update - Update the installed script in your system.\n
967
+ --skip-internet-check - Do not check for internet connection, recommended to use in sync jobs.
968
+ $( [[ ${GUPLOAD_INSTALLED_WITH} = script ]] && printf ' %s\n' ' \n -u | --update - Update the installed script in your system.\n
969
+ -U | --uninstall - Uninstall script, remove related files.\n' )
969
970
--info - Show detailed info, only if script is installed system wide.\n
970
- -U | --uninstall - Uninstall script, remove related files.\n
971
971
-D | --debug - Display script command trace.\n
972
972
-h | --help - Display this message.\n"
973
973
exit 0
@@ -978,71 +978,6 @@ _short_help() {
978
978
exit 0
979
979
}
980
980
981
- # ##################################################
982
- # Automatic updater, only update if script is installed system wide.
983
- # Globals: 5 variables, 2 functions
984
- # COMMAND_NAME, REPO, INSTALL_PATH, TYPE, TYPE_VALUE | _update, _update_value
985
- # Arguments: None
986
- # Result: On
987
- # Update if AUTO_UPDATE_INTERVAL + LAST_UPDATE_TIME less than printf "%(%s)T\\n" "-1"
988
- # ##################################################
989
- _auto_update () {
990
- export REPO
991
- command -v " ${COMMAND_NAME} " 1> /dev/null &&
992
- if [[ -n " ${REPO: +${COMMAND_NAME: +${INSTALL_PATH: +${TYPE: +${TYPE_VALUE} } } } } " ]]; then
993
- current_time=" $( printf " %(%s)T\\ n" " -1" ) "
994
- [[ $(( LAST_UPDATE_TIME + AUTO_UPDATE_INTERVAL)) -lt ${current_time} ]] && _update
995
- _update_value LAST_UPDATE_TIME " ${current_time} "
996
- fi
997
- return 0
998
- }
999
-
1000
- # ##################################################
1001
- # Install/Update/uninstall the script.
1002
- # Globals: 4 variables
1003
- # Varibles - HOME, REPO, TYPE_VALUE, GLOBAL_INSTALL
1004
- # Arguments: 1
1005
- # ${1} = uninstall or update
1006
- # Result: On
1007
- # ${1} = nothing - Update the script if installed, otherwise install.
1008
- # ${1} = uninstall - uninstall the script
1009
- # ##################################################
1010
- _update () {
1011
- declare job=" ${1:- update} "
1012
- [[ ${GLOBAL_INSTALL} = true ]] && ! [[ $( id -u) = 0 ]] && printf " %s\n" " Error: Need root access to update." && return 0
1013
- [[ ${job} =~ uninstall ]] && job_uninstall=" --uninstall"
1014
- _print_center " justify" " Fetching ${job} script.." " -"
1015
- declare repo=" ${REPO:- labbots/ google-drive-upload} " type_value=" ${TYPE_VALUE:- latest} " cmd=" ${COMMAND_NAME:- gupload} " path=" ${INSTALL_PATH:- ${HOME} / .google-drive-upload/ bin} "
1016
- { [[ ${TYPE:- } != branch ]] && type_value=" $( _get_latest_sha release " ${type_value} " " ${repo} " ) " ; } || :
1017
- if script=" $( curl --compressed -Ls " https://github.com/${repo} /raw/${type_value} /install.sh" ) " ; then
1018
- _clear_line 1
1019
- printf " %s\n" " ${script} " | bash -s -- ${job_uninstall:- } --skip-internet-check --cmd " ${cmd} " --path " ${path} "
1020
- current_time=" $( printf " %(%s)T\\ n" " -1" ) "
1021
- [[ -z ${job_uninstall} ]] && _update_value LAST_UPDATE_TIME " ${current_time} " &
1022
- else
1023
- _clear_line 1
1024
- " ${QUIET:- _print_center} " " justify" " Error: Cannot download ${job} script." " =" 1>&2
1025
- return 1
1026
- fi
1027
- return 0
1028
- }
1029
-
1030
- # ##################################################
1031
- # Update in-script values
1032
- # ##################################################
1033
- _update_value () {
1034
- declare command_path=" ${INSTALL_PATH:? } /${COMMAND_NAME} " \
1035
- value_name=" ${1:- } " value=" ${2:- } " script_without_value_and_shebang
1036
- script_without_value_and_shebang=" $( grep -v " ${value_name} =\" .*\" .* # added values" " ${command_path} " | sed 1d) "
1037
- new_script=" $(
1038
- sed -n 1p " ${command_path} "
1039
- printf " %s\n" " ${value_name} =\" ${value} \" # added values"
1040
- printf " %s\n" " ${script_without_value_and_shebang} "
1041
- ) "
1042
- chmod +w " ${command_path} " && printf " %s\n" " ${new_script} " > | " ${command_path} " && chmod -w " ${command_path} "
1043
- return 0
1044
- }
1045
-
1046
981
# ##################################################
1047
982
# Print info if installed
1048
983
# Globals: 7 variable
@@ -1142,8 +1077,6 @@ _setup_arguments() {
1142
1077
case " ${1} " in
1143
1078
-h | --help) _usage ;;
1144
1079
-D | --debug) DEBUG=" true" && export DEBUG ;;
1145
- -u | --update) _check_debug && _update && exit " ${?} " ;;
1146
- --uninstall) _check_debug && _update uninstall && exit " ${?} " ;;
1147
1080
--info) _version_info ;;
1148
1081
-c | -C | --create-dir)
1149
1082
_check_longoptions " ${1} " " ${2} "
@@ -1229,6 +1162,12 @@ _setup_arguments() {
1229
1162
' ' ) shorthelp ;;
1230
1163
* ) # Check if user meant it to be a flag
1231
1164
if [[ ${1} = -* ]]; then
1165
+ [[ ${GUPLOAD_INSTALLED_WITH} = script ]] && {
1166
+ case " ${1} " in
1167
+ -u | --update) _check_debug && _update && exit " ${?} " ;;
1168
+ --uninstall) _check_debug && _update uninstall && exit " ${?} " ;;
1169
+ esac
1170
+ }
1232
1171
printf ' %s: %s: Unknown option\nTry ' " %s -h/--help" ' for more information.\n' " ${0##*/ } " " ${1} " " ${0##*/ } " && exit 1
1233
1172
else
1234
1173
if [[ ${1} =~ (drive.google.com| docs.google.com) ]]; then
@@ -1700,7 +1639,7 @@ main() {
1700
1639
printf " \n\n%s\n" " Script exited manually."
1701
1640
kill -- -$$ &
1702
1641
else
1703
- { _cleanup_config " ${CONFIG} " && _auto_update; } 1> | /dev/null &
1642
+ { _cleanup_config " ${CONFIG} " && [[ ${GUPLOAD_INSTALLED_WITH} = script ]] && _auto_update; } 1> | /dev/null &
1704
1643
fi
1705
1644
} 2> | /dev/null || :
1706
1645
return 0
0 commit comments