Installed SSH key on roof unit and added a host config called roof-unit to simplify the deploy script

This commit is contained in:
Wesley Ray
2025-06-05 12:39:28 -04:00
parent 090046f8e4
commit 5e77c55749
+25 -17
View File
@@ -1,18 +1,24 @@
#!/bin/bash #!/bin/bash
# skyweave_deploy.sh - Deploy Lua API script to RVLink roof unit (legacy crypto) # 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" ROOF_IP="192.168.10.254"
ROOF_USER="root" # The user 'root' is assumed to be set in your ~/.ssh/config for the SSH_ALIAS
REMOTE_PATH="/www/cgi-bin/skyweave.lua" REMOTE_PATH="/www/cgi-bin/skyweave.lua"
SSH_PORT="22"
REMOTE_HTTP_PORT="${2:-42069}" # Default to 42069 if not specified REMOTE_HTTP_PORT="${2:-42069}" # Default to 42069 if not specified
# Local script path (default to skyweave.lua in current directory) # Local script path (default to skyweave.lua in current directory)
LOCAL_SCRIPT="${1:-src/skyweave.lua}" LOCAL_SCRIPT="${1:-src/skyweave.lua}"
# SSH/SCP legacy crypto options # SCP options - '-O' is for legacy SCP mode if required by the server.
SSH_OPTS="-oKexAlgorithms=+diffie-hellman-group1-sha1 -oHostKeyAlgorithms=+ssh-rsa -oMACs=+hmac-sha1 -p ${SSH_PORT}" # Crypto options and port are now handled by ~/.ssh/config for SSH_ALIAS.
SCP_OPTS="-O -oKexAlgorithms=+diffie-hellman-group1-sha1 -oHostKeyAlgorithms=+ssh-rsa -oMACs=+hmac-sha1 -P ${SSH_PORT}" # 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 # Colors for output
GREEN='\033[0;32m' GREEN='\033[0;32m'
@@ -20,7 +26,8 @@ RED='\033[0;31m'
YELLOW='\033[0;33m' YELLOW='\033[0;33m'
NC='\033[0m' # No Color NC='\033[0m' # No Color
echo -e "${YELLOW}Deploying ${LOCAL_SCRIPT} to ${ROOF_USER}@${ROOF_IP}:${REMOTE_PATH}...${NC}" 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 # Check if local script exists
if [ ! -f "${LOCAL_SCRIPT}" ]; then if [ ! -f "${LOCAL_SCRIPT}" ]; then
@@ -28,24 +35,25 @@ if [ ! -f "${LOCAL_SCRIPT}" ]; then
exit 1 exit 1
fi fi
# Copy the script to the roof unit using legacy SCP # Copy the script to the roof unit using SSH alias
scp ${SCP_OPTS} "${LOCAL_SCRIPT}" ${ROOF_USER}@${ROOF_IP}:${REMOTE_PATH} # 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 if [ $? -ne 0 ]; then
echo -e "${RED}Error: Failed to copy script to roof unit!${NC}" echo -e "${RED}Error: Failed to copy script to ${SSH_ALIAS}!${NC}"
exit 1 exit 1
fi fi
# Make the script executable using legacy SSH # Make the script executable using SSH alias
ssh ${SSH_OPTS} ${ROOF_USER}@${ROOF_IP} "chmod +x ${REMOTE_PATH}" ssh ${SSH_ALIAS} "chmod +x ${REMOTE_PATH}"
if [ $? -ne 0 ]; then if [ $? -ne 0 ]; then
echo -e "${RED}Error: Failed to make script executable!${NC}" echo -e "${RED}Error: Failed to make script executable on ${SSH_ALIAS}!${NC}"
exit 1 exit 1
fi fi
echo -e "${GREEN}Deployment successful!${NC}" echo -e "${GREEN}Deployment to ${SSH_ALIAS} successful!${NC}"
# Test the API # Test the API (still uses ROOF_IP for HTTP)
echo -e "${YELLOW}Testing API by fetching network configuration...${NC}" 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") 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 if [ $? -eq 0 ] && [[ "${RESPONSE}" == *'"errCode":0'* ]]; then
@@ -58,4 +66,4 @@ else
fi fi
echo -e "\n${YELLOW}API endpoint: http://${ROOF_IP}:${REMOTE_HTTP_PORT}/cgi-bin/skyweave.lua${NC}" 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}" 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}"