Add help/force/dry-run options to remove-old-kernels
This commit is contained in:
parent
1400bce48c
commit
7369515c91
@ -17,6 +17,42 @@
|
|||||||
# along with this program; if not, write to the Free Software
|
# along with this program; if not, write to the Free Software
|
||||||
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
|
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
|
|
||||||
|
. shell-error
|
||||||
|
. shell-args
|
||||||
|
|
||||||
|
show_help()
|
||||||
|
{
|
||||||
|
cat <<EOF
|
||||||
|
Usage: $PROG [options]
|
||||||
|
Valid options are:
|
||||||
|
-f, --force non-interactive kernel removal (default is interactive)
|
||||||
|
-n, --dry-run just simulate removal
|
||||||
|
-h, --help show this text and exit
|
||||||
|
EOF
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
|
#parse command line options
|
||||||
|
TEMP=`getopt -n $PROG -o f,n,h -l force,dry-run,help -- "$@"` || show_help
|
||||||
|
eval set -- "$TEMP"
|
||||||
|
|
||||||
|
while :; do
|
||||||
|
case "$1" in
|
||||||
|
--) shift; break
|
||||||
|
;;
|
||||||
|
-f|--force) force="-y"
|
||||||
|
;;
|
||||||
|
-n|--dry-run) dryrun="--no-remove"
|
||||||
|
;;
|
||||||
|
-h|--help) show_help
|
||||||
|
esac
|
||||||
|
shift
|
||||||
|
done
|
||||||
|
|
||||||
|
if [ -n "$force" -a -n "$dryrun" ]; then
|
||||||
|
show_usage '--force and --dry-run are mutually exclusive options.'
|
||||||
|
fi
|
||||||
|
|
||||||
flavour_version_release="$(uname -r | awk -F- '{print $2"-"$3"-"$1"-"$4}')"
|
flavour_version_release="$(uname -r | awk -F- '{print $2"-"$3"-"$1"-"$4}')"
|
||||||
old_kernels="$(rpm -qa | fgrep kernel-image | fgrep -v $flavour_version_release | tr '\n' ' ')"
|
old_kernels="$(rpm -qa | fgrep kernel-image | fgrep -v $flavour_version_release | tr '\n' ' ')"
|
||||||
|
|
||||||
@ -30,4 +66,9 @@ done
|
|||||||
# use sudo(1) if running as unprivileged user
|
# use sudo(1) if running as unprivileged user
|
||||||
[ "$UID" = "0" ] && SUDO= || SUDO=sudo
|
[ "$UID" = "0" ] && SUDO= || SUDO=sudo
|
||||||
|
|
||||||
$SUDO apt-get remove $apt_args_list
|
$SUDO apt-get $force $dryrun remove $apt_args_list
|
||||||
|
|
||||||
|
# Mask non-zero apt exit code on dry run:
|
||||||
|
if [ -n "$dryrun" ]; then
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
Loading…
Reference in New Issue
Block a user