enhance initial packages install/ update

This commit is contained in:
buanet
2023-02-20 16:18:22 +01:00
parent 6f83191969
commit 73225edba2
3 changed files with 33 additions and 18 deletions

View File

@@ -3,7 +3,8 @@
* upgrade node version to recommended node18 * upgrade node version to recommended node18
* rewrite of multihost setup handling * rewrite of multihost setup handling
* rewrite of custom objects and states db setup handling * rewrite of custom objects and states db setup handling
* extend logging and error handling * enhance initial packages install/ update
* enhance logging and error handling
* add volume instruction to dockerfile * add volume instruction to dockerfile
* add support for password protected custom objects and states db ([#306](https://github.com/buanet/ioBroker.docker/issues/306)) * add support for password protected custom objects and states db ([#306](https://github.com/buanet/ioBroker.docker/issues/306))
* add restore command to maintenance script * add restore command to maintenance script

View File

@@ -134,24 +134,29 @@ if [[ -f /opt/.first_run ]]; then
# Updating Linux packages # Updating Linux packages
if [[ "$offlinemode" = "true" ]]; then if [[ "$offlinemode" = "true" ]]; then
echo "OFFLINE_MODE is \"true\". Skipping Linux package updates on first run." echo "OFFLINE_MODE is \"true\". Skipping Linux package updates on first run."
echo ' '
else else
echo "Updating Linux packages on first run... " echo -n "Updating Linux packages on first run... "
bash /opt/scripts/setup_packages.sh -update set +e
bash /opt/scripts/setup_packages.sh -update > /opt/scripts/setup_packages.log 2>&1
return=$?
set -e
if [[ "$return" -ne 0 ]]; then
echo "Failed."
echo "For more details see \"/opt/scripts/setup_packages.log\"."
echo "Make sure the container has internet access to get the latest package updates."
echo "This has no impact to the setup process. The script will continue."
else
echo 'Done.' echo 'Done.'
echo ' '
fi fi
fi
echo ' '
# Installing packages from ENV # Installing packages from ENV
if [[ "$packages" != "" && "$offlinemode" = "true" ]]; then if [[ "$packages" != "" && "$offlinemode" = "true" ]]; then
echo "PACKAGES is set, but OFFLINE_MODE is \"true\". Skipping Linux package installation." echo "PACKAGES is set, but OFFLINE_MODE is \"true\". Skipping Linux package installation."
echo ' '
elif [[ "$packages" != "" ]]; then elif [[ "$packages" != "" ]]; then
echo "PACKAGES is set. Installing additional Linux packages." echo "PACKAGES is set. Installing the following additional Linux packages: ""$packages"
echo "Checking the following packages:" "$packages""... "
echo "$packages" > /opt/scripts/.docker_config/.packages echo "$packages" > /opt/scripts/.docker_config/.packages
bash /opt/scripts/setup_packages.sh -install bash /opt/scripts/setup_packages.sh -install
echo 'Done.'
echo ' '
fi fi
# Register maintenance script # Register maintenance script
echo -n 'Registering maintenance script as command... ' echo -n 'Registering maintenance script as command... '
@@ -159,11 +164,10 @@ if [[ -f /opt/.first_run ]]; then
echo "alias maint=\'/opt/scripts/maintenance.sh\'" >> /root/.bashrc echo "alias maint=\'/opt/scripts/maintenance.sh\'" >> /root/.bashrc
echo "alias m=\'/opt/scripts/maintenance.sh\'" >> /root/.bashrc echo "alias m=\'/opt/scripts/maintenance.sh\'" >> /root/.bashrc
echo 'Done.' echo 'Done.'
echo ' '
else else
echo "This is not the first run of this container. Skipping first run preparation." echo "This is not the first run of this container. Skipping first run preparation."
echo ' '
fi fi
echo ' '
# Setting UID and/ or GID # Setting UID and/ or GID
if [[ "$setgid" != "$(cat /etc/group | grep 'iobroker:' | cut -d':' -f3)" || "$setuid" != "$(cat /etc/passwd | grep 'iobroker:' | cut -d':' -f3)" ]]; then if [[ "$setgid" != "$(cat /etc/group | grep 'iobroker:' | cut -d':' -f3)" || "$setuid" != "$(cat /etc/passwd | grep 'iobroker:' | cut -d':' -f3)" ]]; then

View File

@@ -1,23 +1,33 @@
#!/bin/bash #!/bin/bash
export DEBIAN_FRONTEND=noninteractive
if [ "$1" == "-install" ] if [ "$1" == "-install" ]
then then
apt-get -qq update apt-get -q update >> /opt/scripts/setup_packages.log 2>&1
packages=$(cat /opt/scripts/.docker_config/.packages) packages=$(cat /opt/scripts/.docker_config/.packages)
echo ' '
for i in $packages; do for i in $packages; do
if [ "$(dpkg-query -W -f='${Status}' "$i" 2>/dev/null | grep -c "ok installed")" -eq 0 ]; if [ "$(dpkg-query -W -f='${Status}' "$i" 2>/dev/null | grep -c "ok installed")" -eq 0 ];
then then
echo "$i is not installed. Installing..." echo -n "$i is not installed. Installing..."
sudo apt-get -qq -y install "$i" DEBIAN_FRONTEND=noninteractive apt-get -q -y install "$i" >> /opt/scripts/setup_packages.log 2>&1
return=$?
if [[ "$return" -ne 0 ]]; then
echo "Failed."
echo "For more details see \"/opt/scripts/setup_packages.log\"."
echo ' '
else
echo "Done." echo "Done."
fi
else else
echo "$i is already installed." echo "$i is already installed."
fi fi
done done
elif [ "$1" == "-update" ] elif [ "$1" == "-update" ]
then then
apt-get -qq update apt-get -q update
apt-get -qq -y upgrade apt-get -q -y upgrade
else else
echo "No paramerter found!" echo "No paramerter found!"
exit 1 exit 1