-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(updatecli) add a condition to check the package existence for G…
…IT (linux) (#1060) * add a condition to check the package * wip * rename * return code for condition match * return code for condition match * echo debug * sourceID * sourceID sourceis * use a variable * add ppa:git-code to match provisionning * add software-properties-common * remove test for add-apt-repository as we install it * add gpg * add gpg-agent
- Loading branch information
Showing
3 changed files
with
60 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
#!/bin/bash | ||
# This script uses apt to find the latest version of git available and check if it match parameter | ||
set -eux -o pipefail | ||
|
||
for cli in apt-get apt-cache grep cut xargs | ||
do | ||
if ! command -v $cli >/dev/null 2>&1 | ||
then | ||
echo "ERROR: command line ${cli} required but not found. Exiting." | ||
exit 1 | ||
fi | ||
done | ||
|
||
{ | ||
# Updating the list of latest updates available for installed packages on the system | ||
apt-get update -q | ||
apt-get install --yes --no-install-recommends \ | ||
software-properties-common \ | ||
gpg-agent | ||
add-apt-repository -y ppa:git-core/ppa | ||
apt-get update -q | ||
} 1>&2 # Only write logs to stderr to avoid polluting updatecli's source (retrieved from the stdout) | ||
|
||
# Retrieve from apt-cache the latest version of git available | ||
# Note: apt-cache policy will return a result like: | ||
# :# apt-cache policy git | ||
# git: | ||
# Installed: 1:2.43.0-0ppa1~ubuntu22.04.1 | ||
# Candidate: 1:2.43.2-0ppa1~ubuntu22.04.1 | ||
# Version table: | ||
# 1:2.43.2-0ppa1~ubuntu22.04.1 500 | ||
# We want to get the Candidate version (which is the latest available) | ||
# And we want it in a readable format | ||
last=$(apt-cache policy git `# 1. Retrieve information about git from apt` \ | ||
| grep 'Candidate' `# 2. Keep only the line about the Candidate version (latest available)` \ | ||
| cut -f2,3 -d':' `# 3. Cut it so we only keep the version and remove title (version contains a :, hence keeping fields 2 and 3)` \ | ||
| xargs `# 4. Trimming the result (removing spaces before and after)` \ | ||
| cut -d'-' -f1 | cut -d':' -f2 `# 5. Remove the ubuntu package prefix and suffix and last line fails if empty` \ | ||
| { read -r x ; if [ "$x" == '(none)' ]; then exit 1; else echo "${x}"; fi }) | ||
# comparing parameter with last version available | ||
if [[ "${last}" == "${1}" ]] | ||
then | ||
echo " ${last} match the selected version in parameter ${1}" | ||
exit 0 # ok | ||
else | ||
echo " ${last} DOES NOT match the selected version in parameter ${1}" | ||
exit 1 # ko | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters