mirror of
https://github.com/alexbelgium/hassio-addons.git
synced 2026-01-10 09:51:02 +01:00
Use symlinks
This commit is contained in:
1
immich_openvino/rootfs
Symbolic link
1
immich_openvino/rootfs
Symbolic link
@@ -0,0 +1 @@
|
||||
../immich/rootfs
|
||||
@@ -1,22 +0,0 @@
|
||||
#!/usr/bin/with-contenv bashio
|
||||
# shellcheck shell=bash
|
||||
|
||||
MIGRATED=""
|
||||
PREVIOUS_FOLDER="immich"
|
||||
|
||||
# Move main folder
|
||||
if [ -f /homeassistant/addons_config/"$PREVIOUS_FOLDER"/config.yaml ]; then
|
||||
bashio::log.warning "----------------------------------------"
|
||||
bashio::log.warning "Migrating configuration to the new addon"
|
||||
bashio::log.warning "----------------------------------------"
|
||||
cp -rnp /homeassistant/addons_config/"$PREVIOUS_FOLDER"/ /config/
|
||||
mv /homeassistant/addons_config/"$PREVIOUS_FOLDER" "$PREVIOUS_FOLDER"_migrated
|
||||
if [ -d /config/addons_config ]; then rm -r /config/addons_config; fi
|
||||
echo "Files moved to /addon_configs/$HOSTNAME"
|
||||
fi
|
||||
|
||||
# Move autoscript
|
||||
if [ -f /homeassistant/addons_autoscrips/immich.sh ]; then
|
||||
cp -rnf /homeassistant/addons_autoscrips/"$PREVIOUS_FOLDER".sh /config/ &>/dev/null || true
|
||||
bashio::log.yellow "... moved "$PREVIOUS_FOLDER".sh from /config/addons_autoscripts to /addon_configs/$HOSTNAME"
|
||||
fi
|
||||
@@ -1,95 +0,0 @@
|
||||
#!/usr/bin/with-contenv bashio
|
||||
# shellcheck shell=bash
|
||||
set -e
|
||||
|
||||
######################
|
||||
# GENERAL PARAMETERS #
|
||||
######################
|
||||
|
||||
if bashio::config.has_value "PUID"; then
|
||||
PUID="$(bashio::config 'PUID')"
|
||||
else
|
||||
PUID=0
|
||||
fi
|
||||
if bashio::config.has_value "PGID"; then
|
||||
PGID="$(bashio::config 'PGID')"
|
||||
else
|
||||
PGID=0
|
||||
fi
|
||||
|
||||
##########################
|
||||
# MIGRATIONS AND UPDATES #
|
||||
##########################
|
||||
|
||||
# Clean typesense
|
||||
if [ -d /data/typesense ]; then
|
||||
rm -r /data/typesense
|
||||
fi
|
||||
|
||||
#################
|
||||
# DATA_LOCATION #
|
||||
#################
|
||||
|
||||
bashio::log.info "Setting data location"
|
||||
DATA_LOCATION="$(bashio::config 'data_location')"
|
||||
export IMMICH_MEDIA_LOCATION="$DATA_LOCATION"
|
||||
if [ -d /var/run/s6/container_environment ]; then
|
||||
printf "%s" "$DATA_LOCATION" > /var/run/s6/container_environment/IMMICH_MEDIA_LOCATION
|
||||
fi
|
||||
printf "%s\n" "IMMICH_MEDIA_LOCATION=\"$DATA_LOCATION\"" >> ~/.bashrc
|
||||
|
||||
echo "... check $DATA_LOCATION folder exists"
|
||||
mkdir -p "$DATA_LOCATION"
|
||||
|
||||
echo "... setting permissions"
|
||||
chown -R "$PUID":"$PGID" "$DATA_LOCATION"
|
||||
|
||||
echo "... correcting official script"
|
||||
# shellcheck disable=SC2013
|
||||
for file in $(grep -sril '/photos' /etc); do sed -i "s|/photos|$DATA_LOCATION|g" "$file"; done
|
||||
if [ -f /photos ]; then rm -r /photos; fi
|
||||
ln -sf "$DATA_LOCATION" /photos
|
||||
chown "$PUID":"$PGID" /photos
|
||||
|
||||
mkdir -p "$MACHINE_LEARNING_CACHE_FOLDER"
|
||||
mkdir -p "$REVERSE_GEOCODING_DUMP_DIRECTORY"
|
||||
chown -R "$PUID":"$PGID" "$MACHINE_LEARNING_CACHE_FOLDER"
|
||||
chown -R "$PUID":"$PGID" "$REVERSE_GEOCODING_DUMP_DIRECTORY"
|
||||
chown -R "$PUID":"$PGID" /data
|
||||
chmod 777 /data
|
||||
|
||||
####################
|
||||
# LIBRARY LOCATION #
|
||||
####################
|
||||
|
||||
if bashio::config.has_value "library_location"; then
|
||||
LIBRARY_LOCATION="$(bashio::config 'library_location')"
|
||||
bashio::log.info "Setting library location to $LIBRARY_LOCATION. This will not move any of your files, you'll need to do this manually"
|
||||
mkdir -p "$LIBRARY_LOCATION"
|
||||
chown -R "$PUID":"$PGID" "$LIBRARY_LOCATION"
|
||||
|
||||
# Check if the existing library is a directory and not a symlink and has contents
|
||||
if [ -d "$DATA_LOCATION/library" ] && [ ! -L "$DATA_LOCATION/library" ] && [ "$(ls -A "$DATA_LOCATION/library")" ]; then
|
||||
bashio::log.yellow "-------------------------------"
|
||||
bashio::log.warning "Library folder in $DATA_LOCATION/library already exists, is a real folder, and is not empty. Moving to $DATA_LOCATION/library_old"
|
||||
bashio::log.yellow "-------------------------------"
|
||||
mv "$DATA_LOCATION/library" "$DATA_LOCATION/library_old"
|
||||
sleep 5
|
||||
fi
|
||||
|
||||
# Create symbolic link only if it doesn't already exist or is incorrect
|
||||
if [ ! -L "$DATA_LOCATION/library" ] || [ "$(readlink -f "$DATA_LOCATION/library")" != "$LIBRARY_LOCATION" ]; then
|
||||
ln -sf "$LIBRARY_LOCATION" "$DATA_LOCATION/library"
|
||||
fi
|
||||
fi
|
||||
|
||||
##################
|
||||
# REDIS LOCATION #
|
||||
##################
|
||||
|
||||
echo "sed -i \"s=/config/redis=/data/redis=g\" /etc/s6*/s6*/*/run" >> /docker-mods
|
||||
echo "sed -i \"s=/config/log/redis=/data/log=g\" /etc/s6*/s6*/*/run" >> /docker-mods
|
||||
mkdir -p /data/redis
|
||||
mkdir -p /data/log
|
||||
chmod 777 /data/redis
|
||||
chmod 777 /data/log
|
||||
@@ -1,196 +0,0 @@
|
||||
#!/usr/bin/env bashio
|
||||
# shellcheck shell=bash
|
||||
# shellcheck disable=SC2155,SC2016
|
||||
set -e
|
||||
|
||||
# Function to export options from JSON to env variables
|
||||
export_options() {
|
||||
local json_source="/data/options.json"
|
||||
bashio::log.info "Exporting addon options from ${json_source}"
|
||||
|
||||
# Get all keys and export their raw values
|
||||
mapfile -t keys < <(jq -r 'keys[]' "${json_source}")
|
||||
for key in "${keys[@]}"; do
|
||||
local value
|
||||
value=$(jq -r ".${key}" "${json_source}")
|
||||
if bashio::config.false "verbose" || [[ "$key" == *"PASS"* ]]; then
|
||||
bashio::log.blue "${key}=******"
|
||||
else
|
||||
bashio::log.blue "${key}='${value}'"
|
||||
fi
|
||||
export "${key}=${value}"
|
||||
done
|
||||
}
|
||||
|
||||
# Function to check and adjust DB_HOSTNAME if necessary
|
||||
check_db_hostname() {
|
||||
if [[ "$DB_HOSTNAME" == "homeassistant.local" ]]; then
|
||||
local host_ip
|
||||
host_ip=$(bashio::network.ipv4_address)
|
||||
host_ip=${host_ip%/*}
|
||||
export DB_HOSTNAME="$host_ip"
|
||||
bashio::log.warning "DB_HOSTNAME was set to homeassistant.local. Using detected IP: $DB_HOSTNAME"
|
||||
fi
|
||||
|
||||
if ! ping -c 1 -W 3 "$DB_HOSTNAME" >/dev/null 2>&1; then
|
||||
bashio::log.warning "------------------------------------"
|
||||
bashio::log.warning "DB_HOSTNAME ($DB_HOSTNAME) is not reachable."
|
||||
bashio::log.warning "Please set it to the IP address of your database."
|
||||
bashio::log.warning "The addon will stop until this is fixed."
|
||||
bashio::log.warning "------------------------------------"
|
||||
sleep 30
|
||||
bashio::addon.stop
|
||||
else
|
||||
echo "$DB_HOSTNAME is reachable."
|
||||
fi
|
||||
}
|
||||
|
||||
# Function to migrate internal database to external storage if needed
|
||||
migrate_database() {
|
||||
if [ -f /share/postgresql_immich.tar.gz ]; then
|
||||
bashio::log.warning "Previous database export found at /share/postgresql_immich.tar.gz"
|
||||
elif [ -d /data/postgresql ]; then
|
||||
bashio::log.warning "Internal Postgres database detected. Migrating to /share/postgresql_immich.tar.gz"
|
||||
tar -zcvf /share/postgresql_immich.tar.gz /data/postgresql
|
||||
rm -rf /data/postgresql
|
||||
fi
|
||||
}
|
||||
|
||||
# Function to validate required configuration values
|
||||
validate_config() {
|
||||
local missing=false
|
||||
for var in DB_USERNAME DB_HOSTNAME DB_PASSWORD DB_DATABASE_NAME DB_PORT JWT_SECRET; do
|
||||
if ! bashio::config.has_value "${var}"; then
|
||||
bashio::log.error "Missing required configuration: ${var}"
|
||||
missing=true
|
||||
fi
|
||||
done
|
||||
if [ "$missing" = true ]; then
|
||||
bashio::exit.nok "Please ensure all required options are set."
|
||||
fi
|
||||
}
|
||||
|
||||
# Function to export DB variables to s6 environment if applicable
|
||||
export_db_env() {
|
||||
if [ -d /var/run/s6/container_environment ]; then
|
||||
for var in DB_USERNAME DB_PASSWORD DB_DATABASE_NAME DB_PORT DB_HOSTNAME JWT_SECRET; do
|
||||
printf "%s" "${!var}" > "/var/run/s6/container_environment/${var}"
|
||||
done
|
||||
fi
|
||||
}
|
||||
|
||||
# Function to set up the root user with a secure password
|
||||
setup_root_user() {
|
||||
# Generate DB_ROOT_PASSWORD if not set (12-character alphanumeric).
|
||||
if bashio::config.has_value "DB_ROOT_PASSWORD"; then
|
||||
export DB_ROOT_PASSWORD="$(bashio::config 'DB_ROOT_PASSWORD')"
|
||||
else
|
||||
bashio::log.warning "DB_ROOT_PASSWORD not set. Generating a random 12-character alphanumeric password and storing it in the addon options."
|
||||
export DB_ROOT_PASSWORD="$(tr -dc 'A-Za-z0-9' </dev/urandom | head -c12)"
|
||||
bashio::addon.option "DB_ROOT_PASSWORD" "${DB_ROOT_PASSWORD}"
|
||||
|
||||
# Store generated password in the s6 environment if available
|
||||
if [ -d /var/run/s6/container_environment ]; then
|
||||
printf "%s" "${DB_ROOT_PASSWORD}" > "/var/run/s6/container_environment/DB_ROOT_PASSWORD"
|
||||
fi
|
||||
fi
|
||||
|
||||
# Try to connect as root using the default insecure password.
|
||||
if psql "postgres://root:securepassword@${DB_HOSTNAME}:${DB_PORT}/postgres" -c '\q' 2>/dev/null; then
|
||||
bashio::log.info "Detected root user with default password. Updating to new DB_ROOT_PASSWORD..."
|
||||
psql "postgres://${DB_USERNAME}:${DB_PASSWORD}@${DB_HOSTNAME}:${DB_PORT}" <<EOF
|
||||
ALTER ROLE root WITH PASSWORD '${DB_ROOT_PASSWORD}';
|
||||
EOF
|
||||
else
|
||||
# Check if the root user exists.
|
||||
if ! psql "postgres://${DB_USERNAME}:${DB_PASSWORD}@${DB_HOSTNAME}:${DB_PORT}" -tAc "SELECT 1 FROM pg_roles WHERE rolname='root'" | grep -q 1; then
|
||||
bashio::log.info "Root user does not exist. Creating root user with DB_ROOT_PASSWORD..."
|
||||
psql "postgres://${DB_USERNAME}:${DB_PASSWORD}@${DB_HOSTNAME}:${DB_PORT}" <<EOF
|
||||
CREATE ROLE root WITH LOGIN SUPERUSER CREATEDB CREATEROLE PASSWORD '${DB_ROOT_PASSWORD}';
|
||||
EOF
|
||||
else
|
||||
bashio::log.info "Root user exists with a non-default password. No migration needed."
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
# Function to set up the database
|
||||
setup_database() {
|
||||
bashio::log.info "Setting up external PostgreSQL database..."
|
||||
|
||||
# Create the database if it does not exist
|
||||
if ! psql "postgres://${DB_USERNAME}:${DB_PASSWORD}@${DB_HOSTNAME}:${DB_PORT}/postgres" -tAc \
|
||||
"SELECT 1 FROM pg_database WHERE datname='${DB_DATABASE_NAME}';" | grep -q 1; then
|
||||
bashio::log.info "Database does not exist. Creating it now..."
|
||||
psql "postgres://${DB_USERNAME}:${DB_PASSWORD}@${DB_HOSTNAME}:${DB_PORT}" <<EOF
|
||||
CREATE DATABASE ${DB_DATABASE_NAME};
|
||||
EOF
|
||||
else
|
||||
bashio::log.info "Database ${DB_DATABASE_NAME} already exists. Ensuring it is configured correctly."
|
||||
fi
|
||||
|
||||
# Ensure the user exists and update its password
|
||||
psql "postgres://${DB_USERNAME}:${DB_PASSWORD}@${DB_HOSTNAME}:${DB_PORT}" <<EOF
|
||||
DO \$\$
|
||||
BEGIN
|
||||
IF NOT EXISTS (SELECT FROM pg_roles WHERE rolname = '${DB_USERNAME}') THEN
|
||||
CREATE USER ${DB_USERNAME} WITH ENCRYPTED PASSWORD '${DB_PASSWORD}';
|
||||
ELSE
|
||||
ALTER USER ${DB_USERNAME} WITH ENCRYPTED PASSWORD '${DB_PASSWORD}';
|
||||
END IF;
|
||||
END
|
||||
\$\$;
|
||||
EOF
|
||||
|
||||
# Ensure the user has full privileges on the database
|
||||
psql "postgres://${DB_USERNAME}:${DB_PASSWORD}@${DB_HOSTNAME}:${DB_PORT}" <<EOF
|
||||
GRANT ALL PRIVILEGES ON DATABASE ${DB_DATABASE_NAME} TO ${DB_USERNAME};
|
||||
EOF
|
||||
|
||||
bashio::log.info "Database setup completed successfully."
|
||||
}
|
||||
|
||||
# Function to check if vectors extension is enabled
|
||||
check_vector_extension() {
|
||||
echo "Checking if 'vectors' extension is enabled..."
|
||||
RESULT=$(psql "postgres://$DB_USERNAME:$DB_PASSWORD@$DB_HOSTNAME:$DB_PORT" -tAc "SELECT extname FROM pg_extension WHERE extname = 'vectors';")
|
||||
|
||||
if [[ "$RESULT" == "vectors" ]]; then
|
||||
echo "✅ 'vectors' extension is enabled."
|
||||
exit 0
|
||||
else
|
||||
bashio::log.warning "❌ 'vectors' extension is NOT enabled."
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
#########################
|
||||
# Main script execution #
|
||||
#########################
|
||||
|
||||
export_options
|
||||
check_db_hostname
|
||||
migrate_database
|
||||
validate_config
|
||||
|
||||
# Reload DB configuration from the addon options (this ensures we have the correct values)
|
||||
export DB_USERNAME=$(bashio::config 'DB_USERNAME')
|
||||
export DB_HOSTNAME=$(bashio::config 'DB_HOSTNAME')
|
||||
export DB_PASSWORD=$(bashio::config 'DB_PASSWORD')
|
||||
export DB_DATABASE_NAME=$(bashio::config 'DB_DATABASE_NAME')
|
||||
export DB_PORT=$(bashio::config 'DB_PORT')
|
||||
export JWT_SECRET=$(bashio::config 'JWT_SECRET')
|
||||
|
||||
export_db_env
|
||||
|
||||
setup_root_user
|
||||
setup_database
|
||||
check_vector_extension
|
||||
|
||||
echo ""
|
||||
bashio::log.yellow "-----------------------------------------------"
|
||||
bashio::low.warning "EXPERIMENTAL ADDON, CAN SHUTDOWN YOUR HA DUE TO RESOURCES EXCESSIVE USAGE"
|
||||
bashio::log.yellow "-----------------------------------------------"
|
||||
echo ""
|
||||
|
||||
sleep 5
|
||||
Reference in New Issue
Block a user