61 lines
1.3 KiB
Bash
Executable file
61 lines
1.3 KiB
Bash
Executable file
#!/usr/bin/env sh
|
|
|
|
INPUT_PATH=
|
|
CONFIG_PATH=
|
|
HOSTNAME=
|
|
PORT=
|
|
USER=
|
|
IDENTITY=
|
|
HOSTKEY=
|
|
|
|
save_input() {
|
|
input_file="$(mktemp -tp /tmp)"
|
|
cat > "$input_file" <&0
|
|
echo "$input_file"
|
|
return 0
|
|
}
|
|
|
|
read_config() {
|
|
HOSTNAME="$(jq -r .source.hostname < "$1")"
|
|
PORT="$(jq -r '.source.port // "22"' < "$1")"
|
|
USER="$(jq -r .source.user < "$1")"
|
|
IDENTITY="$(jq -r .source.identity < "$1")"
|
|
HOSTKEY="$(jq -r .source.hostkey < "$1")"
|
|
return 0
|
|
}
|
|
|
|
write_config() {
|
|
directory="$(mktemp -dp /tmp)"
|
|
config="$directory/config"
|
|
identity_file="$directory/identity"
|
|
knownhosts_file="$directory/knownhosts"
|
|
|
|
{
|
|
echo "host $HOSTNAME"
|
|
echo " HostName $HOSTNAME"
|
|
echo " Port $PORT"
|
|
echo " User $USER"
|
|
echo " IdentityFile $identity_file"
|
|
echo " UserKnownHostsFile $knownhosts_file"
|
|
} > "$config"
|
|
echo "$IDENTITY" > "$identity_file"
|
|
echo "$HOSTKEY" > "$knownhosts_file"
|
|
chmod 600 "$identity_file" "$knownhosts_file" "$config"
|
|
echo "$config"
|
|
return 0
|
|
}
|
|
|
|
INPUT_PATH="$(save_input)"
|
|
read_config "$INPUT_PATH"
|
|
CONFIG_PATH="$(write_config)"
|
|
|
|
export INPUT_PATH
|
|
export CONFIG_PATH
|
|
|
|
get_version() {
|
|
jq -r '.version // []' < "$INPUT_PATH"
|
|
}
|
|
|
|
get_files() {
|
|
jq -r '.source.files?[]' < "$INPUT_PATH"
|
|
}
|