Skip to content

Commit

Permalink
🔨 Rewrite add-on onto Bashio
Browse files Browse the repository at this point in the history
  • Loading branch information
frenck committed Mar 31, 2019
1 parent 74b9c35 commit 17c090a
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 44 deletions.
24 changes: 2 additions & 22 deletions traccar/rootfs/etc/cont-init.d/10-requirements.sh
Original file line number Diff line number Diff line change
@@ -1,26 +1,6 @@
#!/usr/bin/with-contenv bash
#!/usr/bin/with-contenv bashio
# ==============================================================================
# Community Hass.io Add-ons: Traccar
# This files check if all user configuration requirements are met
# ==============================================================================
# shellcheck disable=SC1091
source /usr/lib/hassio-addons/base.sh

# Check SSL requirements, if enabled
if hass.config.true 'ssl'; then
if ! hass.config.has_value 'certfile'; then
hass.die 'SSL is enabled, but no certfile was specified'
fi

if ! hass.config.has_value 'keyfile'; then
hass.die 'SSL is enabled, but no keyfile was specified'
fi

if ! hass.file_exists "/ssl/$(hass.config.get 'certfile')"; then
hass.die 'The configured certfile is not found'
fi

if ! hass.file_exists "/ssl/$(hass.config.get 'keyfile')"; then
hass.die 'The configured keyfile is not found'
fi
fi
bashio::config.require.ssl
7 changes: 2 additions & 5 deletions traccar/rootfs/etc/cont-init.d/20-config.sh
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
#!/usr/bin/with-contenv bash
#!/usr/bin/with-contenv bashio
# ==============================================================================
# Community Hass.io Add-ons: Traccar
# Ensures the user configuration file is present
# ==============================================================================
# shellcheck disable=SC1091
source /usr/lib/hassio-addons/base.sh

if ! hass.file_exists "/config/traccar.xml"; then
if ! bashio::fs.file_exists "/config/traccar.xml"; then
cp /etc/traccar/traccar.xml /config/traccar.xml
fi
13 changes: 5 additions & 8 deletions traccar/rootfs/etc/cont-init.d/30-nginx.sh
Original file line number Diff line number Diff line change
@@ -1,25 +1,22 @@
#!/usr/bin/with-contenv bash
#!/usr/bin/with-contenv bashio
# ==============================================================================
# Community Hass.io Add-ons: Traccar
# Configures NGINX for use with the Traccar server
# ==============================================================================
# shellcheck disable=SC1091
source /usr/lib/hassio-addons/base.sh

declare certfile
declare keyfile
declare port

if hass.config.true 'ssl'; then
if bashio::config.true 'ssl'; then
rm /etc/nginx/nginx.conf
mv /etc/nginx/nginx-ssl.conf /etc/nginx/nginx.conf

certfile=$(hass.config.get 'certfile')
keyfile=$(hass.config.get 'keyfile')
certfile=$(bashio::config 'certfile')
keyfile=$(bashio::config 'keyfile')

sed -i "s/%%certfile%%/${certfile}/g" /etc/nginx/nginx.conf
sed -i "s/%%keyfile%%/${keyfile}/g" /etc/nginx/nginx.conf
fi

port=$(hass.config.get 'port')
port=$(bashio::config 'port')
sed -i "s/%%port%%/${port}/g" /etc/nginx/nginx.conf
6 changes: 2 additions & 4 deletions traccar/rootfs/etc/services.d/nginx/run
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
#!/usr/bin/with-contenv bash
#!/usr/bin/with-contenv bashio
# ==============================================================================
# Community Hass.io Add-ons: Traccar
# Runs the Nginx daemon
# ==============================================================================
# shellcheck disable=SC1091
source /usr/lib/hassio-addons/base.sh

bashio::log.info "Starting NGinx server..."
exec nginx -g "daemon off;"
9 changes: 4 additions & 5 deletions traccar/rootfs/etc/services.d/traccar/run
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
#!/usr/bin/with-contenv bash
#!/usr/bin/with-contenv bashio
# ==============================================================================
# Community Hass.io Add-ons: Traccar
# Runs the Traccar daemon
# ==============================================================================
# shellcheck disable=SC1091
source /usr/lib/hassio-addons/base.sh

declare -a options

bashio::log.info "Starting Traccar server..."

# Memory settings
options+=(-Xms256m)
options+=(-Xmx512m)
Expand All @@ -22,6 +21,6 @@ options+=(-jar tracker-server.jar)
options+=(/config/traccar.xml)

# Run the Traccar daemon
cd /opt/traccar || hass.die "Failed to switch to Traccar directory"
cd /opt/traccar || bashio::exit.nok "Failed to switch to Traccar directory"

exec java "${options[@]}"

0 comments on commit 17c090a

Please sign in to comment.