first commit

This commit is contained in:
root 2024-03-31 23:33:33 +03:00
commit 752a38cb84
3 changed files with 43 additions and 0 deletions

27
add-system-script.sh Executable file
View File

@ -0,0 +1,27 @@
#!/usr/bin/env bash
DEBUG="0"
set -x
ROUTEROS_HOST="$1"
USERNAME="$2"
PASSWORD="$3"
SCRIPT_NAME="$4"
SCRIPT_FILENAME="$5"
if [ ! -z "${SCRIPT_NAME}" ]
then
DATA=$( ruby text-file-to-json.rb ${SCRIPT_NAME} ${SCRIPT_FILENAME} )
ADD_RES=$(\
curl -q -k -u ${USERNAME}:${PASSWORD} -X POST "https://${ROUTEROS_HOST}/rest/system/script/add" \
-H "content-type: application/json" \
--data "${DATA}" \
)
echo "${ADD_RES}"
fi
set +x

3
script.txt Normal file
View File

@ -0,0 +1,3 @@
/tool/wol mac=00:00:00:00:00:00 interface=bridge;
/tool/wol mac=00:00:00:00:00:00 interface=ether4;

13
text-file-to-json.rb Executable file
View File

@ -0,0 +1,13 @@
#!/usr/bin/env ruby
require "json"
object = { "name" => "default", "source" => "" }
script_name = ARGV[0]
filename = ARGV[1]
object["name"] = script_name
object["source"] = File.open(filename).readlines.join("\r\n")
puts JSON.pretty_generate(object)