From 5e546fbee20bce6c78ccf562c9cde43500fe1b0c Mon Sep 17 00:00:00 2001 From: "Jose M. Guisado" Date: Sun, 13 Nov 2022 18:49:59 +0100 Subject: examples: add examples folder deploy-ubuntu.sh is a simple bash script combining multiple ogcli commands used to format and deploy some image. poweroff.cron is a sample cron file used to schedule client poweroff. --- examples/deploy-ubuntu.sh | 42 ++++++++++++++++++++++++++++++++++++++++++ examples/poweroff.cron | 11 +++++++++++ 2 files changed, 53 insertions(+) create mode 100755 examples/deploy-ubuntu.sh create mode 100644 examples/poweroff.cron (limited to 'examples') diff --git a/examples/deploy-ubuntu.sh b/examples/deploy-ubuntu.sh new file mode 100755 index 0000000..94541a4 --- /dev/null +++ b/examples/deploy-ubuntu.sh @@ -0,0 +1,42 @@ +#!/usr/bin/env bash + +function check_client_status { + local try=0 + local ip="$1" + local state="$2" + local max_tries=${3-10} + + while [ "$(./ogcli list clients | jq ".clients[] | select(.state != \"$state\" and .addr == \"$ip\")")" == "" ] + do + if [ "$try" -eq "$max_tries" ]; then + echo "Timeout!" + exit + fi + + try=$((try+1)) + echo "Waiting for client to exit from state $state..." + sleep 10 + done +} + +IP="192.168.56.11" + +echo "Sending WoL to client $IP" +./ogcli send wol --client-ip "$IP" + +check_client_status $IP "WOL_SENT" +echo "Client is ready... partitioning client" +./ogcli setup disk --type dos --num 1 --part 1,LINUX,EXT4,40G --part 4,CACHE,CACHE,10G --format 1,4 --client-ip "$IP" +# ./ogcli send refresh --client-ip "$IP" + +check_client_status $IP "BSY" +echo "Client is ready... restoring image" +./ogcli restore image --id 1 --disk 1 --part 1 --type tiptorrent --client-ip "$IP" + +check_client_status $IP "BSY" 100 +echo "Client is ready... setting boot mode to first disk first partition" +./ogcli set mode --mode 11 --client-ip "$IP" + +check_client_status $IP "BSY" +echo "Client is ready... shutting down client" +./ogcli send poweroff --client-ip "$IP" diff --git a/examples/poweroff.cron b/examples/poweroff.cron new file mode 100644 index 0000000..da4c476 --- /dev/null +++ b/examples/poweroff.cron @@ -0,0 +1,11 @@ +# This cron task automatically powers off all clients +# specified at 22:00 local time starting Monday until +# Friday. +# +# You can specify clients to shutdown using several parameters +# like --client-ip, --room-id, or even --center-id. +# +# Usually on debian based distros one can insert cron tasks +# using "crontab -e". + +0 22 * * 1-5 ogcli send poweroff --client-ip 192.168.56.11 -- cgit v1.2.3-18-g5258