updated update script

This commit is contained in:
Snogard 2025-03-05 15:21:28 +01:00
parent 189ca080b6
commit 66890c5154

View File

@ -8,144 +8,21 @@ source /opt/kaido/src/libs/bash/lib.sh
root="/opt/kaido"
workdir="$HOME/.cache/kaido/update"
confdir="$KAIDO_CONFIG_FOLDER"
configureScript="$root/src/commands/configure.sh"
installScript="$root/src/commands/install.sh"
buildScript="$root/src/commands/build.sh"
updateConfig="$confdir/update.conf"
previusCommitFile="$workdir/previousCommit_kaido.txt"
previusCommitFile_config="$workdir/previousCommit_config.txt"
# ----------
# create necessary folder and files
if [ ! -d "${confdir}" ]; then
echo "Creating folder at path: ${confdir}"
sudo mkdir -p $confdir
fi
skipContainerUpdate=0
if [ ! -f "${updateConfig}" ]; then
echo "WARNING: container updates will be skipped"
skipContainerUpdate=1
#sudo touch $updateConfig
fi
if [ ! -d "${workdir}" ]; then
echo "Creating folder at path: ${workdir}"
sudo mkdir -p $workdir
fi
# ----------------------
echo -e "Updating repository\n"
# config repository
cd "$confdir"
sudo git reset --hard
sudo git pull
echo ""
currentCommit_config=$(git rev-parse --verify HEAD)
previusCommit_config=origin/master
if [ -f "${previusCommitFile_config}" ]; then
previusCommit_config=$(head -n 1 ${previusCommitFile_config})
fi
git rev-parse --verify HEAD | sudo tee $previusCommitFile_config
# ---------------
# kaido repository
cd $root
sudo git reset --hard
sudo git pull
echo ""
currentCommit=$(git rev-parse --verify HEAD)
previusCommit=origin/master
if [ -f "${previusCommitFile}" ]; then
previusCommit=$(head -n 1 ${previusCommitFile})
fi
git rev-parse --verify HEAD | sudo tee $previusCommitFile
# ------------
# read config files
installList=$(cat ${updateConfig} | grep -i install-)
configureList=$(cat ${updateConfig} | grep -i configure-)
buildList=$(cat ${updateConfig} | grep -i build-)
# -----------------------
echo -e "Starting installation and configs auto update\n"
echo "Kaido: "
echo "previus commit: ${previusCommit}"
echo "current commit: ${currentCommit}"
echo "Config:"
echo "previus commit: ${previusCommit_config}"
echo "current commit: ${currentCommit_config}"
echo ""
# TODO auto secret updates?
# auto update builds
# echo -e "Checking if custom images need to be built\n"
# for val in $buildList; do
# name=${val:5}
# if git diff --name-only $previusCommit $currentCommit build | grep -qi $name ; then
# echo -e "Building latest $name version\n"
# $buildScript $name
# fi
# done
# ---------------------------
# quit early
if [[ $skipContainerUpdate -eq 1 ]]; then
exit 0
fi
# auto update containers
echo -e "Checking if containers need to be updated\n"
for val in $installList; do
name=${val:8}
# TODO support parameters
if $(git -C "$root" diff --name-only $previusCommit $currentCommit src/commands/install | grep -qi $name) || \
( [ -f "$confdir/containers/$name/envs.sh" ] && $(git -C "$confdir" diff --name-only $previusCommit_config $currentCommit_config "$confdir/containers/$name/envs.sh" | grep -qi "envs\.sh" ) ) ;
then
echo -e "Updating ${name} installation\n"
$installScript $name
fi
done
echo -e "Installations updated\n"
# ( [ -d "$confdir/containers/$name/secrets" ] && [ ! $(git -C "$confdir" diff --name-only $previusCommit_config $currentCommit_config "$confdir/containers/$name/secrets") -z ] ) ;
# ---------------------------
# auto update configs
echo -e "Checking if container configs need to be updated\n"
for val in $configureList; do
name=${val:6}
if $(git -C "$root" diff --name-only $previusCommit_config $currentCommit_config "$confdir/containers/$name/config" | grep -qi $name) ; then
echo -e "Updating ${name} configuration\n"
$configureScript $name
fi
done
# ---------------------------
# TODO auto update sysconfig
echo -e "Configurations Updated\n"
echo "Update complete"
#TODO: remove in the future
kaido upgrade
echo "WARNING: the update process is being split into two commands.
kaido update: to download the latest container defitions and kaido versions
kaido upgrade: to donwload the lastest user configs and to actually upgrade your containers to the latest definitions
NOTE: when the transition is finished make sure that your kaido configs are in inside '$HOME/.config/kaido' instead of '/etc/kaido'"
echo "WARNING: if somethig fails, check your file permissions, make sure they belong to the correct user"
exit 0