69 lines
2.6 KiB
Bash
Executable File
69 lines
2.6 KiB
Bash
Executable File
#!/bin/bash
|
|
# skyweave_deploy.sh - Deploy Lua API script to RVLink roof unit (using SSH config alias)
|
|
|
|
# SSH alias for the roof unit (defined in ~/.ssh/config)
|
|
SSH_ALIAS="roof-unit"
|
|
|
|
# IP address for HTTP/curl access (SSH alias might not be resolvable for curl)
|
|
ROOF_IP="192.168.10.254"
|
|
# The user 'root' is assumed to be set in your ~/.ssh/config for the SSH_ALIAS
|
|
|
|
REMOTE_PATH="/www/cgi-bin/skyweave.lua"
|
|
REMOTE_HTTP_PORT="${2:-42069}" # Default to 42069 if not specified
|
|
|
|
# Local script path (default to skyweave.lua in current directory)
|
|
LOCAL_SCRIPT="${1:-src/skyweave.lua}"
|
|
|
|
# SCP options - '-O' is for legacy SCP mode if required by the server.
|
|
# Crypto options and port are now handled by ~/.ssh/config for SSH_ALIAS.
|
|
# If your SSH_ALIAS in ~/.ssh/config specifies a non-standard port,
|
|
# scp and ssh will use it automatically.
|
|
SCP_FLAG_O="-O" # Keep this if your server requires legacy SCP mode
|
|
|
|
# Colors for output
|
|
GREEN='\033[0;32m'
|
|
RED='\033[0;31m'
|
|
YELLOW='\033[0;33m'
|
|
NC='\033[0m' # No Color
|
|
|
|
echo -e "${YELLOW}Deploying ${LOCAL_SCRIPT} to ${SSH_ALIAS}:${REMOTE_PATH}...${NC}"
|
|
echo -e "${YELLOW}(Ensure '${SSH_ALIAS}' is correctly configured in your ~/.ssh/config)${NC}"
|
|
|
|
# Check if local script exists
|
|
if [ ! -f "${LOCAL_SCRIPT}" ]; then
|
|
echo -e "${RED}Error: Local script ${LOCAL_SCRIPT} not found!${NC}"
|
|
exit 1
|
|
fi
|
|
|
|
# Copy the script to the roof unit using SSH alias
|
|
# The SCP_FLAG_O is included; remove it if not needed.
|
|
scp ${SCP_FLAG_O} "${LOCAL_SCRIPT}" ${SSH_ALIAS}:${REMOTE_PATH}
|
|
if [ $? -ne 0 ]; then
|
|
echo -e "${RED}Error: Failed to copy script to ${SSH_ALIAS}!${NC}"
|
|
exit 1
|
|
fi
|
|
|
|
# Make the script executable using SSH alias
|
|
ssh ${SSH_ALIAS} "chmod +x ${REMOTE_PATH}"
|
|
if [ $? -ne 0 ]; then
|
|
echo -e "${RED}Error: Failed to make script executable on ${SSH_ALIAS}!${NC}"
|
|
exit 1
|
|
fi
|
|
|
|
echo -e "${GREEN}Deployment to ${SSH_ALIAS} successful!${NC}"
|
|
|
|
# Test the API (still uses ROOF_IP for HTTP)
|
|
echo -e "${YELLOW}Testing API via http://${ROOF_IP}:${REMOTE_HTTP_PORT}...${NC}"
|
|
RESPONSE=$(curl -s -X GET "http://${ROOF_IP}:${REMOTE_HTTP_PORT}/cgi-bin/skyweave.lua?get_config=network_config")
|
|
|
|
if [ $? -eq 0 ] && [[ "${RESPONSE}" == *'"errCode":0'* ]]; then
|
|
echo -e "${GREEN}API test successful!${NC}"
|
|
echo -e "Response: ${RESPONSE}"
|
|
else
|
|
echo -e "${RED}API test failed!${NC}"
|
|
echo -e "Curl exit status: $?"
|
|
echo -e "Response: ${RESPONSE}"
|
|
fi
|
|
|
|
echo -e "\n${YELLOW}API endpoint: http://${ROOF_IP}:${REMOTE_HTTP_PORT}/cgi-bin/skyweave.lua${NC}"
|
|
echo -e "${YELLOW}Example usage: curl -X POST -H \"Content-Type: application/json\" -d '{\"command\":\"your_command\"}' http://${ROOF_IP}:${REMOTE_HTTP_PORT}/cgi-bin/skyweave.lua${NC}" |