1
0
Fork 0
forked from ahurac/dotfiles
ahuarc-dotfiles/local/bin/wolf
Hippolyte Chauvin c1c1d8adbd Scripts
2023-04-13 00:04:20 +02:00

53 lines
861 B
Bash
Executable file

#!/bin/bash
# Arguments
hostname="$1"; shift
# Variables
declare mac
declare -a wol_com options
name="$(basename "$0")"
wolf_d="${HOME}/.wolf"
wolf_host="${wolf_d}/${hostname}"
# Functions
# Throw an error
function error {
>&2 echo -e "${name}: \033[1;31mERROR:\033[0m ${1:-No further details}"; shift
exit "${1:-1}"
}
# Parse variable in options file
function getvar {
grep '^'"$1"' ' "$wolf_host" | cut -d ' ' -f 2
}
# Parsing
[[ -f $wolf_host ]] || error "\"${hostname}\": No such host"
# Assign the options
mac="$(getvar Mac)"
ip="$(getvar IP)"
port="$(getvar Port)"
# Add options if necessary
[[ -n $ip ]] && options+=(-i "$ip" )
[[ -n $port ]] && options+=(-p "$port")
# Commands building
# wol
wol_com=(
wol
"$@"
"${options[@]}"
"$mac"
)
# Debug
#echo "${wol_com[@]}"
#exit 0
# Execution
set -xe
"${wol_com[@]}"