Compare commits

..

No commits in common. "main" and "v0.1.0" have entirely different histories.
main ... v0.1.0

3 changed files with 27 additions and 49 deletions

View File

@ -313,22 +313,12 @@ Options:
-f | --file full path to upload file required -f | --file full path to upload file required
-t | --token access token required -t | --token access token required
-d | --dst storage domain name required -u | --url target url required
-v | --version print version -v | --version print version
-h | --help print help -h | --help print help
``` ```
#### Пример:
```sh
./uploader.sh \
--dst collector.domain.zone \
--token e63268f4-5946-42eb-a678-b02182f14e87 \
--file /root/logs/all-logs.tar.gz
```
## Лицензия ## Лицензия
GNU GPL 3.0 GNU GPL 3.0

View File

@ -316,20 +316,13 @@ Options:
-f | --file full path to upload file required -f | --file full path to upload file required
-t | --token access token required -t | --token access token required
-d | --dst storage domain name required -u | --url target url required
-v | --version print version -v | --version print version
-h | --help print help -h | --help print help
``` ```
#### Example:
```sh
./uploader.sh \
--dst collector.domain.zone \
--token e63268f4-5946-42eb-a678-b02182f14e87 \
--file /root/logs/all-logs.tar.gz
```
## License ## License

View File

@ -2,15 +2,13 @@
# INIT GLOBAL VARIABLES: # INIT GLOBAL VARIABLES:
_VERSION="0.1.1" _VERSION="0.1.0"
_PKGMGR="apt yum" _PACKGMGR="apt yum"
_SCRIPT_NAME="$0" _SCRIPT_NAME="$0"
_CMD="curl" _CMD="curl"
_FILE="" _FILE=""
_TOKEN="" _TOKEN=""
_DST="" _URL=""
_PROTO="https://"
_API_PATH="/api/v1/archives/"
# Colorize output # Colorize output
@ -44,32 +42,30 @@ check_util_exists() {
# Print help message how used it script # Print help message how used it script
help() { help() {
# colorize value
local script=$(colorize GREEN "$_SCRIPT_NAME") local script=$(colorize GREEN "$_SCRIPT_NAME")
local required=$(colorize RED "required") local required=$(colorize RED "required")
# help message
printf "Usage: $script [options [parameters]]\n" printf "Usage: $script [options [parameters]]\n"
printf "\n" printf "\n"
printf "Options:\n" printf "Options:\n"
printf "\n" printf "\n"
printf " -f | --file full path to upload file $required\n" printf " -f | --file full path to upload file $required\n"
printf " -t | --token access token $required\n" printf " -t | --token access token $required\n"
printf " -d | --dst storage domain name $required\n" printf " -u | --url target url $required\n"
printf " -v | --version print version\n" printf " -v | --version print version\n"
printf " -h | --help print help\n" printf " -h | --help print help\n"
} }
# parse user options # parse user arguments
optparser() { argparser() {
# count user-passed options: # count user-passed arguments:
local count_options=$# local count_arguments=$#
# run help if empty and exit: # run help if empty and exit:
if [[ count_options -eq 0 ]]; then if [[ count_arguments -eq 0 ]]; then
help help
exit 2 exit 2
fi fi
# parse opts: # parse args:
while [ ! -z "$1" ]; do while [ ! -z "$1" ]; do
case "$1" in case "$1" in
--file|-f) --file|-f)
@ -80,9 +76,9 @@ optparser() {
shift shift
_TOKEN="$1" _TOKEN="$1"
;; ;;
--dst|-d) --url|-u)
shift shift
_DST="$1" _URL="$1"
;; ;;
--help|-h) --help|-h)
help help
@ -106,13 +102,12 @@ optparser() {
curl_is_exists() { curl_is_exists() {
if ! check_util_exists $_CMD; then if ! check_util_exists $_CMD; then
local error_cmd=$(colorize RED "$_CMD") local error_cmd=$(colorize RED "$_CMD")
local script=$(colorize GREEN "$_SCRIPT_NAME")
printf "$(colorize RED "ERROR"): upload util doesn't exist, " printf "$(colorize RED "ERROR"): upload util doesn't exist, "
printf "please install $error_cmd before run $script\n" printf "please install $error_cmd before run $_SCRIPT_NAME\n"
# Print how install curl (support only apt/yum): # Print how install curl (support only apt/yum):
for pkgmgr in $_PKGMGR; do for pkgmgr in $_PACKGMGR; do
if check_util_exists $pkgmgr; then if check_util_exists $pkgmgr; then
printf "$(colorize GREEN "RUN"): $pkgmgr install $error_cmd\n" printf "$(colorize GREEN "RUN"): $pkgmgr install $error_cmd"
fi fi
done done
exit 1 exit 1
@ -120,17 +115,17 @@ curl_is_exists() {
} }
validate_opts() { validate_args() {
if [[ -z $_DST ]]; then if [[ -z $_URL ]]; then
printf "$(colorize RED "ERROR"): -d | --dst option is required\n" printf "$(colorize RED "ERROR"): -u | --url argument is required\n"
exit 1 exit 1
fi fi
if [[ -z $_FILE ]]; then if [[ -z $_FILE ]]; then
printf "$(colorize RED "ERROR"): -f | --file option is required\n" printf "$(colorize RED "ERROR"): -f | --file argument is required\n"
exit 1 exit 1
fi fi
if [[ -z $_TOKEN ]]; then if [[ -z $_TOKEN ]]; then
printf "$(colorize RED "ERROR"): -t | --token option is required\n" printf "$(colorize RED "ERROR"): -t | --token argument is required\n"
exit 1 exit 1
fi fi
} }
@ -139,12 +134,12 @@ validate_opts() {
# Upload file used curl # Upload file used curl
# get $_URL $_FILE $_TOKEN # get $_URL $_FILE $_TOKEN
upload() { upload() {
local dst=$1 local url=$1
local file=$2 local file=$2
local token=$3 local token=$3
# run: # run:
curl --progress-bar -X 'POST' \ curl --progress-bar -X 'POST' \
"${_PROTO}${dst}${_API_PATH}" \ "${url}" \
-H 'accept: application/json' \ -H 'accept: application/json' \
-H "Upload-Token: ${token} " \ -H "Upload-Token: ${token} " \
-H 'Content-Type: multipart/form-data' \ -H 'Content-Type: multipart/form-data' \
@ -153,10 +148,10 @@ upload() {
main () { main () {
optparser $@ argparser $@
curl_is_exists curl_is_exists
validate_opts validate_args
upload $_DST $_FILE $_TOKEN upload $_URL $_FILE $_TOKEN
} }