finished profile_uprade implementation
This commit is contained in:
@@ -34,7 +34,9 @@
|
||||
# * 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
|
||||
@@ -52,15 +54,15 @@ check_updates()
|
||||
return 5
|
||||
}
|
||||
|
||||
if [[ -s /tmp/version ]]; then
|
||||
local lastver=$(cat /tmp/version)
|
||||
if [[ -s $vfile ]]; then
|
||||
local lastver=$(cat $vfile)
|
||||
if [[ $lastver != $PROFVERSION ]]; then
|
||||
disp I "You have version $PROFVERSION installed. Version $lastver is available."
|
||||
[[ $quiet ]] && disp I "You should upgrade to last version when possible."
|
||||
result=0
|
||||
result=1
|
||||
else
|
||||
disp I "Your version is up-to-date."
|
||||
result=1
|
||||
result=0
|
||||
fi
|
||||
rm -f $vfile
|
||||
else
|
||||
@@ -75,28 +77,59 @@ check_updates()
|
||||
# ------------------------------------------------------------------------------
|
||||
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
|
||||
disp E "Installation path detection failed, cannot upgrade automatically."
|
||||
return 1
|
||||
fi
|
||||
|
||||
if [[ -d $MYPATH/.git ]]; then
|
||||
disp I "Git installation detected, applying git pull."
|
||||
local curdir=$(pwd)
|
||||
cd $MYPATH
|
||||
git pull
|
||||
if [[ $? -ne 0 ]]; then
|
||||
git pull || {
|
||||
disp E "Git pull failed, upgrade not applyed."
|
||||
else
|
||||
cd "$curdir"
|
||||
return 2
|
||||
}
|
||||
disp I "Successfully upgraded using git."
|
||||
disp I "You should now logout and login again to enjoy new profile."
|
||||
cd $curdir
|
||||
fi
|
||||
cd "$curdir"
|
||||
else
|
||||
disp I "Applying traditionnal upgrade..."
|
||||
# TODO
|
||||
fi
|
||||
disp I "No Git detected. Downloading and applying upgrade from archive..."
|
||||
local tmpdir="/tmp/profile_upg.$$"
|
||||
mkdir -p "$tmpdir" || {
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user