Alexandre
2023-09-09 13:09:25 +02:00
parent eb77a98b1f
commit 3eaf00841e
13 changed files with 142 additions and 227 deletions

View File

@@ -16,9 +16,7 @@
ARG BUILD_FROM
ARG BUILD_VERSION
ARG BUILD_UPSTREAM="latest"
FROM ${BUILD_FROM}${BUILD_UPSTREAM}
ENV BASHIO_VERSION=1.29.1
FROM ${BUILD_FROM}
##################
# 2 Modify Image #
@@ -30,6 +28,16 @@ ENV S6_CMD_WAIT_FOR_SERVICES=1 \
S6_SERVICES_GRACETIME=0
# load volume
VOLUME [ "/sys/fs/cgroup" ]
# Specific images modifications
# hadolint ignore=SC2015,DL4006,SC2013,SC2086
RUN \
# Change home folder location
usermod --home /config/addons_config/calibre abc \
&& mkdir -p /opt/calibre
# Global LSIO modifications
ARG CONFIGLOCATION="/config/addons_config/calibre"
# hadolint ignore=SC2015, SC2013, SC2086
@@ -53,11 +61,6 @@ RUN \
# Replace lsiown if not found
&& if [ ! -f /usr/bin/lsiown ]; then for file in $(grep -sril "lsiown" /etc); do sed -i "s|lsiown|chown|g" $file; done; fi
# Specific images modifications
RUN \
usermod --home /config/addons_config/calibre abc \
&& mkdir -p /opt/calibre
##################
# 3 Install apps #
##################
@@ -104,9 +107,11 @@ RUN \
#Correct shebang in entrypoint
for shebang in "/command/with-contenv bashio" "/usr/bin/env bashio" "/usr/bin/bashio" "/bin/bash" "/bin/sh"; do if [ -f "${shebang%% *}" ]; then break; fi; done; sed -i "s|/command/with-contenv bashio|$shebang|g" /ha_entrypoint.sh
#
#WORKDIR /
#ENTRYPOINT [ "/usr/bin/env" ]
#CMD [ "/ha_entrypoint.sh" ]
#SHELL ["/bin/bash", "-o", "pipefail", "-c"]
############
# 5 Labels #

View File

@@ -1,9 +1,9 @@
{
"build_from": {
"aarch64": "lscr.io/linuxserver/calibre:arm64v8-",
"amd64": "lscr.io/linuxserver/calibre:amd64-"
"aarch64": "lscr.io/linuxserver/calibre:arm64v8-latest",
"amd64": "lscr.io/linuxserver/calibre:amd64-latest"
},
"codenotary": {
"signer": "alexandrep.github@gmail.com"
}
}
}

View File

@@ -105,6 +105,6 @@
},
"slug": "calibre",
"url": "https://github.com/alexbelgium/hassio-addons/tree/master/calibre",
"version": "v6.14.1-ls210_reverted",
"version": "v6.14.1-ls210_test",
"video": true
}
}

View File

@@ -1,64 +0,0 @@
#!/usr/bin/with-contenv bashio
# shellcheck shell=bash
# Define user
PUID=$(bashio::config "PUID")
PGID=$(bashio::config "PGID")
# Check data location
LOCATION=$(bashio::config 'data_location')
if [[ "$LOCATION" = "null" || -z "$LOCATION" ]]; then
# Default location
LOCATION="/config/addons_config/calibre"
else
bashio::log.warning "Warning : a custom data location was selected, but the previous folder will NOT be copied. You need to do it manually"
# Check if config is located in an acceptable location
LOCATIONOK=""
for location in "/share" "/config" "/data" "/mnt"; do
if [[ "$LOCATION" == "$location"* ]]; then
LOCATIONOK=true
fi
done
if [ -z "$LOCATIONOK" ]; then
LOCATION=/config/addons_config/${HOSTNAME#*-}
bashio::log.fatal "Your data_location value can only be set in /share, /config or /data (internal to addon). It will be reset to the default location : $LOCATION"
fi
fi
# Set data location
bashio::log.info "Setting data location to $LOCATION"
sed -i "1a export HOME=$LOCATION" /etc/s6-overlay/s6-rc.d/svc-web/run || true
sed -i "1a export FM_HOME=$LOCATION" /etc/s6-overlay/s6-rc.d/svc-web/run || true
sed -i "s|/config/addons_config/calibre|$LOCATION|g" /defaults/* || true
sed -i "s|/config/addons_config/calibre|$LOCATION|g" /etc/s6-overlay/s6-rc.d/*/* || true
sed -i "s|/config/addons_config/calibre|$LOCATION|g" /etc/s6-overlay/s6-rc.d/*/run || true
sed -i "1a export HOME=$LOCATION" /etc/services.d/web/run || true
sed -i "1a export FM_HOME=$LOCATION" /etc/services.d/web/run || true
sed -i "s|/config/addons_config/calibre|$LOCATION|g" /defaults/* || true
sed -i "s|/config/addons_config/calibre|$LOCATION|g" /etc/cont-init.d/* || true
sed -i "s|/config/addons_config/calibre|$LOCATION|g" /etc/services.d/*/run || true
if [ -d /var/run/s6/container_environment ]; then
printf "%s" "$LOCATION" > /var/run/s6/container_environment/HOME
printf "%s" "$LOCATION" > /var/run/s6/container_environment/FM_HOME
fi
{
printf "%s" "HOME=\"$LOCATION\""
printf "%s" "FM_HOME=\"$LOCATION\""
} >> ~/.bashrc
usermod --home "$LOCATION" abc
# Create folder
echo "Creating $LOCATION"
mkdir -p "$LOCATION"
# Set ownership
bashio::log.info "Setting ownership to $PUID:$PGID"
chown "$PUID":"$PGID" "$LOCATION"

View File

@@ -1,8 +1,69 @@
#!/bin/bash
#!/usr/bin/with-contenv bashio
# shellcheck shell=bash
# shellcheck disable=SC2046
# Define user
PUID=$(bashio::config "PUID")
PGID=$(bashio::config "PGID")
# Check data location
LOCATION=$(bashio::config 'data_location')
if [[ "$LOCATION" = "null" || -z "$LOCATION" ]]; then
# Default location
LOCATION="/config/addons_config/calibre"
else
bashio::log.warning "Warning : a custom data location was selected, but the previous folder will NOT be copied. You need to do it manually"
# Check if config is located in an acceptable location
LOCATIONOK=""
for location in "/share" "/config" "/data" "/mnt"; do
if [[ "$LOCATION" == "$location"* ]]; then
LOCATIONOK=true
fi
done
if [ -z "$LOCATIONOK" ]; then
LOCATION="/config/addons_config/calibre"
bashio::log.fatal "Your data_location value can only be set in /share, /config or /data (internal to addon). It will be reset to the default location : $LOCATION"
fi
if [ ! -d /config/addons_config/calibre ]; then
echo "Creating /config/addons_config/calibre"
mkdir -p /config/addons_config/calibre
fi
chown -R abc:abc /config/addons_config/calibre
# Set data location
bashio::log.info "Setting data location to $LOCATION"
# Correct home locations
for file in /etc/s6-overlay/s6-rc.d/*/run; do
if [ "$(sed -n '1{/bash/p};q' "$file")" ]; then
sed -i "1a export HOME=$LOCATION" "$file"
sed -i "1a export FM_HOME=$LOCATION" "$file"
fi
done
# Correct home location
for folders in /defaults /etc/cont-init.d /etc/services.d /etc/s6-overlay/s6-rc.d; do
if [ -d "$folders" ]; then
sed -i "s|/config/addons_config/calibre|$LOCATION|g" $(find "$folders" -type f) &>/dev/null || true
fi
done
# Change user home
usermod --home "$LOCATION" abc
# Add environment variables
if [ -d /var/run/s6/container_environment ]; then printf "%s" "$LOCATION" > /var/run/s6/container_environment/HOME; fi
if [ -d /var/run/s6/container_environment ]; then printf "%s" "$LOCATION" > /var/run/s6/container_environment/FM_HOME; fi
{
printf "%s" "HOME=\"$LOCATION\""
printf "%s" "FM_HOME=\"$LOCATION\""
} >> ~/.bashrc
# Create folder
echo "Creating $LOCATION"
mkdir -p "$LOCATION"
# Set ownership
bashio::log.info "Setting ownership to $PUID:$PGID"
chown -R "$PUID":"$PGID" "$LOCATION"
chmod -R 755 "$LOCATION"

View File

@@ -1,33 +0,0 @@
#!/usr/bin/with-contenv bashio
# shellcheck shell=bash
#################
# NGINX SETTING #
#################
declare port
declare certfile
declare ingress_interface
declare ingress_port
declare keyfile
port=$(bashio::addon.port 80)
if bashio::var.has_value "${port}"; then
bashio::config.require.ssl
if bashio::config.true 'ssl'; then
certfile=$(bashio::config 'certfile')
keyfile=$(bashio::config 'keyfile')
mv /etc/nginx/servers/direct-ssl.disabled /etc/nginx/servers/direct.conf
sed -i "s/%%certfile%%/${certfile}/g" /etc/nginx/servers/direct.conf
sed -i "s/%%keyfile%%/${keyfile}/g" /etc/nginx/servers/direct.conf
else
mv /etc/nginx/servers/direct.disabled /etc/nginx/servers/direct.conf
fi
fi
ingress_port=$(bashio::addon.ingress_port)
ingress_interface=$(bashio::addon.ip_address)
sed -i "s/%%port%%/${ingress_port}/g" /etc/nginx/servers/ingress.conf
sed -i "s/%%interface%%/${ingress_interface}/g" /etc/nginx/servers/ingress.conf

View File

@@ -2,38 +2,52 @@
# shellcheck shell=bash
# shellcheck disable=SC2015
# Install specific apps
if bashio::config.has_value 'additional_apps'; then
bashio::log.info "Installing additional apps :"
# hadolint ignore=SC2005
NEWAPPS=$(bashio::config 'additional_apps')
for packagestoinstall in ${NEWAPPS//,/ }; do
bashio::log.green "... $packagestoinstall"
if command -v "apk" &>/dev/null; then
apk add --no-cache "$packagestoinstall" &>/dev/null || (bashio::log.fatal "Error : $packagestoinstall not found")
elif command -v "apt" &>/dev/null; then
apt-get install -yqq --no-install-recommends "$packagestoinstall" &>/dev/null || (bashio::log.fatal "Error : $packagestoinstall not found")
elif command -v "pacman" &>/dev/null; then
pacman --noconfirm -S "$packagestoinstall" &>/dev/null || (bashio::log.fatal "Error : $packagestoinstall not found")
fi
done
fi
# Set TZ
if bashio::config.has_value 'TZ'; then
TIMEZONE=$(bashio::config 'TZ')
bashio::log.info "Setting timezone to $TIMEZONE"
ln -snf /usr/share/zoneinfo/"$TIMEZONE" /etc/localtime && echo "$TIMEZONE" >/etc/timezone
fi || true
# Set keyboard
if bashio::config.has_value 'KEYBOARD'; then
KEYBOARD=$(bashio::config 'KEYBOARD')
bashio::log.info "Setting keyboard to $KEYBOARD"
sed -i "1a export KEYBOARD=$KEYBOARD" /etc/s6-overlay/s6-rc.d/svc-web/run
if [ -d /var/run/s6/container_environment ]; then printf "%s" "$KEYBOARD" > /var/run/s6/container_environment/KEYBOARD; fi
printf "%s" "KEYBOARD=\"$KEYBOARD\"" >> ~/.bashrc
fi || true
ln -snf /usr/share/zoneinfo/"$TIMEZONE" /etc/localtime
echo "$TIMEZONE" >/etc/timezone
fi || (bashio::log.fatal "Error : $TIMEZONE not found. Here is a list of valid timezones : https://manpages.ubuntu.com/manpages/focal/man3/DateTime::TimeZone::Catalog.3pm.html")
# Set cli args
if bashio::config.has_value 'CLI_ARGS'; then
bashio::log.info "Setting password to the value defined in options"
CLI_ARGS=$(bashio::config 'CLI_ARGS')
bashio::log.info "Setting arguments to $CLI_ARGS"
sed -i "1a export CLI_ARGS=$CLI_ARGS" /etc/s6-overlay/s6-rc.d/svc-web/run
if [ -d /var/run/s6/container_environment ]; then printf "%s" "$CLI_ARGS" > /var/run/s6/container_environment/CLI_ARGS; fi
printf "%s" "CLI_ARGS=\"$CLI_ARGS\"" >> ~/.bashrc
if [ -d /var/run/s6/container_environment ]; then printf "%s" "$CLI_ARGS" >/var/run/s6/container_environment/CLI_ARGS; fi
printf "%s" "CLI_ARGS=\"$CLI_ARGS\"" >>~/.bashrc
fi || true
# Set keyboard
if bashio::config.has_value 'KEYBOARD'; then
KEYBOARD=$(bashio::config 'KEYBOARD')
bashio::log.info "Setting keyboard to $KEYBOARD"
if [ -d /var/run/s6/container_environment ]; then printf "%s" "$KEYBOARD" >/var/run/s6/container_environment/KEYBOARD; fi
printf "%s" "KEYBOARD=\"$KEYBOARD\"" >>~/.bashrc
fi || true
# Set password
if bashio::config.has_value 'PASSWORD'; then
bashio::log.info "Setting password to the value defined in options"
PASSWORD=$(bashio::config 'PASSWORD')
bashio::log.info "Setting password to $PASSWORD"
sed -i "1a export PASSWORD=$PASSWORD" /etc/s6-overlay/s6-rc.d/svc-web/run
if [ -d /var/run/s6/container_environment ]; then printf "%s" "$PASSWORD" > /var/run/s6/container_environment/PASSWORD; fi
printf "%s" "PASSWORD=\"$PASSWORD\"" >> ~/.bashrc
passwd -d abc
echo -e "$PASSWORD\n$PASSWORD" | passwd abc
fi || true

View File

@@ -0,0 +1,25 @@
#!/usr/bin/with-contenv bashio
# shellcheck shell=bash
# nginx Path
NGINX_CONFIG=/etc/nginx/sites-available/ingress.conf
SUBFOLDER="$(bashio::addon.ingress_entry)"
# Copy template
cp /defaults/default.conf "${NGINX_CONFIG}"
# Remove ssl part
awk -v n=4 '/server/{n--}; n > 0' "${NGINX_CONFIG}" >tmpfile
mv tmpfile "${NGINX_CONFIG}"
# Remove ipv6
sed -i '/listen \[::\]/d' "${NGINX_CONFIG}"
# Add ingress parameters
sed -i "s|3000|$(bashio::addon.ingress_port)|g" "${NGINX_CONFIG}"
sed -i '/proxy_buffering/a proxy_set_header Accept-Encoding "";' "${NGINX_CONFIG}"
sed -i '/proxy_buffering/a sub_filter_once off;' "${NGINX_CONFIG}"
sed -i '/proxy_buffering/a sub_filter_types *;' "${NGINX_CONFIG}"
sed -i '/proxy_buffering/a sub_filter "vnc/index.html?autoconnect" "vnc/index.html?path=%%path%%/websockify?autoconnect";' "${NGINX_CONFIG}"
sed -i "s|%%path%%|${SUBFOLDER:1}|g" "${NGINX_CONFIG}"
# Enable ingress
cp /etc/nginx/sites-available/ingress.conf /etc/nginx/sites-enabled

View File

@@ -1,56 +0,0 @@
# Run nginx in foreground.
daemon off;
# This is run inside Docker.
user root;
# Pid storage location.
pid /var/run/nginx.pid;
# Set number of worker processes.
worker_processes 1;
# Enables the use of JIT for regular expressions to speed-up their processing.
pcre_jit on;
# Write error log to Hass.io add-on log.
error_log /proc/1/fd/1 error;
# Load allowed environment vars
env HASSIO_TOKEN;
# Load dynamic modules.
include /etc/nginx/modules/*.conf;
# Max num of simultaneous connections by a worker process.
events {
worker_connections 512;
}
http {
include /etc/nginx/includes/mime.types;
log_format hassio '[$time_local] $status '
'$http_x_forwarded_for($remote_addr) '
'$request ($http_user_agent)';
access_log /proc/1/fd/1 hassio;
client_max_body_size 4G;
default_type application/octet-stream;
gzip on;
keepalive_timeout 65;
sendfile on;
server_tokens off;
tcp_nodelay on;
tcp_nopush on;
map $http_upgrade $connection_upgrade {
default upgrade;
'' close;
}
include /etc/nginx/includes/resolver.conf;
include /etc/nginx/includes/upstream.conf;
include /etc/nginx/servers/*.conf;
}

View File

@@ -1,18 +0,0 @@
server {
listen %%interface%%:%%port%% default_server;
include /etc/nginx/includes/server_params.conf;
include /etc/nginx/includes/proxy_params.conf;
client_max_body_size 0;
server_name webtop.*;
location / {
add_header Access-Control-Allow-Origin *;
proxy_pass http://127.0.0.1:8080;
proxy_buffering off;
proxy_read_timeout 30;
proxy_set_header Connection "Upgrade";
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Host $host;
}
}

View File

@@ -1,8 +0,0 @@
#!/usr/bin/execlineb -S0
# ==============================================================================
# Take down the S6 supervision tree when Nginx fails
# ==============================================================================
if { s6-test ${1} -ne 0 }
if { s6-test ${1} -ne 256 }
s6-svscanctl -t /var/run/s6/services

View File

@@ -1,10 +0,0 @@
#!/usr/bin/with-contenv bashio
# shellcheck shell=bash
# ==============================================================================
# Wait for transmission to become available
bashio::net.wait_for 8080 localhost 900
bashio::log.info "Starting NGinx..."
exec nginx

View File

@@ -1,10 +1,9 @@
{
"github_fulltag": "true",
"last_update": "08-04-2023",
"paused": true,
"repository": "alexbelgium/hassio-addons",
"slug": "calibre",
"source": "github",
"upstream_repo": "linuxserver/docker-calibre",
"upstream_version": "v6.15.0-ls211"
}
}