commit 752a38cb84436a6df6cac9f9beb9bed0bf60bc79 Author: root Date: Sun Mar 31 23:33:33 2024 +0300 first commit diff --git a/add-system-script.sh b/add-system-script.sh new file mode 100755 index 0000000..1d10413 --- /dev/null +++ b/add-system-script.sh @@ -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 diff --git a/script.txt b/script.txt new file mode 100644 index 0000000..0623b9a --- /dev/null +++ b/script.txt @@ -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; + diff --git a/text-file-to-json.rb b/text-file-to-json.rb new file mode 100755 index 0000000..383dd29 --- /dev/null +++ b/text-file-to-json.rb @@ -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)