finished profile_uprade implementation

This commit is contained in:
Geoffray Levasseur-Brandin
2025-06-19 14:40:02 +02:00
parent ff4c6702b7
commit e9e9993dfc

View File

@@ -34,7 +34,9 @@
# * OF SUCH DAMAGE. # * OF SUCH DAMAGE.
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
export UPDT_URL="https://git.geoffray-levasseur.org/fatalerrors/profile/raw/branch/master" export BASE_URL="https://git.geoffray-levasseur.org/fatalerrors/profile"
export UPDT_URL="$BASE_URL/raw/branch/master"
export ARCH_URL="$BASE_URL/archive/master.tar.gz"
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
# Check for profile updates # Check for profile updates
@@ -52,15 +54,15 @@ check_updates()
return 5 return 5
} }
if [[ -s /tmp/version ]]; then if [[ -s $vfile ]]; then
local lastver=$(cat /tmp/version) local lastver=$(cat $vfile)
if [[ $lastver != $PROFVERSION ]]; then if [[ $lastver != $PROFVERSION ]]; then
disp I "You have version $PROFVERSION installed. Version $lastver is available." disp I "You have version $PROFVERSION installed. Version $lastver is available."
[[ $quiet ]] && disp I "You should upgrade to last version when possible." [[ $quiet ]] && disp I "You should upgrade to last version when possible."
result=0 result=1
else else
disp I "Your version is up-to-date." disp I "Your version is up-to-date."
result=1 result=0
fi fi
rm -f $vfile rm -f $vfile
else else
@@ -75,28 +77,59 @@ check_updates()
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
profile_upgrade() profile_upgrade()
{ {
if [[ $(check_updates -q) -eq 0 ]]; then check_updates -q
local need_update=$?
[[ $need_update -ne 1 ]] && {
disp "No update available."
return 0
}
if [[ -s $MYPATH/profile.sh ]]; then if [[ -s $MYPATH/profile.sh ]]; then
disp E "Installation path detection failed, cannot upgrade automatically." disp E "Installation path detection failed, cannot upgrade automatically."
return 1 return 1
fi fi
if [[ -d $MYPATH/.git ]]; then if [[ -d $MYPATH/.git ]]; then
disp I "Git installation detected, applying git pull." disp I "Git installation detected, applying git pull."
local curdir=$(pwd) local curdir=$(pwd)
cd $MYPATH cd $MYPATH
git pull git pull || {
if [[ $? -ne 0 ]]; then
disp E "Git pull failed, upgrade not applyed." disp E "Git pull failed, upgrade not applyed."
else cd "$curdir"
return 2
}
disp I "Successfully upgraded using git." disp I "Successfully upgraded using git."
disp I "You should now logout and login again to enjoy new profile." cd "$curdir"
cd $curdir
fi
else else
disp I "Applying traditionnal upgrade..." disp I "No Git detected. Downloading and applying upgrade from archive..."
# TODO local tmpdir="/tmp/profile_upg.$$"
fi mkdir -p "$tmpdir" || {
fi disp E "Failed to create temporary directory."
return 4
} }
local archive="$tmpdir/profile.tar.gz"
wget -q "$ARCH_URL" -O "$archive" || {
disp E "Failed to download archive."
rm -rf "$tmpdir"
return 5
}
tar -xzf "$archive" -C "$tmpdir" || {
disp E "Archive extraction failed."
rm -rf "$tmpdir"
return 6
}
disp I "Installing new version..."
cp -r "$tmpdir"/profile/* "$MYPATH"/ || {
disp E "Failed to copy new files to $MYPATH."
rm -rf "$tmpdir"
return 7
}
disp I "Upgrade complete. You should now logout and login again."
rm -rf "$tmpdir"
fi
}
# EOF # EOF