mirror of
https://github.com/YunoHost/package_check.git
synced 2024-09-03 20:06:20 +02:00
Fix self-upgrade madness
This commit is contained in:
parent
6cc335eafe
commit
17f4e3f546
1 changed files with 16 additions and 58 deletions
|
@ -41,7 +41,7 @@ assert_we_are_connected_to_the_internets() {
|
||||||
}
|
}
|
||||||
|
|
||||||
assert_we_have_all_dependencies() {
|
assert_we_have_all_dependencies() {
|
||||||
for dep in "lxc" "lxd" "lynx" "jq" "python3"
|
for dep in "lxc" "lxd" "lynx" "jq" "python3" "pip3"
|
||||||
do
|
do
|
||||||
which $dep 2>&1 > /dev/null || log_critical "Please install $dep"
|
which $dep 2>&1 > /dev/null || log_critical "Please install $dep"
|
||||||
done
|
done
|
||||||
|
@ -189,47 +189,24 @@ stop_timer () {
|
||||||
}
|
}
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# Upgrade Package check
|
# Package check self-upgrade
|
||||||
#=================================================
|
#=================================================
|
||||||
|
|
||||||
|
|
||||||
function self_upgrade()
|
function self_upgrade()
|
||||||
{
|
{
|
||||||
local git_repository=https://github.com/YunoHost/package_check
|
# We only self-upgrade if we're in a git repo on master branch
|
||||||
local version_file="./.pcheck_version"
|
# (which should correspond to production contexts)
|
||||||
|
[[ -d ".git" ]] || return
|
||||||
|
[[ $(git rev-parse --abbrev-ref HEAD) == "master" ]] || return
|
||||||
|
|
||||||
local check_version="$(git ls-remote $git_repository | cut -f 1 | head -n1)"
|
git fetch origin --quiet
|
||||||
|
|
||||||
# Check if the last commit on the repository match with the current version
|
# If already up to date, don't do anything else
|
||||||
if [ ! -e "$version_file" ] || [ "$check_version" != "$(cat "$version_file")" ]
|
[[ $(git rev-parse HEAD) == $(git rev-parse origin/master) ]] && return
|
||||||
then
|
|
||||||
# If the versions don't matches. Do an upgrade
|
|
||||||
log_info "Upgrading Package check"
|
|
||||||
|
|
||||||
# Build the upgrade script
|
log_info "Upgrading package_check..."
|
||||||
cat > "./upgrade_script.sh" << EOF
|
git reset --hard origin/master --quiet
|
||||||
|
|
||||||
#!/bin/bash
|
|
||||||
# Clone in another directory
|
|
||||||
git clone --quiet $git_repository "./upgrade"
|
|
||||||
cp -a "./upgrade/." "./."
|
|
||||||
rm -rf "./upgrade"
|
|
||||||
# Update the version file
|
|
||||||
echo "$check_version" > "$version_file"
|
|
||||||
rm "./pcheck.lock"
|
|
||||||
# Execute package check by replacement of this process
|
|
||||||
exec "./package_check.sh" "${arguments[@]}"
|
exec "./package_check.sh" "${arguments[@]}"
|
||||||
EOF
|
|
||||||
|
|
||||||
# Give the execution right
|
|
||||||
chmod +x "./upgrade_script.sh"
|
|
||||||
|
|
||||||
# Start the upgrade script by replacement of this process
|
|
||||||
exec "./upgrade_script.sh"
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Update the version file
|
|
||||||
echo "$check_version" > "$version_file"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
|
@ -239,35 +216,16 @@ EOF
|
||||||
function fetch_or_upgrade_package_linter()
|
function fetch_or_upgrade_package_linter()
|
||||||
{
|
{
|
||||||
local git_repository=https://github.com/YunoHost/package_linter
|
local git_repository=https://github.com/YunoHost/package_linter
|
||||||
local version_file="./.plinter_version"
|
|
||||||
|
|
||||||
local check_version="$(git ls-remote $git_repository | cut -f 1 | head -n1)"
|
if [[ ! -d "./package_linter" ]]
|
||||||
|
|
||||||
# If the version file exist, check for an upgrade
|
|
||||||
if [ -e "$version_file" ]
|
|
||||||
then
|
then
|
||||||
# Check if the last commit on the repository match with the current version
|
|
||||||
if [ "$check_version" != "$(cat "$version_file")" ]
|
|
||||||
then
|
|
||||||
# If the versions don't matches. Do an upgrade
|
|
||||||
log_info "Upgrading Package linter"
|
|
||||||
|
|
||||||
# Clone in another directory
|
|
||||||
git clone --quiet $git_repository "./package_linter_tmp"
|
|
||||||
pip3 install pyparsing six
|
|
||||||
|
|
||||||
# And replace
|
|
||||||
cp -a "./package_linter_tmp/." "./package_linter/."
|
|
||||||
rm -r "./package_linter_tmp"
|
|
||||||
fi
|
|
||||||
else
|
|
||||||
log_info "Installing Package linter"
|
log_info "Installing Package linter"
|
||||||
git clone --quiet $git_repository "./package_linter"
|
git clone --quiet $git_repository "./package_linter"
|
||||||
pip3 install pyparsing six
|
pip3 install pyparsing six
|
||||||
|
else
|
||||||
|
git -C "./package_linter" fetch origin --quiet
|
||||||
|
git -C "./package_linter" reset --hard origin/master --quiet
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Update the version file
|
|
||||||
echo "$check_version" > "$version_file"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
|
|
Loading…
Add table
Reference in a new issue