finished profile_uprade implementation
This commit is contained in:
@@ -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
|
||||||
if [[ -s $MYPATH/profile.sh ]]; then
|
local need_update=$?
|
||||||
disp E "Installation path detection failed, cannot upgrade automatically."
|
[[ $need_update -ne 1 ]] && {
|
||||||
return 1
|
disp "No update available."
|
||||||
fi
|
return 0
|
||||||
if [[ -d $MYPATH/.git ]]; then
|
}
|
||||||
disp I "Git installation detected, applying git pull."
|
|
||||||
local curdir=$(pwd)
|
if [[ -s $MYPATH/profile.sh ]]; then
|
||||||
cd $MYPATH
|
disp E "Installation path detection failed, cannot upgrade automatically."
|
||||||
git pull
|
return 1
|
||||||
if [[ $? -ne 0 ]]; then
|
fi
|
||||||
disp E "Git pull failed, upgrade not applyed."
|
|
||||||
else
|
if [[ -d $MYPATH/.git ]]; then
|
||||||
disp I "Successfully upgraded using git."
|
disp I "Git installation detected, applying git pull."
|
||||||
disp I "You should now logout and login again to enjoy new profile."
|
local curdir=$(pwd)
|
||||||
cd $curdir
|
cd $MYPATH
|
||||||
fi
|
git pull || {
|
||||||
else
|
disp E "Git pull failed, upgrade not applyed."
|
||||||
disp I "Applying traditionnal upgrade..."
|
cd "$curdir"
|
||||||
# TODO
|
return 2
|
||||||
fi
|
}
|
||||||
|
disp I "Successfully upgraded using git."
|
||||||
|
cd "$curdir"
|
||||||
|
else
|
||||||
|
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
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
# EOF
|
# EOF
|
||||||
|
|||||||
Reference in New Issue
Block a user