Skip to content

Commit

Permalink
Add install wizard (#13)
Browse files Browse the repository at this point in the history
* initial scaffold for install wizard. untested

* first working draft

* moves scripts from root into seperate folder

* Adds description in README.md
  • Loading branch information
isaric authored Dec 2, 2023
1 parent 1aff794 commit 47c4d8a
Show file tree
Hide file tree
Showing 21 changed files with 175 additions and 11 deletions.
10 changes: 10 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
install:
## check if vars are set
bash ./install_scripts/check_vars.sh GOPATH
## run go install
go install ./...
## create system-wide symlink to executables
bash ./install_scripts/create_symlinks.sh motion-poll set-preset goto-preset set-time
## create config folder
bash ./install_scripts/create_service_templates.sh

4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,3 +76,7 @@ Example:
## service templates
Please check the services folder for examples of what a systemd service template should look like if you choose to run motion-poll or set-time as
a service. By using environemnt files and templating, the user can handle multiple cameras with only one service file.

## system-wide install
A Makefile is provided in the project root that will make a system-wide install of the go binaries once compiled. It will then use the provided
service templates to create systemd services for every compiled command and place it in a config folder that the user can specify.
18 changes: 18 additions & 0 deletions install_scripts/check_vars.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/bin/bash
function check_var {
declare -n var_ref=$1
declared=$?
if [ "$declared" != 0 ]
then
echo "$var_ref must be set! Exiting!"
exit 1
fi
}

for var in "$@"
do
echo "checking $var is set"
check_var "$var"
done


17 changes: 17 additions & 0 deletions install_scripts/create_service_templates.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/bin/bash

read -r -p "Path for configuration folder [~/.config/onvif-cam-poll]" $CONFIG_PATH
export CONFIG_PATH=${config_path:-~/.config/onvif-cam-poll}
echo "$CONFIG_PATH"
mkdir --p "$CONFIG_PATH"
export CONFIG_PATH
## create service templates
cp ./services/* "$CONFIG_PATH"/.
envsubst < "$CONFIG_PATH"/[email protected] > "$CONFIG_PATH"/[email protected] && mv "$CONFIG_PATH"/[email protected] "$CONFIG_PATH"/[email protected]
envsubst < "$CONFIG_PATH"/[email protected] > "$CONFIG_PATH"/[email protected] && mv "$CONFIG_PATH"/[email protected] "$CONFIG_PATH"/[email protected]
sudo cp "$CONFIG_PATH"/*.service /lib/systemd/system/.
sudo systemctl daemon-reload
echo "To track a new camera create an .env file for it in $CONFIG_PATH"
echo "Fill in all the variables that are listed in the example.env file"
echo "Afterwards, run systemctl start motion@camera_envfile_name"
echo "Don't forget to enable the service if you want it to run after a restart"
10 changes: 10 additions & 0 deletions install_scripts/create_symlinks.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
function create_symlink() {
sudo rm "/usr/bin/$1"
sudo ln -s "$GOPATH/$1" "/usr/bin/$1"
}

for var in "$@"
do
echo "creating symlink for $var"
create_symlink "$var"
done
16 changes: 16 additions & 0 deletions [email protected]
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
[Unit]
DefaultDependencies=no
After=network.target

[Service]
Type=simple
EnvironmentFile=/home/isaric/.config/onvif-cam-poll/%i.env
Restart=always
RestartSec=3
User=isaric
Group=isaric
ExecStart=/bin/bash /home/isaric/.config/onvif-cam-poll/motion.sh
TimeoutStartSec=0

[Install]
WantedBy=default.target
6 changes: 6 additions & 0 deletions onfig_path/example.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
CAMERA_ADDRESS=bla.bla.bla:8899
CAMERA_USER=admin
CAMERA_PASSWORD=xxxxxx
CAMERA_NAME=garage
SLACK_BOT_TOKEN=xoxb-xxxxxx-xxxxxx-xxxxxx
SLACK_CHANNEL_ID=xxxxxx
1 change: 1 addition & 0 deletions onfig_path/motion.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
motion-poll -a ${CAMERA_ADDRESS} -u ${CAMERA_USER} -p ${CAMERA_PASSWORD} -n ${CAMERA_NAME} -s ${SLACK_WEBHOOK} -t 30 -b ${SLACK_BOT_TOKEN} -c ${SLACK_CHANNEL_ID}
16 changes: 16 additions & 0 deletions onfig_path/[email protected]
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
[Unit]
DefaultDependencies=no
After=network.target

[Service]
Type=simple
EnvironmentFile=$path/%i.env
Restart=always
RestartSec=3
User=$SUDO_USER
Group=$SUDO_USER
ExecStart=/bin/bash $path/motion.sh
TimeoutStartSec=0

[Install]
WantedBy=default.target
1 change: 1 addition & 0 deletions onfig_path/time.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
set-time -a ${CAMERA_ADDRESS} -u admin -p ${CAMERA_PASSWORD}
16 changes: 16 additions & 0 deletions onfig_path/[email protected]
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
[Unit]
DefaultDependencies=no
After=network.target

[Service]
Type=simple
EnvironmentFile=$path/%i.env
Restart=always
RestartSec=3
User=$SUDO_USER
Group=$SUDO_USER
ExecStart=/bin/bash $path/time.sh
TimeoutStartSec=0

[Install]
WantedBy=default.target
1 change: 0 additions & 1 deletion services/example.env
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,5 @@ CAMERA_ADDRESS=bla.bla.bla:8899
CAMERA_USER=admin
CAMERA_PASSWORD=xxxxxx
CAMERA_NAME=garage
SLACK_WEBHOOK=https://hooks.slack.com/services/xxxxxx/xxxxxx/xxxxxx
SLACK_BOT_TOKEN=xoxb-xxxxxx-xxxxxx-xxxxxx
SLACK_CHANNEL_ID=xxxxxx
16 changes: 16 additions & 0 deletions services/[email protected]
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
[Unit]
DefaultDependencies=no
After=network.target

[Service]
Type=simple
EnvironmentFile=${CONFIG_PATH}/%i.env
Restart=always
RestartSec=3
User=${USER}
Group=${USER}
ExecStart=/bin/bash ${CONFIG_PATH}/goto.sh
TimeoutStartSec=0

[Install]
WantedBy=default.target
1 change: 1 addition & 0 deletions services/goto.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
goto-preset -a ${CAMERA_ADDRESS} -u ${CAMERA_USER} -p ${CAMERA_PASSWORD} -t 30 -l 001
2 changes: 1 addition & 1 deletion services/motion.sh
Original file line number Diff line number Diff line change
@@ -1 +1 @@
/path/to/motion-poll -a ${CAMERA_ADDRESS} -u ${CAMERA_USER} -p ${CAMERA_PASSWORD} -n ${CAMERA_NAME} -s ${SLACK_WEBHOOK} -t 30 -b ${SLACK_BOT_TOKEN} -c ${SLACK_CHANNEL_ID}
motion-poll -a ${CAMERA_ADDRESS} -u ${CAMERA_USER} -p ${CAMERA_PASSWORD} -n ${CAMERA_NAME} -s ${SLACK_WEBHOOK} -t 30 -b ${SLACK_BOT_TOKEN} -c ${SLACK_CHANNEL_ID}
8 changes: 4 additions & 4 deletions services/[email protected]
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ After=network.target

[Service]
Type=simple
EnvironmentFile=/home/your-user/motion-poll-services/%i.env
EnvironmentFile=${CONFIG_PATH}/%i.env
Restart=always
RestartSec=3
User=isaric
Group=isaric
ExecStart=/bin/bash /home/your-user/motion-poll-services/motion.sh
User=${USER}
Group=${USER}
ExecStart=/bin/bash ${CONFIG_PATH}/motion.sh
TimeoutStartSec=0

[Install]
Expand Down
1 change: 1 addition & 0 deletions services/set-preset.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
set-preset -a ${CAMERA_ADDRESS} -u ${CAMERA_USER} -p ${CAMERA_PASSWORD} -l 001
16 changes: 16 additions & 0 deletions services/[email protected]
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
[Unit]
DefaultDependencies=no
After=network.target

[Service]
Type=simple
EnvironmentFile=${CONFIG_PATH}/%i.env
Restart=always
RestartSec=3
User=${USER}
Group=${USER}
ExecStart=/bin/bash ${CONFIG_PATH}/set-preset.sh
TimeoutStartSec=0

[Install]
WantedBy=default.target
2 changes: 1 addition & 1 deletion services/time.sh
Original file line number Diff line number Diff line change
@@ -1 +1 @@
/path/to/set-time -a ${CAMERA_ADDRESS} -u admin -p ${CAMERA_PASSWORD}
set-time -a ${CAMERA_ADDRESS} -u admin -p ${CAMERA_PASSWORD}
8 changes: 4 additions & 4 deletions services/[email protected]
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ After=network.target

[Service]
Type=simple
EnvironmentFile=/home/your-user/motion-poll-services/%i.env
EnvironmentFile=${CONFIG_PATH}/%i.env
Restart=always
RestartSec=3
User=isaric
Group=isaric
ExecStart=/bin/bash /home/your-user/motion-poll-services/time.sh
User=${USER}
Group={$USER}
ExecStart=/bin/bash ${CONFIG_PATH}/time.sh
TimeoutStartSec=0

[Install]
Expand Down
16 changes: 16 additions & 0 deletions [email protected]
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
[Unit]
DefaultDependencies=no
After=network.target

[Service]
Type=simple
EnvironmentFile=/home/isaric/.config/onvif-cam-poll/%i.env
Restart=always
RestartSec=3
User=isaric
Group=isaric
ExecStart=/bin/bash /home/isaric/.config/onvif-cam-poll/time.sh
TimeoutStartSec=0

[Install]
WantedBy=default.target

0 comments on commit 47c4d8a

Please sign in to comment.