mirror of
https://gitlab.com/Snogard/kaido.git
synced 2025-06-25 02:13:00 +02:00
added new upgrade command
This commit is contained in:
parent
70477b23f5
commit
1be3d1fb30
@ -143,4 +143,8 @@ echo -e "Configurations Updated\n"
|
||||
|
||||
echo "Update complete"
|
||||
|
||||
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"
|
||||
|
||||
exit 0
|
135
src/commands/upgrade.sh
Normal file
135
src/commands/upgrade.sh
Normal file
@ -0,0 +1,135 @@
|
||||
#!/bin/bash
|
||||
source /opt/kaido/src/libs/bash/lib.sh
|
||||
|
||||
|
||||
# init
|
||||
root=/opt/kaido
|
||||
configDir=$KAIDO_CONFIG_FOLDER
|
||||
workDir=$HOME/.cache/kaido/update
|
||||
|
||||
updateConfig="$configDir/update.conf"
|
||||
previousCommitFile_kaido="$workDir/previousCommit_kaido.txt"
|
||||
previousCommitFIle_config="$workDir/previousCOmmit_config.txt"
|
||||
|
||||
|
||||
skipContainerUpdate=0
|
||||
updateSuccess=0
|
||||
# ------------
|
||||
|
||||
|
||||
# check file and folders
|
||||
ensure_folder "${configDir}"
|
||||
ensure_folder "${workDir}"
|
||||
|
||||
if [ ! -f "${updateConfig}" ]; then
|
||||
echo "WARNING: container updates will be skipped"
|
||||
skipContainerUpdate=1
|
||||
fi
|
||||
|
||||
|
||||
# get commit hashes
|
||||
cd "$root"
|
||||
|
||||
currentCommit_kaido=$(git rev-parse --verify HEAD)
|
||||
previousCommit_kaido="origin/master"
|
||||
if [ -f "${previousCommitFile_kaido}" ]; then
|
||||
previousCommit_kaido=$(head -n 1 "${previousCommitFile_kaido}")
|
||||
fi
|
||||
|
||||
|
||||
cd "$configDir"
|
||||
|
||||
git reset --hard
|
||||
git pull
|
||||
|
||||
currentCommit_config=$(git rev-parse --verify HEAD)
|
||||
previusCommit_config=origin/master
|
||||
|
||||
if [ -f "${previousCommitFIle_config}" ]; then
|
||||
previusCommit_config=$(head -n 1 ${previousCommitFIle_config})
|
||||
fi
|
||||
# ------------
|
||||
|
||||
|
||||
# read config files
|
||||
installList=$(cat ${updateConfig} | grep -i install-)
|
||||
configureList=$(cat ${updateConfig} | grep -i configure-)
|
||||
buildList=$(cat ${updateConfig} | grep -i build-)
|
||||
# -----------------------
|
||||
|
||||
|
||||
# Actual update
|
||||
if [[ $skipContainerUpdate -eq 1 ]]; then
|
||||
exit 0
|
||||
fi
|
||||
|
||||
echo -e "Starting installation and configs auto update\n"
|
||||
|
||||
echo "Kaido: "
|
||||
echo "previous commit: ${previousCommit_kaido}"
|
||||
echo "current commit: ${currentCommit_kaido}"
|
||||
echo "Config:"
|
||||
echo "previous commit: ${previousCommit_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
|
||||
# ---------------------------
|
||||
|
||||
|
||||
# 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 $previousCommit_kaido $currentCommit_kaido src/commands/install | grep -qi $name) || \
|
||||
( [ -f "$configDir/containers/$name/envs.sh" ] && $(git -C "$configDir" diff --name-only $previousCommit_config $currentCommit_config "$configDir/containers/$name/envs.sh" | grep -qi "envs\.sh" ) ) ;
|
||||
then
|
||||
echo -e "Updating ${name} installation\n"
|
||||
kaido install $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 "$configDIr" diff --name-only $previousCommit_config $currentCommit_config "$configDIr/containers/$name/config" | grep -qi $name) ; then
|
||||
echo -e "Updating ${name} configuration\n"
|
||||
kaido config $name
|
||||
fi
|
||||
done
|
||||
echo -e "Configurations Updated\n"
|
||||
# ---------------------------
|
||||
|
||||
#TODO do an actual check
|
||||
updateSuccess=1
|
||||
|
||||
|
||||
# end
|
||||
if [[ $updateSuccess -eq 1 ]]; then
|
||||
echo $previousCommit_kaido | tee "${previousCommitFile_kaido}"
|
||||
echo $previousCOmmit_config | tee "${previousCommitFIle_config}"
|
||||
fi
|
||||
|
||||
|
||||
echo "Upgrade complete"
|
||||
|
||||
exit 0
|
Loading…
x
Reference in New Issue
Block a user