Commit d7a69884 authored by Chris's avatar Chris

Implement a --quiet flag in the update-gitlab tool

parent 3ae1eb01
......@@ -61,6 +61,7 @@ EOF
# Parse command options
flag_dry_run=0
flag_verbose=0
flag_quiet=0
flag_exit_code=0
while [[ $# -gt 0 ]]; do
case "$1" in
......@@ -70,6 +71,9 @@ while [[ $# -gt 0 ]]; do
"-v" | "--verbose")
flag_verbose=1
;;
"-q" | "--quiet")
flag_quiet=1
;;
"-c" | "--code")
flag_exit_code=1
;;
......@@ -86,15 +90,23 @@ done
# Make sure we're running as root
if [ $(id -u) -ne 0 ]; then
echo "This script must be run as root or with sudo"
exit 1
error_exit "This script must be run as root or with sudo"
fi
# Make sure we're not quiet and verbose at the same time
if [ ${flag_verbose} -eq 1 ] && [ ${flag_quiet} -eq 1 ]; then
error_exit "Using --verbose and --quiet options together is not supported"
fi
# Update Apt-Cache if older than 15 minutes
if [ "$[$(date +%s) - $(stat -c %Z /var/lib/apt/periodic/update-success-stamp)]" -ge 900 ]; then
echo "APT cache is stale; updating..."
if [ ${flag_quiet} -eq 0 ]; then
echo "APT cache is stale; updating..."
fi
apt-get -qq update
echo
if [ ${flag_quiet} -eq 0 ]; then
echo
fi
fi
latest=`apt-cache policy ${package} | sed -n 's/ Candidate: \([0-9]\+\.[0-9]\+\.[^ ]\+\).*/\1/p'`
......@@ -110,18 +122,24 @@ if [ ${flag_verbose} -eq 1 ]; then
fi
if [ "${installed}" == "${target}" ]; then
echo "Most recent patch version (${target}) of last minor version is already installed."
if [ ${flag_quiet} -eq 0 ]; then
echo "Most recent patch version (${target}) of last minor version is already installed."
fi
if [ ${flag_exit_code} -eq 1 ]; then
exit 64
fi
elif [ "${target}" != `echo -e "${installed}\n${target}" | sort -Vr | sed -n 1p` ]; then
echo "Installed version (${installed}) is newer than the target version (${target}.*). Not upgrading."
if [ ${flag_quiet} -eq 0 ]; then
echo "Installed version (${installed}) is newer than the target version (${target}.*). Not upgrading."
fi
if [ ${flag_exit_code} -eq 1 ]; then
exit 64
fi
else
if [ ${flag_dry_run} -eq 0 ]; then
echo "Upgrading from ${installed} to ${target}"
if [ ${flag_quiet} -eq 0 ]; then
echo "Upgrading from ${installed} to ${target}"
fi
apt-get install ${package}=${target}
else
echo "Would upgrade from ${installed} to ${target}"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment