new logic

This commit is contained in:
Alexandre
2021-12-10 22:23:24 +01:00
parent 21ab1fe6e6
commit 17a8e244ae

View File

@@ -4,16 +4,10 @@
# INIT #
########
# Messages ?
VERBOSE=false
# Non interactive
export DEBIAN_FRONTEND="noninteractive"
export LANG="C.UTF-8"
# Allow undefined variables
set +u 2>/dev/null
# Get env variables
PACKAGES="${@:-}"
[ $VERBOSE = true ] && echo "ENV : $PACKAGES"
PACKAGES="${*:-}"
[ "$VERBOSE" = true ] && echo "ENV : $PACKAGES"
############################
# CHECK WHICH BASE IS USED #
@@ -21,12 +15,12 @@ PACKAGES="${@:-}"
if [[ "$(apk -h 2>/dev/null)" ]]; then
# If apk based
[ $VERBOSE = true ] && echo "apk based"
[ "$VERBOSE" = true ] && echo "apk based"
PACKMANAGER="apk"
PACKAGES="apk add --no-cache $PACKAGES"
else
# If apt-get based
[ $VERBOSE = true ] && echo "apt based"
[ "$VERBOSE" = true ] && echo "apt based"
PACKMANAGER="apt"
PACKAGES="apt-get clean \
&& apt-get update \
@@ -45,71 +39,88 @@ PACKAGES="$PACKAGES jq curl"
# FOR EACH SCRIPT, SELECT PACKAGES
##################################
# Nginx
if ls /etc/nginx 1> /dev/null 2>&1; then
[ $VERBOSE = true ] && echo "nginx found"
[ $PACKMANAGER = "apk" ] && PACKAGES="$PACKAGES nginx"
[ $PACKMANAGER = "apt" ] && PACKAGES="$PACKAGES nginx"
mv /etc/nginx /etc/nginx2
fi
# 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
if ls $files/*smb* 1> /dev/null 2>&1; then
[ $VERBOSE = true ] && echo "smb found"
[ $PACKMANAGER = "apk" ] && PACKAGES="$PACKAGES cifs-utils keyutils samba samba-client"
[ $PACKMANAGER = "apt" ] && PACKAGES="$PACKAGES cifs-utils keyutils samba smbclient"
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
if ls $files/*vpn* 1> /dev/null 2>&1; then
[ $VERBOSE = true ] && echo "vpn found"
[ $PACKMANAGER = "apk" ] && PACKAGES="$PACKAGES coreutils openvpn"
[ $PACKMANAGER = "apt" ] && PACKAGES="$PACKAGES coreutils openvpn"
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 samba"
[ "$PACKMANAGER" = "apt" ] && PACKAGES="$PACKAGES cifs-utils keyutils samba"
fi
if ls $files/*global_var* 1> /dev/null 2>&1; then
[ $VERBOSE = true ] && echo "global_var found"
[ $PACKMANAGER = "apk" ] && PACKAGES="$PACKAGES jq"
[ $PACKMANAGER = "apt" ] && PACKAGES="$PACKAGES jq"
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
if ls $files/*yaml* 1> /dev/null 2>&1; then
echo "yaml found"
[ $PACKMANAGER = "apk" ] && PACKAGES="$PACKAGES yamllint"
[ $PACKMANAGER = "apt" ] && PACKAGES="$PACKAGES yamllint"
COMMAND="openvpn"
if grep -q -rn "$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
if [[ $(grep -rnw "$files/" -e 'git') ]]; then
[ $VERBOSE = true ] && echo "git found"
[ $PACKMANAGER = "apk" ] && PACKAGES="$PACKAGES git"
[ $PACKMANAGER = "apt" ] && PACKAGES="$PACKAGES git"
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
if [[ $(grep -rnw "$files/" -e 'sponge') ]]; then
[ $VERBOSE = true ] && echo "sponge found"
[ $PACKMANAGER = "apk" ] && PACKAGES="$PACKAGES moreutils"
[ $PACKMANAGER = "apt" ] && PACKAGES="$PACKAGES moreutils"
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
if [[ $(grep -rnw "$files/" -e 'sqlite') ]]; then
[ $VERBOSE = true ] && echo "sqlite found"
[ $PACKMANAGER = "apk" ] && PACKAGES="$PACKAGES sqlite"
[ $PACKMANAGER = "apt" ] && PACKAGES="$PACKAGES sqlite3"
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
if [[ $(grep -rnw "$files/" -e 'pip') ]]; then
[ $VERBOSE = true ] && echo "pip found"
[ $PACKMANAGER = "apk" ] && PACKAGES="$PACKAGES py3-pip"
[ $PACKMANAGER = "apt" ] && PACKAGES="$PACKAGES python-pip"
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
if [[ $(grep -rnw "$files/" -e 'wget') ]]; then
[ $VERBOSE = true ] && echo "wget found"
[ $PACKMANAGER = "apk" ] && PACKAGES="$PACKAGES wget"
[ $PACKMANAGER = "apt" ] && PACKAGES="$PACKAGES wget"
COMMAND="sqlite"
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 python-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
@@ -118,16 +129,13 @@ done
# INSTALL ELEMENTS #
####################
[ $VERBOSE = true ] && echo "installing packages $PACKAGES"
# Install apps
[ "$VERBOSE" = true ] && echo "installing packages $PACKAGES"
eval "$PACKAGES"
##########################
# CORRECT INSTALLED APPS #
##########################
# Replace nginx if installed
if ls /etc/nginx2 1> /dev/null 2>&1; then
[ $VERBOSE = true ] && echo "replace nginx2"
[ "$VERBOSE" = true ] && echo "replace nginx2"
rm -r /etc/nginx
mv /etc/nginx2 /etc/nginx
mkdir -p /var/log/nginx
@@ -138,14 +146,14 @@ fi
# INSTALL MANUAL APPS #
#######################
for files in "/etc/cont-init.d" "/etc/services.d" "/scripts"; do
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 -rnw "$files/" -e 'bashio') ]] && [ ! -f "/usr/bin/bashio" ]; then
[ $VERBOSE = true ] && echo "install 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
@@ -155,14 +163,14 @@ if ! ls $files 1> /dev/null 2>&1; then continue; fi
fi
# Lastversion
if [[ $(grep -rnw "$files/" -e 'lastversion') ]]; then
[ $VERBOSE = true ] && echo "install lastversion"
if grep -q -rnw "$files/" -e 'lastversion'; then
[ "$VERBOSE" = true ] && echo "install lastversion"
pip install lastversion
fi
# Tempio
if [[ $(grep -rnw "$files/" -e 'tempio') ]] && [ ! -f "/usr/bin/tempio" ]; then
[ $VERBOSE = true ] && echo "install 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}"