various fixes in scn_send script
This commit is contained in:
parent
c46190c3fc
commit
2fbc892898
@ -36,7 +36,7 @@ usage<span class="o">()</span><span class="w"> </span><span class="o">{</span>
|
||||
|
||||
<span class="nv">args</span><span class="o">=(</span><span class="w"> </span><span class="s2">"</span><span class="nv">$@</span><span class="s2">"</span><span class="w"> </span><span class="o">)</span>
|
||||
|
||||
<span class="nv">title</span><span class="o">=</span><span class="nv">$1</span>
|
||||
<span class="nv">title</span><span class="o">=</span><span class="s2">""</span>
|
||||
<span class="nv">content</span><span class="o">=</span><span class="s2">""</span>
|
||||
<span class="nv">channel</span><span class="o">=</span><span class="s2">""</span>
|
||||
<span class="nv">priority</span><span class="o">=</span><span class="m">1</span>
|
||||
@ -52,7 +52,7 @@ usage<span class="o">()</span><span class="w"> </span><span class="o">{</span>
|
||||
|
||||
<span class="k">if</span><span class="w"> </span><span class="o">[[</span><span class="w"> </span><span class="s2">"</span><span class="si">${</span><span class="nv">args</span><span class="p">[0]</span><span class="si">}</span><span class="s2">"</span><span class="w"> </span><span class="o">=</span>~<span class="w"> </span>^@.*<span class="w"> </span><span class="o">]]</span><span class="p">;</span><span class="w"> </span><span class="k">then</span>
|
||||
<span class="w"> </span><span class="nv">channel</span><span class="o">=</span><span class="s2">"</span><span class="si">${</span><span class="nv">args</span><span class="p">[0]</span><span class="si">}</span><span class="s2">"</span>
|
||||
<span class="w"> </span><span class="nb">unset</span><span class="w"> </span><span class="s2">"args[0]"</span>
|
||||
<span class="w"> </span><span class="nv">args</span><span class="o">=(</span><span class="s2">"</span><span class="si">${</span><span class="nv">args</span><span class="p">[@]:</span><span class="nv">1</span><span class="si">}</span><span class="s2">"</span><span class="o">)</span>
|
||||
<span class="w"> </span><span class="nv">channel</span><span class="o">=</span><span class="s2">"</span><span class="si">${</span><span class="nv">channel</span><span class="p">:</span><span class="nv">1</span><span class="si">}</span><span class="s2">"</span>
|
||||
<span class="k">fi</span>
|
||||
|
||||
@ -63,24 +63,49 @@ usage<span class="o">()</span><span class="w"> </span><span class="o">{</span>
|
||||
<span class="k">fi</span>
|
||||
|
||||
<span class="nv">title</span><span class="o">=</span><span class="s2">"</span><span class="si">${</span><span class="nv">args</span><span class="p">[0]</span><span class="si">}</span><span class="s2">"</span>
|
||||
<span class="nv">args</span><span class="o">=(</span><span class="s2">"</span><span class="si">${</span><span class="nv">args</span><span class="p">[@]:</span><span class="nv">1</span><span class="si">}</span><span class="s2">"</span><span class="o">)</span>
|
||||
|
||||
<span class="nv">content</span><span class="o">=</span><span class="s2">""</span>
|
||||
|
||||
<span class="k">if</span><span class="w"> </span><span class="o">[</span><span class="w"> </span><span class="si">${#</span><span class="nv">args</span><span class="p">[@]</span><span class="si">}</span><span class="w"> </span>-gt<span class="w"> </span><span class="m">1</span><span class="w"> </span><span class="o">]</span><span class="p">;</span><span class="w"> </span><span class="k">then</span>
|
||||
<span class="k">if</span><span class="w"> </span><span class="o">[</span><span class="w"> </span><span class="si">${#</span><span class="nv">args</span><span class="p">[@]</span><span class="si">}</span><span class="w"> </span>-gt<span class="w"> </span><span class="m">0</span><span class="w"> </span><span class="o">]</span><span class="p">;</span><span class="w"> </span><span class="k">then</span>
|
||||
<span class="w"> </span><span class="nv">content</span><span class="o">=</span><span class="s2">"</span><span class="si">${</span><span class="nv">args</span><span class="p">[0]</span><span class="si">}</span><span class="s2">"</span>
|
||||
<span class="w"> </span><span class="nb">unset</span><span class="w"> </span><span class="s2">"args[0]"</span>
|
||||
<span class="w"> </span><span class="nv">args</span><span class="o">=(</span><span class="s2">"</span><span class="si">${</span><span class="nv">args</span><span class="p">[@]:</span><span class="nv">1</span><span class="si">}</span><span class="s2">"</span><span class="o">)</span>
|
||||
<span class="k">fi</span>
|
||||
|
||||
<span class="k">if</span><span class="w"> </span><span class="o">[</span><span class="w"> </span><span class="si">${#</span><span class="nv">args</span><span class="p">[@]</span><span class="si">}</span><span class="w"> </span>-gt<span class="w"> </span><span class="m">1</span><span class="w"> </span><span class="o">]</span><span class="p">;</span><span class="w"> </span><span class="k">then</span>
|
||||
<span class="k">if</span><span class="w"> </span><span class="o">[</span><span class="w"> </span><span class="si">${#</span><span class="nv">args</span><span class="p">[@]</span><span class="si">}</span><span class="w"> </span>-gt<span class="w"> </span><span class="m">0</span><span class="w"> </span><span class="o">]</span><span class="p">;</span><span class="w"> </span><span class="k">then</span>
|
||||
<span class="w"> </span><span class="nv">priority</span><span class="o">=</span><span class="s2">"</span><span class="si">${</span><span class="nv">args</span><span class="p">[0]</span><span class="si">}</span><span class="s2">"</span>
|
||||
<span class="w"> </span><span class="nb">unset</span><span class="w"> </span><span class="s2">"args[0]"</span>
|
||||
<span class="w"> </span><span class="nv">args</span><span class="o">=(</span><span class="s2">"</span><span class="si">${</span><span class="nv">args</span><span class="p">[@]:</span><span class="nv">1</span><span class="si">}</span><span class="s2">"</span><span class="o">)</span>
|
||||
<span class="k">fi</span>
|
||||
|
||||
<span class="k">if</span><span class="w"> </span><span class="o">[</span><span class="w"> </span><span class="si">${#</span><span class="nv">args</span><span class="p">[@]</span><span class="si">}</span><span class="w"> </span>-gt<span class="w"> </span><span class="m">1</span><span class="w"> </span><span class="o">]</span><span class="p">;</span><span class="w"> </span><span class="k">then</span>
|
||||
<span class="w"> </span>rederr<span class="w"> </span><span class="s2">"Too many arguments to scn_send"</span>
|
||||
<span class="w"> </span>usage
|
||||
<span class="w"> </span><span class="nb">exit</span><span class="w"> </span><span class="m">1</span>
|
||||
<span class="k">if</span><span class="w"> </span><span class="o">[</span><span class="w"> </span><span class="si">${#</span><span class="nv">args</span><span class="p">[@]</span><span class="si">}</span><span class="w"> </span>-gt<span class="w"> </span><span class="m">0</span><span class="w"> </span><span class="o">]</span><span class="p">;</span><span class="w"> </span><span class="k">then</span>
|
||||
<span class="w"> </span>rederr<span class="w"> </span><span class="s2">"Too many arguments to scn_send"</span>
|
||||
<span class="w"> </span>usage
|
||||
<span class="w"> </span><span class="nb">exit</span><span class="w"> </span><span class="m">1</span>
|
||||
<span class="k">fi</span>
|
||||
|
||||
<span class="nv">curlparams</span><span class="o">=()</span>
|
||||
|
||||
<span class="nv">curlparams</span><span class="o">+=(</span><span class="w"> </span><span class="s2">"--data"</span><span class="w"> </span><span class="s2">"user_id=</span><span class="si">${</span><span class="nv">SCN_UID</span><span class="si">}</span><span class="s2">"</span><span class="w"> </span><span class="o">)</span>
|
||||
<span class="nv">curlparams</span><span class="o">+=(</span><span class="w"> </span><span class="s2">"--data"</span><span class="w"> </span><span class="s2">"key=</span><span class="si">${</span><span class="nv">SCN_KEY</span><span class="si">}</span><span class="s2">"</span><span class="w"> </span><span class="o">)</span>
|
||||
<span class="nv">curlparams</span><span class="o">+=(</span><span class="w"> </span><span class="s2">"--data"</span><span class="w"> </span><span class="s2">"title=</span><span class="nv">$title</span><span class="s2">"</span><span class="w"> </span><span class="o">)</span>
|
||||
<span class="nv">curlparams</span><span class="o">+=(</span><span class="w"> </span><span class="s2">"--data"</span><span class="w"> </span><span class="s2">"timestamp=</span><span class="nv">$sendtime</span><span class="s2">"</span><span class="w"> </span><span class="o">)</span>
|
||||
<span class="nv">curlparams</span><span class="o">+=(</span><span class="w"> </span><span class="s2">"--data"</span><span class="w"> </span><span class="s2">"msg_id=</span><span class="nv">$usr_msg_id</span><span class="s2">"</span><span class="w"> </span><span class="o">)</span>
|
||||
|
||||
<span class="k">if</span><span class="w"> </span><span class="o">[[</span><span class="w"> </span>-n<span class="w"> </span><span class="s2">"</span><span class="nv">$content</span><span class="s2">"</span><span class="w"> </span><span class="o">]]</span><span class="p">;</span><span class="w"> </span><span class="k">then</span>
|
||||
<span class="w"> </span><span class="nv">curlparams</span><span class="o">+=(</span><span class="s2">"--data"</span><span class="w"> </span><span class="s2">"content=</span><span class="nv">$content</span><span class="s2">"</span><span class="o">)</span>
|
||||
<span class="k">fi</span>
|
||||
|
||||
<span class="k">if</span><span class="w"> </span><span class="o">[[</span><span class="w"> </span>-n<span class="w"> </span><span class="s2">"</span><span class="nv">$priority</span><span class="s2">"</span><span class="w"> </span><span class="o">]]</span><span class="p">;</span><span class="w"> </span><span class="k">then</span>
|
||||
<span class="w"> </span><span class="nv">curlparams</span><span class="o">+=(</span><span class="s2">"--data"</span><span class="w"> </span><span class="s2">"priority=</span><span class="nv">$priority</span><span class="s2">"</span><span class="o">)</span>
|
||||
<span class="k">fi</span>
|
||||
|
||||
<span class="k">if</span><span class="w"> </span><span class="o">[[</span><span class="w"> </span>-n<span class="w"> </span><span class="s2">"</span><span class="nv">$channel</span><span class="s2">"</span><span class="w"> </span><span class="o">]]</span><span class="p">;</span><span class="w"> </span><span class="k">then</span>
|
||||
<span class="w"> </span><span class="nv">curlparams</span><span class="o">+=(</span><span class="s2">"--data"</span><span class="w"> </span><span class="s2">"channel=</span><span class="nv">$channel</span><span class="s2">"</span><span class="o">)</span>
|
||||
<span class="k">fi</span>
|
||||
|
||||
<span class="k">if</span><span class="w"> </span><span class="o">[[</span><span class="w"> </span>-n<span class="w"> </span><span class="s2">"</span><span class="nv">$sender</span><span class="s2">"</span><span class="w"> </span><span class="o">]]</span><span class="p">;</span><span class="w"> </span><span class="k">then</span>
|
||||
<span class="w"> </span><span class="nv">curlparams</span><span class="o">+=(</span><span class="s2">"--data"</span><span class="w"> </span><span class="s2">"sender_name=</span><span class="nv">$sender</span><span class="s2">"</span><span class="o">)</span>
|
||||
<span class="k">fi</span>
|
||||
|
||||
<span class="k">while</span><span class="w"> </span><span class="nb">true</span><span class="w"> </span><span class="p">;</span><span class="w"> </span><span class="k">do</span>
|
||||
|
||||
@ -89,15 +114,7 @@ usage<span class="o">()</span><span class="w"> </span><span class="o">{</span>
|
||||
<span class="w"> </span><span class="nv">curlresp</span><span class="o">=</span><span class="k">$(</span>curl<span class="w"> </span>--silent<span class="w"> </span><span class="se">\</span>
|
||||
<span class="w"> </span>--output<span class="w"> </span><span class="s2">"</span><span class="si">${</span><span class="nv">outf</span><span class="si">}</span><span class="s2">"</span><span class="w"> </span><span class="se">\</span>
|
||||
<span class="w"> </span>--write-out<span class="w"> </span><span class="s2">"%{http_code}"</span><span class="w"> </span><span class="se">\</span>
|
||||
<span class="w"> </span>--data<span class="w"> </span><span class="s2">"user_id=</span><span class="nv">$user_id</span><span class="s2">"</span><span class="w"> </span><span class="se">\</span>
|
||||
<span class="w"> </span>--data<span class="w"> </span><span class="s2">"key=</span><span class="nv">$user_key</span><span class="s2">"</span><span class="w"> </span><span class="se">\</span>
|
||||
<span class="w"> </span>--data<span class="w"> </span><span class="s2">"title=</span><span class="nv">$title</span><span class="s2">"</span><span class="w"> </span><span class="se">\</span>
|
||||
<span class="w"> </span>--data<span class="w"> </span><span class="s2">"timestamp=</span><span class="nv">$sendtime</span><span class="s2">"</span><span class="w"> </span><span class="se">\</span>
|
||||
<span class="w"> </span>--data<span class="w"> </span><span class="s2">"content=</span><span class="nv">$content</span><span class="s2">"</span><span class="w"> </span><span class="se">\</span>
|
||||
<span class="w"> </span>--data<span class="w"> </span><span class="s2">"priority=</span><span class="nv">$priority</span><span class="s2">"</span><span class="w"> </span><span class="se">\</span>
|
||||
<span class="w"> </span>--data<span class="w"> </span><span class="s2">"msg_id=</span><span class="nv">$usr_msg_id</span><span class="s2">"</span><span class="w"> </span><span class="se">\</span>
|
||||
<span class="w"> </span>--data<span class="w"> </span><span class="s2">"channel=</span><span class="nv">$channel</span><span class="s2">"</span><span class="w"> </span><span class="se">\</span>
|
||||
<span class="w"> </span>--data<span class="w"> </span><span class="s2">"sender_name=</span><span class="nv">$sender</span><span class="s2">"</span><span class="w"> </span><span class="se">\</span>
|
||||
<span class="w"> </span><span class="s2">"</span><span class="si">${</span><span class="nv">curlparams</span><span class="p">[@]</span><span class="si">}</span><span class="s2">"</span><span class="w"> </span><span class="se">\</span>
|
||||
<span class="w"> </span><span class="s2">"https://simplecloudnotifier.de/"</span><span class="w"> </span><span class="k">)</span>
|
||||
|
||||
<span class="w"> </span><span class="nv">curlout</span><span class="o">=</span><span class="s2">"</span><span class="k">$(</span>cat<span class="w"> </span><span class="s2">"</span><span class="nv">$outf</span><span class="s2">"</span><span class="k">)</span><span class="s2">"</span>
|
||||
|
@ -36,7 +36,7 @@ function green() { if cfgcol; then echo -e "\x1B[32m$1\x1B[0m"; else ec
|
||||
|
||||
args=( "$@" )
|
||||
|
||||
title=$1
|
||||
title=""
|
||||
content=""
|
||||
channel=""
|
||||
priority=1
|
||||
@ -52,7 +52,7 @@ fi
|
||||
|
||||
if [[ "${args[0]}" =~ ^@.* ]]; then
|
||||
channel="${args[0]}"
|
||||
unset "args[0]"
|
||||
args=("${args[@]:1}")
|
||||
channel="${channel:1}"
|
||||
fi
|
||||
|
||||
@ -63,24 +63,49 @@ if [ ${#args[@]} -lt 1 ]; then
|
||||
fi
|
||||
|
||||
title="${args[0]}"
|
||||
args=("${args[@]:1}")
|
||||
|
||||
content=""
|
||||
|
||||
if [ ${#args[@]} -gt 1 ]; then
|
||||
if [ ${#args[@]} -gt 0 ]; then
|
||||
content="${args[0]}"
|
||||
unset "args[0]"
|
||||
args=("${args[@]:1}")
|
||||
fi
|
||||
|
||||
if [ ${#args[@]} -gt 1 ]; then
|
||||
if [ ${#args[@]} -gt 0 ]; then
|
||||
priority="${args[0]}"
|
||||
unset "args[0]"
|
||||
args=("${args[@]:1}")
|
||||
fi
|
||||
|
||||
if [ ${#args[@]} -gt 1 ]; then
|
||||
rederr "Too many arguments to scn_send"
|
||||
usage
|
||||
exit 1
|
||||
if [ ${#args[@]} -gt 0 ]; then
|
||||
rederr "Too many arguments to scn_send"
|
||||
usage
|
||||
exit 1
|
||||
fi
|
||||
|
||||
curlparams=()
|
||||
|
||||
curlparams+=( "--data" "user_id=${SCN_UID}" )
|
||||
curlparams+=( "--data" "key=${SCN_KEY}" )
|
||||
curlparams+=( "--data" "title=$title" )
|
||||
curlparams+=( "--data" "timestamp=$sendtime" )
|
||||
curlparams+=( "--data" "msg_id=$usr_msg_id" )
|
||||
|
||||
if [[ -n "$content" ]]; then
|
||||
curlparams+=("--data" "content=$content")
|
||||
fi
|
||||
|
||||
if [[ -n "$priority" ]]; then
|
||||
curlparams+=("--data" "priority=$priority")
|
||||
fi
|
||||
|
||||
if [[ -n "$channel" ]]; then
|
||||
curlparams+=("--data" "channel=$channel")
|
||||
fi
|
||||
|
||||
if [[ -n "$sender" ]]; then
|
||||
curlparams+=("--data" "sender_name=$sender")
|
||||
fi
|
||||
|
||||
while true ; do
|
||||
|
||||
@ -89,15 +114,7 @@ while true ; do
|
||||
curlresp=$(curl --silent \
|
||||
--output "${outf}" \
|
||||
--write-out "%{http_code}" \
|
||||
--data "user_id=$user_id" \
|
||||
--data "key=$user_key" \
|
||||
--data "title=$title" \
|
||||
--data "timestamp=$sendtime" \
|
||||
--data "content=$content" \
|
||||
--data "priority=$priority" \
|
||||
--data "msg_id=$usr_msg_id" \
|
||||
--data "channel=$channel" \
|
||||
--data "sender_name=$sender" \
|
||||
"${curlparams[@]}" \
|
||||
"https://simplecloudnotifier.de/" )
|
||||
|
||||
curlout="$(cat "$outf")"
|
||||
|
Loading…
Reference in New Issue
Block a user