Skip to content

Instantly share code, notes, and snippets.

@fumiyas
Created November 28, 2014 04:39
Show Gist options
  • Save fumiyas/92a0666b6aa339923d11 to your computer and use it in GitHub Desktop.
Save fumiyas/92a0666b6aa339923d11 to your computer and use it in GitHub Desktop.
Do `rpm -U *.rpm` except already updated packages
#!/bin/bash
##
## Do `rpm -U *.rpm` except already updated packages
## Copyright (c) 2013 SATOH Fumiyasu @ OSS Technology Corp., Japan
##
## License: DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE Version 2
##
set -u
rpm="${RPM_COMMAND-/usr/bin/rpm}"
rpm_args=()
for rpm_arg in "$@"; do
if [[ -z ${rpm_arg%%*.rpm} && -f $rpm_arg ]]; then
rpm_test=$(LC_ALL=C "$rpm" -U --test "$rpm_arg" 2>&1 >/dev/null)
if [[ -z ${rpm_test%%* is already installed} ]]; then
echo "$rpm_test (ignored)" 1>&2
continue
fi
fi
rpm_args+=("$rpm_arg")
done
if [[ ${#rpm_args[@]} -gt 0 ]]; then
exec "$rpm" -U "${rpm_args[@]}"
fi
exit 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment