mirror of
https://github.com/MOIS3Y/logs-collector.git
synced 2025-02-01 01:10:52 +01:00
Modify: uploader.sh url option changed to dst to upload the file, only need to specify the domain name
This commit is contained in:
parent
405d7da754
commit
baacd46248
@ -2,13 +2,15 @@
|
|||||||
|
|
||||||
|
|
||||||
# INIT GLOBAL VARIABLES:
|
# INIT GLOBAL VARIABLES:
|
||||||
_VERSION="0.1.0"
|
_VERSION="0.1.1"
|
||||||
_PACKGMGR="apt yum"
|
_PKGMGR="apt yum"
|
||||||
_SCRIPT_NAME="$0"
|
_SCRIPT_NAME="$0"
|
||||||
_CMD="curl"
|
_CMD="curl"
|
||||||
_FILE=""
|
_FILE=""
|
||||||
_TOKEN=""
|
_TOKEN=""
|
||||||
_URL=""
|
_DST=""
|
||||||
|
_PROTO="https://"
|
||||||
|
_API_PATH="/api/v1/archives/"
|
||||||
|
|
||||||
|
|
||||||
# Colorize output
|
# Colorize output
|
||||||
@ -42,30 +44,32 @@ 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 " -u | --url target url $required\n"
|
printf " -d | --dst storage domain name $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 arguments
|
# parse user options
|
||||||
argparser() {
|
optparser() {
|
||||||
# count user-passed arguments:
|
# count user-passed options:
|
||||||
local count_arguments=$#
|
local count_options=$#
|
||||||
# run help if empty and exit:
|
# run help if empty and exit:
|
||||||
if [[ count_arguments -eq 0 ]]; then
|
if [[ count_options -eq 0 ]]; then
|
||||||
help
|
help
|
||||||
exit 2
|
exit 2
|
||||||
fi
|
fi
|
||||||
# parse args:
|
# parse opts:
|
||||||
while [ ! -z "$1" ]; do
|
while [ ! -z "$1" ]; do
|
||||||
case "$1" in
|
case "$1" in
|
||||||
--file|-f)
|
--file|-f)
|
||||||
@ -76,9 +80,9 @@ argparser() {
|
|||||||
shift
|
shift
|
||||||
_TOKEN="$1"
|
_TOKEN="$1"
|
||||||
;;
|
;;
|
||||||
--url|-u)
|
--dst|-d)
|
||||||
shift
|
shift
|
||||||
_URL="$1"
|
_DST="$1"
|
||||||
;;
|
;;
|
||||||
--help|-h)
|
--help|-h)
|
||||||
help
|
help
|
||||||
@ -102,12 +106,13 @@ argparser() {
|
|||||||
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_NAME\n"
|
printf "please install $error_cmd before run $script\n"
|
||||||
# Print how install curl (support only apt/yum):
|
# Print how install curl (support only apt/yum):
|
||||||
for pkgmgr in $_PACKGMGR; do
|
for pkgmgr in $_PKGMGR; do
|
||||||
if check_util_exists $pkgmgr; then
|
if check_util_exists $pkgmgr; then
|
||||||
printf "$(colorize GREEN "RUN"): $pkgmgr install $error_cmd"
|
printf "$(colorize GREEN "RUN"): $pkgmgr install $error_cmd\n"
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
exit 1
|
exit 1
|
||||||
@ -115,17 +120,17 @@ curl_is_exists() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
validate_args() {
|
validate_opts() {
|
||||||
if [[ -z $_URL ]]; then
|
if [[ -z $_DST ]]; then
|
||||||
printf "$(colorize RED "ERROR"): -u | --url argument is required\n"
|
printf "$(colorize RED "ERROR"): -d | --dst option is required\n"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
if [[ -z $_FILE ]]; then
|
if [[ -z $_FILE ]]; then
|
||||||
printf "$(colorize RED "ERROR"): -f | --file argument is required\n"
|
printf "$(colorize RED "ERROR"): -f | --file option is required\n"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
if [[ -z $_TOKEN ]]; then
|
if [[ -z $_TOKEN ]]; then
|
||||||
printf "$(colorize RED "ERROR"): -t | --token argument is required\n"
|
printf "$(colorize RED "ERROR"): -t | --token option is required\n"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
@ -134,12 +139,12 @@ validate_args() {
|
|||||||
# Upload file used curl
|
# Upload file used curl
|
||||||
# get $_URL $_FILE $_TOKEN
|
# get $_URL $_FILE $_TOKEN
|
||||||
upload() {
|
upload() {
|
||||||
local url=$1
|
local dst=$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' \
|
||||||
"${url}" \
|
"${_PROTO}${dst}${_API_PATH}" \
|
||||||
-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' \
|
||||||
@ -148,10 +153,10 @@ upload() {
|
|||||||
|
|
||||||
|
|
||||||
main () {
|
main () {
|
||||||
argparser $@
|
optparser $@
|
||||||
curl_is_exists
|
curl_is_exists
|
||||||
validate_args
|
validate_opts
|
||||||
upload $_URL $_FILE $_TOKEN
|
upload $_DST $_FILE $_TOKEN
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user