From 752a38cb84436a6df6cac9f9beb9bed0bf60bc79 Mon Sep 17 00:00:00 2001 From: root Date: Sun, 31 Mar 2024 23:33:33 +0300 Subject: [PATCH] first commit --- add-system-script.sh | 27 +++++++++++++++++++++++++++ script.txt | 3 +++ text-file-to-json.rb | 13 +++++++++++++ 3 files changed, 43 insertions(+) create mode 100755 add-system-script.sh create mode 100644 script.txt create mode 100755 text-file-to-json.rb 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)