mirror of
https://github.com/alexbelgium/hassio-addons.git
synced 2026-06-08 16:45:56 +02:00
change templates location
This commit is contained in:
33
.templates/00-aaa_dockerfile_backup.sh
Normal file
33
.templates/00-aaa_dockerfile_backup.sh
Normal file
@@ -0,0 +1,33 @@
|
||||
#!/bin/bash
|
||||
# If dockerfile failed install manually
|
||||
if [ -e "/MODULESFILE" ]; then
|
||||
echo "Executing modules script"
|
||||
PACKAGES=$(</MODULESFILE)
|
||||
(
|
||||
##############################
|
||||
# Automatic modules download #
|
||||
##############################
|
||||
if ! command -v bash >/dev/null 2>/dev/null; then (apt-get update && apt-get install -yqq --no-install-recommends bash || apk add --no-cache bash); fi &&
|
||||
if ! command -v curl >/dev/null 2>/dev/null; then (apt-get update && apt-get install -yqq --no-install-recommends curl || apk add --no-cache curl); fi &&
|
||||
mkdir -p /tmpscripts /etc/cont-init.d &&
|
||||
for scripts in $MODULES; do curl -L -f -s "https://raw.githubusercontent.com/alexbelgium/hassio-addons/master/.templates/$scripts" -o /tmpscripts/"$scripts"; done &&
|
||||
if [ -d /etc/cont-init.d ]; then /bin/cp -rf /tmpscripts/* /etc/cont-init.d/ && chmod -R 755 /etc/cont-init.d; fi &&
|
||||
rm -rf /tmpscripts || printf '%s\n' "${MODULES:-}" >/MODULESFILE
|
||||
) >/dev/null
|
||||
|
||||
fi
|
||||
|
||||
if [ -e "/ENVFILE" ]; then
|
||||
echo "Executing script"
|
||||
PACKAGES=$(</ENVFILE)
|
||||
|
||||
#######################
|
||||
# Automatic installer #
|
||||
#######################
|
||||
if ! command -v bash >/dev/null 2>/dev/null; then (apt-get update && apt-get install -yqq --no-install-recommends bash || apk add --no-cache bash) >/dev/null; fi &&
|
||||
if ! command -v curl >/dev/null 2>/dev/null; then (apt-get update && apt-get install -yqq --no-install-recommends curl || apk add --no-cache curl) >/dev/null; fi &&
|
||||
curl -L -f -s "https://raw.githubusercontent.com/alexbelgium/hassio-addons/master/.templates/automatic_packages.sh" --output /automatic_packages.sh &&
|
||||
chmod 777 /automatic_packages.sh &&
|
||||
eval /./automatic_packages.sh "$PACKAGES" &&
|
||||
rm /automatic_packages.sh
|
||||
fi
|
||||
39
.templates/00-banner.sh
Normal file
39
.templates/00-banner.sh
Normal file
@@ -0,0 +1,39 @@
|
||||
#!/usr/bin/with-contenv bashio
|
||||
# ==============================================================================
|
||||
# Displays a simple add-on banner on startup
|
||||
# ==============================================================================
|
||||
echo "hello"
|
||||
if bashio::supervisor.ping; then
|
||||
bashio::log.blue \
|
||||
'-----------------------------------------------------------'
|
||||
bashio::log.blue " Add-on: $(bashio::addon.name)"
|
||||
bashio::log.blue " $(bashio::addon.description)"
|
||||
bashio::log.blue \
|
||||
'-----------------------------------------------------------'
|
||||
|
||||
bashio::log.blue " Add-on version: $(bashio::addon.version)"
|
||||
if bashio::var.true "$(bashio::addon.update_available)"; then
|
||||
bashio::log.magenta ' There is an update available for this add-on!'
|
||||
bashio::log.magenta \
|
||||
" Latest add-on version: $(bashio::addon.version_latest)"
|
||||
bashio::log.magenta ' Please consider upgrading as soon as possible.'
|
||||
else
|
||||
bashio::log.green ' You are running the latest version of this add-on.'
|
||||
fi
|
||||
|
||||
bashio::log.blue " System: $(bashio::info.operating_system)" \
|
||||
" ($(bashio::info.arch) / $(bashio::info.machine))"
|
||||
bashio::log.blue " Home Assistant Core: $(bashio::info.homeassistant)"
|
||||
bashio::log.blue " Home Assistant Supervisor: $(bashio::info.supervisor)"
|
||||
|
||||
bashio::log.blue \
|
||||
'-----------------------------------------------------------'
|
||||
bashio::log.blue \
|
||||
' Please, share the above information when looking for help'
|
||||
bashio::log.blue \
|
||||
' or support in, e.g., GitHub, forums'
|
||||
bashio::log.green \
|
||||
' https://github.com/alexbelgium/hassio-addons'
|
||||
bashio::log.blue \
|
||||
'-----------------------------------------------------------'
|
||||
fi
|
||||
8
.templates/00-bettercomments.sh
Normal file
8
.templates/00-bettercomments.sh
Normal file
@@ -0,0 +1,8 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Color comments
|
||||
#! Red
|
||||
#? Question
|
||||
#// Done
|
||||
#todo To do
|
||||
#* Green
|
||||
33
.templates/00-global_var.sh
Normal file
33
.templates/00-global_var.sh
Normal file
@@ -0,0 +1,33 @@
|
||||
#!/usr/bin/with-contenv bashio
|
||||
|
||||
###################################
|
||||
# Export all addon options as env #
|
||||
###################################
|
||||
|
||||
# For all keys in options.json
|
||||
JSONSOURCE="/data/options.json"
|
||||
|
||||
# Export keys as env variables
|
||||
# echo "All addon options were exported as variables"
|
||||
mapfile -t arr < <(jq -r 'keys[]' ${JSONSOURCE})
|
||||
for KEYS in ${arr[@]}; do
|
||||
# export key
|
||||
VALUE=$(jq ."$KEYS" ${JSONSOURCE})
|
||||
line="${KEYS}=${VALUE//[\"\']/}"
|
||||
# Use locally
|
||||
if ! bashio::config.false "verbose"; then bashio::log.blue "$line"; fi
|
||||
# Export the variable to run scripts
|
||||
line="${KEYS}=${VALUE//[\"\']/} 2>/dev/null || true"
|
||||
[ -f /etc/services.d/*/*run* ] && sed -i "1a export $line" /etc/services.d/*/*run* 2>/dev/null
|
||||
[ -f /etc/cont-init.d/*run* ] && sed -i "1a export $line" /etc/cont-init.d/*run* 2>/dev/null
|
||||
done
|
||||
|
||||
################
|
||||
# Set timezone #
|
||||
################
|
||||
if [ ! -z "TZ" ] && [ -f /etc/localtime ]; then
|
||||
if [ -f /usr/share/zoneinfo/"$TZ" ]; then
|
||||
echo "Timezone set from $(cat /etc/timezone) to $TZ"
|
||||
ln -snf /usr/share/zoneinfo/"$TZ" /etc/localtime && echo "$TZ" >/etc/timezone
|
||||
fi
|
||||
fi
|
||||
52
.templates/19-json_repair.sh
Normal file
52
.templates/19-json_repair.sh
Normal file
@@ -0,0 +1,52 @@
|
||||
#!/usr/bin/with-contenv bashio
|
||||
|
||||
JSONTOCHECK='/config/transmission/settings.json'
|
||||
JSONSOURCE='/defaults/settings.json'
|
||||
|
||||
# If json already exists
|
||||
if [ -f ${JSONTOCHECK} ]; then
|
||||
# Variables
|
||||
echo "Checking settings.json format"
|
||||
|
||||
# Check if json file valid or not
|
||||
jq . -S ${JSONTOCHECK} &>/dev/null && ERROR=false || ERROR=true
|
||||
if [ $ERROR = true ]; then
|
||||
bashio::log.fatal "Settings.json structure is abnormal, restoring options from scratch. Your old file is renamed as settings.json_old"
|
||||
mv ${JSONSOURCE} ${JSONSOURCE}_old
|
||||
cp ${JSONSOURCE} ${JSONTOCHECK}
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# Get the default keys from the original file
|
||||
mapfile -t arr < <(jq -r 'keys[]' ${JSONSOURCE})
|
||||
|
||||
# Check if all keys are still there, or add them
|
||||
for KEYS in ${arr[@]}; do
|
||||
# Check if key exists
|
||||
KEYSTHERE=$(jq "has(\"${KEYS}\")" ${JSONTOCHECK})
|
||||
if [ $KEYSTHERE != "true" ]; then
|
||||
#Fetch initial value
|
||||
JSONSOURCEVALUE=$(jq -r ".\"$KEYS\"" ${JSONSOURCE})
|
||||
#Add key
|
||||
sed -i "3 i\"${KEYS}\": \"${JSONSOURCEVALUE}\"," ${JSONTOCHECK}
|
||||
# Message
|
||||
bashio::log.warning "${KEYS} was missing from your settings.json, it was added with the default value ${JSONSOURCEVALUE}"
|
||||
fi
|
||||
done
|
||||
|
||||
# Show structure in a nice way
|
||||
jq . -S ${JSONTOCHECK} | cat >temp.json && mv temp.json ${JSONTOCHECK}
|
||||
|
||||
# Message
|
||||
bashio::log.info "Your settings.json was checked and seems perfectly normal!"
|
||||
fi
|
||||
|
||||
# Repair structure
|
||||
################
|
||||
#jq . -S $CONFIGDIR/settings.json | cat >temp.json && mv temp.json $CONFIGDIR/settings.json
|
||||
#echo "Making sure settings.json structure is good"
|
||||
#for KEYS in "incomplete-dir" "download-dir" "rpc-host-whitelist-enabled" "rpc-authentication-required" "rpc-username" "rpc-password" "rpc-whitelist-enabled" "rpc-whitelist"; do
|
||||
# KEYSTHERE=$(jq "has(\"${KEYS}\")" $CONFIGDIR/settings.json)
|
||||
# [ $KEYSTHERE != "true" ] && sed -i "3 i\"${KEYS}\": null," $CONFIGDIR/settings.json && echo "... $KEYS was missing, added"
|
||||
#done
|
||||
#jq . -S $CONFIGDIR/settings.json | cat >temp.json && mv temp.json $CONFIGDIR/settings.json
|
||||
103
.templates/90-config_yaml.sh
Normal file
103
.templates/90-config_yaml.sh
Normal file
@@ -0,0 +1,103 @@
|
||||
#!/usr/bin/with-contenv bashio
|
||||
|
||||
##################
|
||||
# INITIALIZATION #
|
||||
##################
|
||||
|
||||
# Where is the config
|
||||
CONFIGSOURCE=$(bashio::config "CONFIG_LOCATION")
|
||||
|
||||
# Check if config file is there, or create one from template
|
||||
if [ -f $CONFIGSOURCE ]; then
|
||||
echo "Using config file found in $CONFIGSOURCE"
|
||||
else
|
||||
echo "No config file, creating one from template"
|
||||
# Create folder
|
||||
mkdir -p "$(dirname "${CONFIGSOURCE}")"
|
||||
# Placing template in config
|
||||
if [ -f /templates/config.yaml ]; then
|
||||
# Use available template
|
||||
cp /templates/config.yaml "$(dirname "${CONFIGSOURCE}")"
|
||||
else
|
||||
# Download template
|
||||
TEMPLATESOURCE="https://raw.githubusercontent.com/alexbelgium/hassio-addons/master/.templates/config.template"
|
||||
curl -L -f -s $TEMPLATESOURCE --output $CONFIGSOURCE
|
||||
fi
|
||||
# Need to restart
|
||||
bashio::log.fatal "Config file not found, creating a new one. Please customize the file in $CONFIGSOURCE before restarting."
|
||||
# bashio::exit.nok
|
||||
fi
|
||||
|
||||
# Check if yaml is valid
|
||||
EXIT_CODE=0
|
||||
yamllint -d relaxed $CONFIGSOURCE &>ERROR || EXIT_CODE=$?
|
||||
if [ $EXIT_CODE = 0 ]; then
|
||||
echo "Config file is a valid yaml"
|
||||
else
|
||||
cat ERROR
|
||||
bashio::log.fatal "Config file has an invalid yaml format. Please check the file in $CONFIGSOURCE. Errors list above."
|
||||
# bashio::exit.nok
|
||||
fi
|
||||
|
||||
# Export all yaml entries as env variables
|
||||
# Helper function
|
||||
function parse_yaml {
|
||||
local prefix=$2 || local prefix=""
|
||||
local s='[[:space:]]*' w='[a-zA-Z0-9_]*' fs=$(echo @ | tr @ '\034')
|
||||
sed -ne "s|^\($s\):|\1|" \
|
||||
-e "s| #.*$||g" \
|
||||
-e "s|#.*$||g" \
|
||||
-e "s|^\($s\)\($w\)$s:$s[\"']\(.*\)[\"']$s\$|\1$fs\2$fs\3|p" \
|
||||
-e "s|^\($s\)\($w\)$s:$s\(.*\)$s\$|\1$fs\2$fs\3|p" $1 |
|
||||
awk -F$fs '{
|
||||
indent = length($1)/2;
|
||||
vname[indent] = $2;
|
||||
for (i in vname) {if (i > indent) {delete vname[i]}}
|
||||
if (length($3) > 0) {
|
||||
vn=""; for (i=0; i<indent; i++) {vn=(vn)(vname[i])("_")}
|
||||
printf("%s%s%s=\"%s\"\n", "'$prefix'",vn, $2, $3);
|
||||
}
|
||||
}'
|
||||
}
|
||||
|
||||
# Get variables and export
|
||||
bashio::log.info "Starting the app with the variables in in $CONFIGSOURCE"
|
||||
# Get list of parameters in a file
|
||||
parse_yaml "$CONFIGSOURCE" "" >/tmpfile
|
||||
while IFS= read -r line; do
|
||||
# Clean output
|
||||
line=${line//[\"\']/}
|
||||
# Check if secret
|
||||
if [[ "${line}" == *'!secret '* ]]; then
|
||||
echo "secret detected"
|
||||
secret=${line#*secret }
|
||||
# Check if single match
|
||||
secretnum=$(sed -n "/$secret:/=" /config/secrets.yaml)
|
||||
[[ $(echo $secretnum) == *' '* ]] && bashio::exit.nok "There are multiple matches for your password name. Please check your secrets.yaml file"
|
||||
# Get text
|
||||
secret=$(sed -n "/$secret:/p" /config/secrets.yaml)
|
||||
secret=${secret#*: }
|
||||
line="${line%%=*}=$secret"
|
||||
fi
|
||||
# Data validation
|
||||
if [[ $line =~ ^.+[=].+$ ]]; then
|
||||
export $line
|
||||
# Export the variable
|
||||
sed -i "1a export $line" /etc/services.d/*/*run* 2>/dev/null || true
|
||||
sed -i "1a export $line" /etc/cont-init.d/*run* 2>/dev/null || true
|
||||
sed -i "1a export $line" /scripts/*run* 2>/dev/null || true
|
||||
# Show in log
|
||||
if ! bashio::config.false "verbose"; then bashio::log.blue "$line"; fi
|
||||
else
|
||||
bashio::exit.nok "$line does not follow the correct structure. Please check your yaml file."
|
||||
fi
|
||||
done <"/tmpfile"
|
||||
|
||||
# Test mode
|
||||
TZ=$(bashio::config "TZ")
|
||||
if [ $TZ = "test" ]; then
|
||||
echo "secret mode found, launching script in /config/test.sh"
|
||||
cd /config
|
||||
chmod 777 test.sh
|
||||
./test.sh
|
||||
fi
|
||||
28
.templates/90-dns_set.sh
Normal file
28
.templates/90-dns_set.sh
Normal file
@@ -0,0 +1,28 @@
|
||||
#!/usr/bin/with-contenv bashio
|
||||
|
||||
###############
|
||||
# DNS SETTING #
|
||||
###############
|
||||
|
||||
# Avoid usage of local dns such as adguard home or pihole\n"
|
||||
|
||||
if bashio::config.has_value 'DNS_server'; then
|
||||
# Define variables
|
||||
DNSSERVER=$(bashio::config 'DNS_server')
|
||||
DNS=""
|
||||
DNSLIST=""
|
||||
|
||||
# Get DNS servers
|
||||
for server in ${DNSSERVER//,/ } # Separate comma separated values
|
||||
do
|
||||
DNS="${DNS}nameserver $server\n"
|
||||
DNSLIST="$server $DNSLIST"
|
||||
done
|
||||
|
||||
# Write resolv.conf
|
||||
printf "${DNS}" > /etc/resolv.conf
|
||||
chmod 644 /etc/resolv.conf
|
||||
bashio::log.info "DNS SERVERS set to $DNSLIST"
|
||||
else
|
||||
bashio::log.info "DNS Servers option empty. Using default router (or HA) dns servers."
|
||||
fi
|
||||
12
.templates/91-silent.sh
Normal file
12
.templates/91-silent.sh
Normal file
@@ -0,0 +1,12 @@
|
||||
#!/usr/bin/with-contenv bashio
|
||||
|
||||
###############
|
||||
# SILENT MODE #
|
||||
###############
|
||||
|
||||
if bashio::config.true 'silent'; then
|
||||
APPEND=' > /dev/null'
|
||||
[ -f /etc/services.d/*/run ] && sed -i '$s|$|'"$APPEND"'|' /etc/services.d/*/run
|
||||
[ -f /etc/cont-init.d/*/*run* ] && sed -i '$s|$|'"$APPEND"'|' /etc/cont-init.d/*/*run*
|
||||
bashio::log.info 'Silent mode activated, all logs from emby server are hidden. Disable this option if you need to troubleshoot the addon.'
|
||||
fi
|
||||
32
.templates/92-local_mounts.sh
Normal file
32
.templates/92-local_mounts.sh
Normal file
@@ -0,0 +1,32 @@
|
||||
#!/usr/bin/with-contenv bashio
|
||||
|
||||
######################
|
||||
# MOUNT LOCAL SHARES #
|
||||
######################
|
||||
|
||||
# Mount local Share if configured
|
||||
if bashio::config.has_value 'localdisks'; then
|
||||
|
||||
MOREDISKS=$(bashio::config 'localdisks')
|
||||
echo "Local Disks mounting..."
|
||||
|
||||
# Separate comma separated values
|
||||
for disk in ${MOREDISKS//,/ }; do
|
||||
|
||||
# Mount by device as default
|
||||
devpath=/dev
|
||||
|
||||
# Mount as label
|
||||
[ ${disk:0:2} != "sd" ] && devpath=/dev/disk/by-label
|
||||
|
||||
# Creates dir
|
||||
mkdir -p /mnt/$disk
|
||||
chown -R $(id -u):$(id -g) /mnt/$disk
|
||||
# Legacy mounting : mount to share if still exists (avoid breaking changes)
|
||||
[ -d /share/$disk ] && mount $devpath/$disk /share/$disk || true
|
||||
# Mount
|
||||
mount $devpath/$disk /mnt/$disk && bashio::log.info "Success! $disk mounted to /mnt/$disk" || (bashio::log.fatal "Unable to mount local drives! Please check the name." && rmdir /mnt/$disk)
|
||||
|
||||
done
|
||||
|
||||
fi
|
||||
83
.templates/92-smb_mounts.sh
Normal file
83
.templates/92-smb_mounts.sh
Normal file
@@ -0,0 +1,83 @@
|
||||
#!/usr/bin/with-contenv bashio
|
||||
|
||||
#########################
|
||||
# MOUNT SMB SHARES v1.6 #
|
||||
#########################
|
||||
if bashio::config.has_value 'networkdisks'; then
|
||||
|
||||
# Define variables
|
||||
MOREDISKS=$(bashio::config 'networkdisks')
|
||||
CIFS_USERNAME=$(bashio::config 'cifsusername')
|
||||
CIFS_PASSWORD=$(bashio::config 'cifspassword')
|
||||
MOUNTED=false
|
||||
SMBVERS=""
|
||||
SECVERS=""
|
||||
|
||||
# Mount CIFS Share if configured and if Protection Mode is active
|
||||
echo 'Mounting smb share(s)...'
|
||||
|
||||
if bashio::config.has_value 'cifsdomain'; then
|
||||
DOMAIN=",domain=$(bashio::config 'cifsdomain')"
|
||||
else
|
||||
DOMAIN=""
|
||||
fi
|
||||
|
||||
# Mounting disks
|
||||
for disk in ${MOREDISKS//,/ }; do # Separate comma separated values
|
||||
|
||||
# Clean name of network share
|
||||
disk=$(echo $disk | sed "s,/$,,") # Remove / at end of name
|
||||
diskname=${disk//\\//} #replace \ with /
|
||||
diskname=${diskname##*/} # Get only last part of the name
|
||||
|
||||
# Data validation
|
||||
if [[ ! $disk =~ ^.*+[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+[/]+.*+$ ]]; then
|
||||
bashio::log.fatal "The structure of your \"networkdisks\" option : \"$disk\" doesn't seem correct, please use a structure like //123.12.12.12/sharedfolder,//123.12.12.12/sharedfolder2. If you don't use it, you can simply remove the text, this will avoid this error message in the future."
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# Prepare mount point
|
||||
mkdir -p /mnt/$diskname
|
||||
chown -R root:root /mnt/$diskname
|
||||
|
||||
#Tries to mount with default options
|
||||
mount -t cifs -o rw,username=$CIFS_USERNAME,password=${CIFS_PASSWORD}$DOMAIN $disk /mnt/$diskname 2>ERRORCODE && MOUNTED=true || MOUNTED=false
|
||||
|
||||
# if Fail test different smb and sec versions
|
||||
if [ $MOUNTED = false ]; then
|
||||
for SMBVERS in ",vers=3" ",vers=1.0" ",vers=2.1" ",vers=3.0" ",nodfs" ",uid=0,gid=0,forceuid,forcegid" ",noforceuid,noforcegid" ",${DOMAIN:-WORKGROUP}"; do
|
||||
mount -t cifs -o rw,file_mode=0777,dir_mode=0777,username=$CIFS_USERNAME,password=${CIFS_PASSWORD}$SMBVERS $disk /mnt/$diskname 2>/dev/null && MOUNTED=true && break || MOUNTED=false
|
||||
for SECVERS in ",sec=ntlmi" ",sec=ntlmv2" ",sec=ntlmv2i" ",sec=ntlmssp" ",sec=ntlmsspi" ",sec=ntlm" ",sec=krb5i" ",sec=krb5" ",iocharset=utf8"; do
|
||||
mount -t cifs -o rw,file_mode=0777,dir_mode=0777,username=$CIFS_USERNAME,password=${CIFS_PASSWORD}$SMBVERS$SECVERS $disk /mnt/$disk name 2>/dev/null && MOUNTED=true && break 2 && break || MOUNTED=false
|
||||
done
|
||||
done
|
||||
fi
|
||||
|
||||
# Messages
|
||||
if [ $MOUNTED = true ] && [ "mountpoint -q /mnt/$diskname" ]; then
|
||||
#Test write permissions
|
||||
touch /mnt/$diskname/testaze && rm /mnt/$diskname/testaze &&
|
||||
bashio::log.info "... $disk successfully mounted to /mnt/$diskname with options $SMBVERS$SECVERS" ||
|
||||
bashio::log.fatal "Disk is mounted, however unable to write in the shared disk. Please check UID/GID for permissions, and if the share is rw"
|
||||
|
||||
else
|
||||
# Mounting failed messages
|
||||
bashio::log.fatal "Error, unable to mount $disk to /mnt/$diskname with username $CIFS_USERNAME, $CIFS_PASSWORD. Please check your remote share path, username, password, domain, try putting 0 in UID and GID"
|
||||
bashio::log.fatal "Here is some debugging info :"
|
||||
|
||||
# Provide debugging info
|
||||
smbclient -V &>/dev/null || apt-get install smbclient || apk add --no-cache samba-client
|
||||
#smbclient $disk -U $CIFS_USERNAME%$CIFS_PASSWORD || true
|
||||
smbclient -L $disk -U $CIFS_USERNAME%$CIFS_PASSWORD || true
|
||||
|
||||
# Error code
|
||||
bashio::log.fatal "Error read : $(<ERRORCODE)"
|
||||
rm ERRORCODE
|
||||
|
||||
# clean folder
|
||||
umount /mnt/$diskname 2>/dev/null || true
|
||||
rmdir /mnt/$diskname || true
|
||||
fi
|
||||
|
||||
done
|
||||
fi
|
||||
8
.templates/99-custom_script.sh
Normal file
8
.templates/99-custom_script.sh
Normal file
@@ -0,0 +1,8 @@
|
||||
#!/bin/bash
|
||||
|
||||
CONFIGSOURCE=$(bashio::config "CONFIG_LOCATION")
|
||||
CONFIGSOURCE="$(dirname "${CONFIGSOURCE}")"
|
||||
|
||||
if [ -f "$CONFIGSOURCE"/script.sh ]; then
|
||||
"$CONFIGSOURCE"./script.sh
|
||||
fi
|
||||
213
.templates/automatic_packages.sh
Normal file
213
.templates/automatic_packages.sh
Normal file
@@ -0,0 +1,213 @@
|
||||
#!/bin/bash
|
||||
|
||||
########
|
||||
# INIT #
|
||||
########
|
||||
|
||||
#Verbose or not
|
||||
VERBOSE=false
|
||||
#Avoid fails on non declared variables
|
||||
set +u 2>/dev/null
|
||||
#If no packages, empty
|
||||
PACKAGES="${*:-}"
|
||||
#Avoids messages if non interactive
|
||||
echo 'debconf debconf/frontend select Noninteractive' | debconf-set-selections || true
|
||||
|
||||
[ "$VERBOSE" = true ] && echo "ENV : $PACKAGES"
|
||||
|
||||
############################
|
||||
# CHECK WHICH BASE IS USED #
|
||||
############################
|
||||
|
||||
COMMAND="apk"
|
||||
if command -v $COMMAND &>/dev/null; then
|
||||
# If apk based
|
||||
[ "$VERBOSE" = true ] && echo "apk based"
|
||||
PACKMANAGER="apk"
|
||||
else
|
||||
# If apt-get based
|
||||
[ "$VERBOSE" = true ] && echo "apt based"
|
||||
PACKMANAGER="apt"
|
||||
fi
|
||||
|
||||
###################
|
||||
# DEFINE PACKAGES #
|
||||
###################
|
||||
|
||||
# ADD GENERAL ELEMENTS
|
||||
######################
|
||||
|
||||
PACKAGES="$PACKAGES jq curl vim"
|
||||
|
||||
# FOR EACH SCRIPT, SELECT PACKAGES
|
||||
##################################
|
||||
|
||||
# Scripts
|
||||
for files in "/etc/cont-init.d" "/etc/services.d" "/scripts"; do
|
||||
# Next directory if does not exists
|
||||
if ! ls $files 1>/dev/null 2>&1; then continue; fi
|
||||
|
||||
# Test each possible command
|
||||
COMMAND="nginx"
|
||||
if grep -q -rnw "$files/" -e "$COMMAND" && ! command -v $COMMAND &>/dev/null; then
|
||||
[ "$VERBOSE" = true ] && echo "$COMMAND required"
|
||||
[ "$PACKMANAGER" = "apk" ] && PACKAGES="$PACKAGES nginx"
|
||||
[ "$PACKMANAGER" = "apt" ] && PACKAGES="$PACKAGES nginx"
|
||||
if ls /etc/nginx 1>/dev/null 2>&1; then mv /etc/nginx /etc/nginx2; fi
|
||||
fi
|
||||
|
||||
COMMAND="cifs"
|
||||
if grep -q -rnw "$files/" -e "$COMMAND" && ! command -v $COMMAND &>/dev/null; then
|
||||
[ "$VERBOSE" = true ] && echo "$COMMAND required"
|
||||
[ "$PACKMANAGER" = "apk" ] && PACKAGES="$PACKAGES cifs-utils keyutils"
|
||||
[ "$PACKMANAGER" = "apt" ] && PACKAGES="$PACKAGES cifs-utils keyutils"
|
||||
fi
|
||||
|
||||
COMMAND="smbclient"
|
||||
if grep -q -rnw "$files/" -e "$COMMAND" && ! command -v $COMMAND &>/dev/null; then
|
||||
[ "$VERBOSE" = true ] && echo "$COMMAND required"
|
||||
[ "$PACKMANAGER" = "apk" ] && PACKAGES="$PACKAGES samba samba-client"
|
||||
[ "$PACKMANAGER" = "apt" ] && PACKAGES="$PACKAGES samba smbclient"
|
||||
fi
|
||||
|
||||
COMMAND="openvpn"
|
||||
if grep -q -rnw "$files/" -e "$COMMAND" && ! command -v $COMMAND &>/dev/null; then
|
||||
[ "$VERBOSE" = true ] && echo "$COMMAND required"
|
||||
[ "$PACKMANAGER" = "apk" ] && PACKAGES="$PACKAGES coreutils openvpn"
|
||||
[ "$PACKMANAGER" = "apt" ] && PACKAGES="$PACKAGES coreutils openvpn"
|
||||
fi
|
||||
|
||||
COMMAND="jq"
|
||||
if grep -q -rnw "$files/" -e "$COMMAND" && ! command -v $COMMAND &>/dev/null; then
|
||||
[ "$VERBOSE" = true ] && echo "$COMMAND required"
|
||||
[ "$PACKMANAGER" = "apk" ] && PACKAGES="$PACKAGES jq"
|
||||
[ "$PACKMANAGER" = "apt" ] && PACKAGES="$PACKAGES jq"
|
||||
fi
|
||||
|
||||
COMMAND="yamllint"
|
||||
if grep -q -rnw "$files/" -e "$COMMAND" && ! command -v $COMMAND &>/dev/null; then
|
||||
[ "$VERBOSE" = true ] && echo "$COMMAND required"
|
||||
[ "$PACKMANAGER" = "apk" ] && PACKAGES="$PACKAGES yamllint"
|
||||
[ "$PACKMANAGER" = "apt" ] && PACKAGES="$PACKAGES yamllint"
|
||||
fi
|
||||
|
||||
COMMAND="git"
|
||||
if grep -q -rnw "$files/" -e "$COMMAND" && ! command -v $COMMAND &>/dev/null; then
|
||||
[ "$VERBOSE" = true ] && echo "$COMMAND required"
|
||||
[ "$PACKMANAGER" = "apk" ] && PACKAGES="$PACKAGES git"
|
||||
[ "$PACKMANAGER" = "apt" ] && PACKAGES="$PACKAGES git"
|
||||
fi
|
||||
|
||||
COMMAND="sponge"
|
||||
if grep -q -rnw "$files/" -e "$COMMAND" && ! command -v $COMMAND &>/dev/null; then
|
||||
[ "$VERBOSE" = true ] && echo "$COMMAND required"
|
||||
[ "$PACKMANAGER" = "apk" ] && PACKAGES="$PACKAGES moreutils"
|
||||
[ "$PACKMANAGER" = "apt" ] && PACKAGES="$PACKAGES moreutils"
|
||||
fi
|
||||
|
||||
COMMAND="sqlite3"
|
||||
if grep -q -rnw "$files/" -e "$COMMAND" && ! command -v $COMMAND &>/dev/null; then
|
||||
[ "$VERBOSE" = true ] && echo "$COMMAND required"
|
||||
[ "$PACKMANAGER" = "apk" ] && PACKAGES="$PACKAGES sqlite"
|
||||
[ "$PACKMANAGER" = "apt" ] && PACKAGES="$PACKAGES sqlite3"
|
||||
fi
|
||||
|
||||
COMMAND="pip"
|
||||
if grep -q -rnw "$files/" -e "$COMMAND" && ! command -v $COMMAND &>/dev/null; then
|
||||
[ "$VERBOSE" = true ] && echo "$COMMAND required"
|
||||
[ "$PACKMANAGER" = "apk" ] && PACKAGES="$PACKAGES py3-pip"
|
||||
[ "$PACKMANAGER" = "apt" ] && PACKAGES="$PACKAGES pip"
|
||||
fi
|
||||
|
||||
COMMAND="wget"
|
||||
if grep -q -rnw "$files/" -e "$COMMAND" && ! command -v $COMMAND &>/dev/null; then
|
||||
[ "$VERBOSE" = true ] && echo "$COMMAND required"
|
||||
[ "$PACKMANAGER" = "apk" ] && PACKAGES="$PACKAGES wget"
|
||||
[ "$PACKMANAGER" = "apt" ] && PACKAGES="$PACKAGES wget"
|
||||
fi
|
||||
|
||||
done
|
||||
|
||||
####################
|
||||
# INSTALL ELEMENTS #
|
||||
####################
|
||||
|
||||
# Install apps
|
||||
[ "$VERBOSE" = true ] && echo "installing packages $PACKAGES"
|
||||
[ "$PACKMANAGER" = "apt" ] && apt-get update >/dev/null || true
|
||||
|
||||
# Install apps one by one to allow failures
|
||||
for packagestoinstall in $PACKAGES; do
|
||||
[ "$VERBOSE" = true ] && echo "... $packagestoinstall"
|
||||
if [ "$PACKMANAGER" = "apk" ]; then
|
||||
apk add --no-cache $packagestoinstall &>/dev/null || echo "Error : $packagestoinstall not found"
|
||||
elif [ "$PACKMANAGER" = "apt" ]; then
|
||||
apt-get install -yqq --no-install-recommends $packagestoinstall &>/dev/null || echo "Error : $packagestoinstall not found"
|
||||
fi
|
||||
[ "$VERBOSE" = true ] && echo "... $packagestoinstall done"
|
||||
done
|
||||
|
||||
# Clean after install
|
||||
[ "$VERBOSE" = true ] && echo "Cleaning apt cache"
|
||||
[ "$PACKMANAGER" = "apt" ] && apt-get clean >/dev/null || true
|
||||
|
||||
# Replace nginx if installed
|
||||
if ls /etc/nginx2 1>/dev/null 2>&1; then
|
||||
[ "$VERBOSE" = true ] && echo "replace nginx2"
|
||||
rm -r /etc/nginx
|
||||
mv /etc/nginx2 /etc/nginx
|
||||
mkdir -p /var/log/nginx
|
||||
touch /var/log/nginx/error.log
|
||||
fi
|
||||
|
||||
#######################
|
||||
# INSTALL MANUAL APPS #
|
||||
#######################
|
||||
|
||||
for files in "/scripts" "/etc/services.d" "/etc/cont-init.d"; do
|
||||
|
||||
# Next directory if does not exists
|
||||
if ! ls $files 1>/dev/null 2>&1; then continue; fi
|
||||
|
||||
# Bashio
|
||||
if grep -q -rnw "$files/" -e 'bashio' && [ ! -f "/usr/bin/bashio" ]; then
|
||||
[ "$VERBOSE" = true ] && echo "install bashio"
|
||||
BASHIO_VERSION="0.14.3"
|
||||
mkdir -p /tmp/bashio
|
||||
curl -L -f -s "https://github.com/hassio-addons/bashio/archive/v${BASHIO_VERSION}.tar.gz" | tar -xzf - --strip 1 -C /tmp/bashio
|
||||
mv /tmp/bashio/lib /usr/lib/bashio
|
||||
ln -s /usr/lib/bashio/bashio /usr/bin/bashio
|
||||
rm -rf /tmp/bashio
|
||||
fi
|
||||
|
||||
# Lastversion
|
||||
if grep -q -rnw "$files/" -e 'lastversion'; then
|
||||
[ "$VERBOSE" = true ] && echo "install lastversion"
|
||||
pip install lastversion
|
||||
fi
|
||||
|
||||
# Tempio
|
||||
if grep -q -rnw "$files/" -e 'tempio' && [ ! -f "/usr/bin/tempio" ]; then
|
||||
[ "$VERBOSE" = true ] && echo "install tempio"
|
||||
TEMPIO_VERSION="2021.09.0"
|
||||
BUILD_ARCH="$(bashio::info.arch)"
|
||||
curl -L -f -s -o /usr/bin/tempio "https://github.com/home-assistant/tempio/releases/download/${TEMPIO_VERSION}/tempio_${BUILD_ARCH}"
|
||||
chmod a+x /usr/bin/tempio
|
||||
fi
|
||||
|
||||
# Mustache
|
||||
COMMAND="mustache"
|
||||
if grep -q -rnw "$files/" -e "$COMMAND" && ! command -v $COMMAND &>/dev/null; then
|
||||
[ "$VERBOSE" = true ] && echo "$COMMAND required"
|
||||
[ "$PACKMANAGER" = "apk" ] && apk add --no-cache go npm &&
|
||||
apk upgrade --no-cache &&
|
||||
apk add --no-cache --virtual .build-deps build-base git go &&
|
||||
go get -u github.com/quantumew/mustache-cli &&
|
||||
cp "$GOPATH"/bin/* /usr/bin/ &&
|
||||
rm -rf "$GOPATH" /var/cache/apk/* /tmp/src &&
|
||||
apk del .build-deps xz build-base
|
||||
[ "$PACKMANAGER" = "apt" ] && apt-get update &&
|
||||
apt-get install -yqq go npm node-mustache
|
||||
fi
|
||||
|
||||
done
|
||||
10
.templates/config.template
Normal file
10
.templates/config.template
Normal file
@@ -0,0 +1,10 @@
|
||||
#============================#
|
||||
# ALEXBELGIUM'S ENV INJECTOR #
|
||||
#============================#
|
||||
#
|
||||
# All env variables set in this file will be enabled in the app
|
||||
# This allows enabling more options that normally available in the addon options
|
||||
# This file must be filled according to the yaml format. If the format is invalid, the addon will note an error. To validate your yaml, you can use the free online tool http://www.yamllint.com/
|
||||
|
||||
# EXAMPLE of the format (you need to remove the # for it to become active)
|
||||
# TZ: Europe/Paris
|
||||
8
.templates/show_text_color
Normal file
8
.templates/show_text_color
Normal file
@@ -0,0 +1,8 @@
|
||||
#Define colors
|
||||
red=1
|
||||
green=2
|
||||
yellow=3
|
||||
blue=4
|
||||
violet=5
|
||||
teal=6
|
||||
echo "$(tput setaf $red)ENV exported : $word$(tput sgr0)"
|
||||
Reference in New Issue
Block a user