Skip to content

Make eap-install.sh look for connection details in environment variables #442

@apljungquist

Description

@apljungquist

It's common to have developer tools that interact with a device using VAPIX and it would be neat if there was a unified way to specify which device we work with. To that end I propose that eap-install.sh should look for connection details also among the user's environment variables. This could be implemented like this:

diff --git a/eap-install.sh b/eap-install.sh
index 4f3c04b..7679b31 100755
--- a/eap-install.sh
+++ b/eap-install.sh
@@ -28,6 +28,11 @@ help_and_exit() {
 	echo "successful execution. After this you can simply write:"
 	echo "Usage:   $me <action>"
 	echo "Example: $me install"
+	echo
+	echo "Environment variables (take precedence over saved connection details):"
+	echo "  AXIS_DEVICE_IP   - Target device IP address"
+	echo "  AXIS_DEVICE_USER - Target device username"
+	echo "  AXIS_DEVICE_PASS - Target device password"
 	exit 100;
 }
 
@@ -210,6 +215,11 @@ if [ -r ./.eap-install.cfg ]; then
 	. ./.eap-install.cfg
 fi
 
+# Override with environment variables if set
+[ -n "$AXIS_DEVICE_IP" ] && axis_device_ip="$AXIS_DEVICE_IP"
+[ -n "$AXIS_DEVICE_USER" ] && user="$AXIS_DEVICE_USER"
+[ -n "$AXIS_DEVICE_PASS" ] && password="$AXIS_DEVICE_PASS"
+
 # Check the command line parameters
 if [ -z "$1" ]; then
 	# Script called without arguments ask the user
@@ -238,7 +248,7 @@ elif [ "$1" ] && [ "$2" ] && [ "$3" ]; then
 	action=$3
 	# and save them
 elif [ "$1" ] && [ -z "$2" ]; then
-	# 1 parameter, both axis_device_ip and password retrieved from config file
+	# 1 parameter, connection details retrieved from config file and/or environment variables
 	action=$1
 	do_check_action $action
 	# if we come here, action is OK, ask for the rest

The name AXIS_DEVICE_IP is chosen to match the placeholder used in these examples.
The other names are chosen mostly to be consistent with the first.

Users can combine this with other tools that facilitate setting environment variables. For instance, (direnv)[https://github.com/direnv/direnv/] automatically sets environment variables based on the working directory and can be used to work with different devices in different projects, or ensure that the environment variables are set in every instance of the user's' shell.


On the topic of eap-install.sh; the help text forgets to say that the username is also remembered:

echo "The script remembers the target_ip and password after the first"

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions