--- wgetpaste-2.29/wgetpaste 2019-06-12 20:56:03.000000000 +0000 +++ wgetpaste-2.30/wgetpaste 2020-07-31 21:56:05.000000000 +0000 @@ -3,7 +3,7 @@ # relying only on bash, sed, coreutils (mktemp/sort/tr/wc/whoami/tee) and wget # Copyright (c) 2007-2016 Bo Ørsted Andresen -VERSION="2.29" +VERSION="2.30" # don't inherit LANGUAGE from the env unset LANGUAGE @@ -13,7 +13,7 @@ N=$'\n' ### services -SERVICES="codepad bpaste dpaste gists" +SERVICES="codepad bpaste dpaste gists snippets" # bpaste ENGINE_bpaste=pinnwand URL_bpaste="https://bpaste.net/" @@ -36,6 +36,10 @@ ENGINE_tinyurl=tinyurl URL_tinyurl="http://tinyurl.com/ api-create.php" REGEX_RAW_tinyurl='s|^\(http://[^/]*/\)\([[:alnum:]]*\)$|\1\2|' +# snippets +ENGINE_snippets=snippets +URL_snippets="https://gitlab.com/api/v4/snippets" +ADDITIONAL_HEADERS_snippets=("Content-Type: application/json") ### engines # codepad @@ -88,6 +92,15 @@ [[ "$language" = auto ]] && language="" || language=".$language" echo "{\"description\":\"${description}\",\"public\":\"${PUBLIC_gists}\",\"files\":{\"${description//\/}${language}\":{\"content\":\"${content}\"}}" } +# snippets +REGEX_URL_snippets='s|.*"web_url":"\([^"]*\)".*|\1|p' +REGEX_RAW_snippets='s|^\(.*/snippets\)\(/.*\)$|\1\2/raw|' +escape_description_snippets() { sed -e 's|"|\\"|g' -e 's|\x1b|\\u001b|g' -e 's|\r||g' <<< "$*"; } +escape_input_snippets() { sed -e 's|\\|\\\\|g' -e 's|\x1b|\\u001b|g' -e 's|\r||g' -e 's|\t|\\t|g' -e 's|"|\\"|g' -e 's|$|\\n|' <<< "$*" | tr -d '\n'; } +json_snippets() { + local description="${1}" content="${3}" + echo "{\"title\": \"${description}\", \"content\": \"${content}\", \"description\": \"${description}\", \"file_name\": \"${description}\", \"visibility\": \"${VISIBILITY_snippets}\" }" +} # lodgeit LANGUAGES_lodgeit="ABAP ActionScript ActionScript%3 Ada ANTLR ANTLR%With%ActionScript%Target \ ANTLR%With%CPP%Target ANTLR%With%C#%Target ANTLR%With%Java%Target ANTLR%With%ObjectiveC%Target \ @@ -181,7 +194,8 @@ xml+velocity xml xquery xslt xtend yaml" EXPIRATIONS_pinnwand="1day 1week 1month never" POST_pinnwand="submit=Paste! % % lexer expiry % code" -REGEX_RAW_pinnwand='s|^\(https\?://[^/]*/\)show\(/[[:alnum:]]*/\?\)$|\1raw\2|' +REGEX_LOC_pinnwand="\(/show/[^ ]*\).*$|https://bpaste.net\1" +REGEX_RAW_pinnwand='s|^\(https\?://[^/]*/\)show\(/[^ ]*/\?\)$|\1raw\2|' ### errors die() { @@ -408,10 +422,15 @@ An additional http header can be passed by setting HEADER_\${SERVICE} in any of the configuration files mentioned above. For example, authenticating with github gist: -HEADER_gists="Authorization: token 1234abc56789..." +HEADER_gists="Authorization: token 1234abc56789...", or with gitlab snippets: +HEADER_snippets="PRIVATE-TOKEN: 1234abc56789..." -In the case of github gist you can also set PUBLIC_gists='false' if you want to -default to secret instead of public gists. +You can also set PUBLIC_gists='false' if you want to default to secret instead of +public github gists. In the case of gitlab, you can set VISIBILITY_snippets= to +'public', 'private' or 'internal'" + +To change your gitlab server, you can override the default API URL setting +URL_snippets='https://gitlab.[server].com/api/v4/snippets' EOF } @@ -550,14 +569,19 @@ # get url from response from server geturl() { - local regex + local regex location regex=REGEX_URL_$ENGINE + location=REGEX_LOC_$ENGINE if [[ -n ${!regex} ]]; then [[ needstdout = $1 ]] && return 0 sed -n -e "${!regex}" <<< "$*" + elif [[ -n ${!location} ]]; then + [[ needstdout = $1 ]] && return 1 + sed -n -e "s|^.*Location: ${!location}|p" <<< "$*" else [[ needstdout = $1 ]] && return 1 - sed -n -e 's|^.*Location: \(https\{0,1\}://[^ ]*\).*$|\1|p' <<< "$*" + svc_url=URL_$SERVICE + sed -n -e "s|^.*Location: \\(${!svc_url}[^ ]*\\).*$|\\1|p" <<< "$*" fi | tail -n1 } @@ -734,6 +758,9 @@ PUBLIC_gists=${PUBLIC_gists:-true} [[ "${PUBLIC_gists}" = "true" || "${PUBLIC_gists}" = "false" ]] || die "Invalid setting for PUBLIC_gists. Can either be 'true' or 'false' not '${PUBLIC_gists}'" +VISIBILITY_snippets=${VISIBILITY_snippets:-public} +[[ "${VISIBILITY_snippets}" = "public" || "${VISIBILITY_snippets}" = "private" || "${VISIBILITY_snippets}" = "internal" ]] || die "Invalid setting for VISIBILITY_snippets. Can either be 'public', 'private' or 'internal' not '${VISIBILITY_snippets}'" + INFO_COMMAND=${INFO_COMMAND:-"emerge --info"} INFO_ARGS=${INFO_ARGS:-"--ignore-default-opts"} @@ -913,12 +940,23 @@ WGETEXTRAHEADER="" fi + # build additional headers + additional_headers="ADDITIONAL_HEADERS_$SERVICE" + WGETADDITIONALHEADERS=() + if [[ -n "${!additional_headers}" ]]; then + tmp=$additional_headers[@] + for i in "${!tmp}" + do + WGETADDITIONALHEADERS+=("--header=${i}") + done + fi + # paste it WGETARGS="--tries=5 --timeout=60 $WGETARGS" if geturl needstdout ; then - OUTPUT=$(LC_ALL=C wget -O - $WGETARGS ${WGETEXTRAHEADER:+"$WGETEXTRAHEADER"} $RECIPIENT 2>&1) + OUTPUT=$(LC_ALL=C wget -O - $WGETARGS ${WGETEXTRAHEADER:+"$WGETEXTRAHEADER"} ${WGETADDITIONALHEADERS[@]:+"${WGETADDITIONALHEADERS[@]}"} $RECIPIENT 2>&1) else - OUTPUT=$(LC_ALL=C wget -O /dev/null $WGETARGS ${WGETEXTRAHEADER:+"$WGETEXTRAHEADER"} $RECIPIENT 2>&1) + OUTPUT=$(LC_ALL=C wget -O /dev/null $WGETARGS ${WGETEXTRAHEADER:+"$WGETEXTRAHEADER"} ${WGETADDITIONALHEADERS[@]:+"${WGETADDITIONALHEADERS[@]}"} $RECIPIENT 2>&1) fi # clean temporary file if it was created