#!/bin/bash set -e if [[ "$EUID" -ne 0 ]]; then echo -e "\e[31m[FATAL]\e[39m Currently this script requires being ran as root user - please try again as root." exit 1 fi echo -e "\n\nINSTALL LOG FOR axis_timelapse: $(date --rfc-3339=seconds)\n" >> /var/log/axis_timelapse-install.log info() { echo -e "\e[34m[INFO]\e[39m $1" echo "[INFO] $1" >> /var/log/axis_timelapse-install.log } debug() { if [[ ! -z "$DEBUG" ]]; then echo -e "\e[96m[DEBUG]\e[39m $1" fi echo "[DEBUG] $1" >> /var/log/axis_timelapse-install.log } warn() { echo -e "\e[33m[WARNING]\e[39m $1" echo "[WARNING] $1" >> /var/log/axis_timelapse-install.log } fatal() { echo -e "\e[31m[FATAL]\e[39m $1" echo "[FATAL] $1" >> /var/log/axis_timelapse-install.log exit 1 } install_axis_timelapse(){ info "Installing axis_timelapse web service..." mkdir -p /etc/axis_timelapse > /dev/null 2>&1 info "Creating axis_timelapse config..." cat < /etc/axis_timelapse/config.toml [camera] tls = true selfsigned = true address = "192.168.0.220" port = 443 compression = 35 [storage] type = "local" path = "/mnt/data-0/nature_cam1" tls = true port = 443 endpoint_domain = "s3.us-east-1.amazonaws.com" region = "us-east-1" access_key = "" secret_key = "" [timer] chron = "*/5 * * * *" EOT info "Downloading axis_timelapse_linux_amd64..." wget -O axis_timelapse_linux_amd64.tar https://git.anomalous.dev/57_Wolve/axis_timelapse/releases/download/latest/axis_timelapse_linux_amd64.tar || true tar xvf axis_timelapse_linux_amd64.tar -C /usr/local/bin/ rm axis_timelapse_linux_amd64.tar.gz > /dev/null 2>&1 || true chmod u+x /usr/local/bin/axis_timelapse info "Creating axis_timelapse.service..." cat < /etc/systemd/system/axis_timelapse.service [Unit] Description=axis_timelapse daemon Wants=network-online.target After=network.target network-online.target [Service] User=root WorkingDirectory=/etc/axis_timelapse LimitNOFILE=4096 PIDFile=/var/run/axis_timelapse/daemon.pid ExecStart=/usr/local/bin/axis_timelapse Restart=on-failure StartLimitInterval=600 [Install] WantedBy=multi-user.target EOT systemctl daemon-reload > /dev/null 2>&1 || true systemctl enable axis_timelapse > /dev/null 2>&1 || true debug "Starting axis_timelapse Web Service..." systemctl start axis_timelapse > /dev/null 2>&1 || true } main() { info "Script loaded, starting the install process..." if [[ ! -x "$(command -v curl)" ]]; then fatal "Couldn't find curl installed on the system - please install it first and rerun the script." fi install_axis_timelapse info "axis_timelapse service is now installed, install script finished." } main