Fix multiple shellcheck warnings
Signed-off-by: Vitaly Chikunov <vt@altlinux.org>
This commit is contained in:
parent
725f623e1c
commit
930c38e5e5
@ -1,4 +1,4 @@
|
||||
#!/bin/sh
|
||||
#!/bin/bash
|
||||
# Copyright (C) 2008 Vladimir V. Kamarzin <vvk@altlinux.org>
|
||||
#
|
||||
# Remove all kernels except current
|
||||
@ -17,6 +17,7 @@
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
# shellcheck source-path=/bin
|
||||
. shell-error
|
||||
. shell-args
|
||||
|
||||
@ -35,7 +36,7 @@ exit 1
|
||||
}
|
||||
|
||||
#parse command line options
|
||||
TEMP=`getopt -n $PROG -o f,y,n,t:,h,a -l force,dry-run,type:,help,all -- "$@"` || show_help
|
||||
TEMP=$(getopt -n "$PROG" -o f,y,n,t:,h,a -l force,dry-run,type:,help,all -- "$@") || show_help
|
||||
eval set -- "$TEMP"
|
||||
|
||||
while :; do
|
||||
@ -55,20 +56,20 @@ while :; do
|
||||
shift
|
||||
done
|
||||
|
||||
if [ -n "$force" -a -n "$dryrun" ]; then
|
||||
if [ -n "$force" ] && [ -n "$dryrun" ]; then
|
||||
show_usage '--force and --dry-run are mutually exclusive options.'
|
||||
fi
|
||||
|
||||
if [ -n "$kernel_flavour" -a -n "$all" ]; then
|
||||
if [ -n "$kernel_flavour" ] && [ -n "$all" ]; then
|
||||
show_usage '--type and --all are mutually exclusive options.'
|
||||
fi
|
||||
|
||||
###### copied from update-kernel
|
||||
# get running kernel version
|
||||
current_kernel_package=$(rpmquery -qf /lib/modules/$(uname -r)/kernel 2>/dev/null)
|
||||
current_kernel_package=$(rpmquery -qf "/lib/modules/$(uname -r)/kernel" 2>/dev/null)
|
||||
if [ -n "$current_kernel_package" ] ; then
|
||||
current_kernel_pkgname=$(rpmquery --queryformat "%{NAME}-%{SERIAL}:%{VERSION}-%{RELEASE}\n" -q $current_kernel_package)
|
||||
echo $current_kernel_pkgname | grep -q "(none)" && current_kernel_pkgname=$(rpmquery --queryformat "%{NAME}-%{VERSION}-%{RELEASE}\n" -q $current_kernel_package)
|
||||
current_kernel_pkgname=$(rpmquery --queryformat "%{NAME}-%{SERIAL}:%{VERSION}-%{RELEASE}\n" -q "$current_kernel_package")
|
||||
echo "$current_kernel_pkgname" | grep -q "(none)" && current_kernel_pkgname=$(rpmquery --queryformat "%{NAME}-%{VERSION}-%{RELEASE}\n" -q "$current_kernel_package")
|
||||
else
|
||||
current_kernel_pkgname="UNKNOWN"
|
||||
fi
|
||||
@ -80,7 +81,7 @@ current_kernel_flavour="$(uname -r)"
|
||||
current_kernel_flavour="${current_kernel_flavour#*-}"
|
||||
current_kernel_flavour="${current_kernel_flavour%-*}"
|
||||
if [ -n "$all" ] ; then
|
||||
flavours="$(rpm -qa --queryformat '%{NAME}\n' | fgrep kernel-image- | fgrep -v domU | sort -u | cut -d "-" -f3- | tr '\n' ' ')"
|
||||
flavours="$(rpm -qa --queryformat '%{NAME}\n' | grep -F kernel-image- | grep -F -v domU | sort -u | cut -d "-" -f3- | tr '\n' ' ')"
|
||||
else
|
||||
flavours="${kernel_flavour:-$current_kernel_flavour}"
|
||||
fi
|
||||
@ -91,7 +92,7 @@ flavour_version_release="$(uname -r | awk -F- '{print $2"-"$3"-"$1"-"$4}')"
|
||||
echo "For removing:"
|
||||
for kernel_flavour in $flavours
|
||||
do
|
||||
old_kernels="$(rpm -qa | fgrep kernel-image-$kernel_flavour | fgrep -v $flavour_version_release | sort | tr '\n' ' ')"
|
||||
old_kernels="$(rpm -qa | grep -F "kernel-image-$kernel_flavour" | grep -F -v "$flavour_version_release" | sort | tr '\n' ' ')"
|
||||
if [ -n "$all" ] ; then
|
||||
echo "$kernel_flavour:"
|
||||
fi
|
||||
@ -111,7 +112,7 @@ do
|
||||
[ "$latest" -eq 1 ] && continue
|
||||
fi
|
||||
echo " $kernel"
|
||||
apt_args_list="$apt_args_list $(rpm -q --queryformat '%{NAME}=%{EPOCH}:%{VERSION}-%{RELEASE}\n' $kernel \
|
||||
apt_args_list="$apt_args_list $(rpm -q --queryformat '%{NAME}=%{EPOCH}:%{VERSION}-%{RELEASE}\n' "$kernel" \
|
||||
| sed -e "s,(none):,,g")"
|
||||
done
|
||||
done
|
||||
@ -126,6 +127,7 @@ if [ "$UID" != "0" ]; then
|
||||
echo >&2 "This program requires root privileges."
|
||||
fi
|
||||
|
||||
# shellcheck disable=SC2086
|
||||
apt-get $force $dryrun remove $apt_args_list
|
||||
|
||||
# Mask non-zero apt exit code on dry run:
|
||||
|
@ -22,6 +22,7 @@
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
# shellcheck source-path=/bin
|
||||
. shell-error
|
||||
. shell-args
|
||||
|
||||
@ -54,13 +55,14 @@ module_install() {
|
||||
|
||||
if [ "$interactive" = 1 ]; then
|
||||
echo -n "Try to install or update module $module [y]/n? "
|
||||
read
|
||||
read -r
|
||||
case "$REPLY" in
|
||||
n|no|N|No|NO|0) return 0
|
||||
;;
|
||||
*)
|
||||
;;
|
||||
esac
|
||||
# shellcheck disable=SC2086
|
||||
apt-get install -o APT::Install::VirtualVersion=true -o APT::Install::Virtual=true -y $dryrun "$module"
|
||||
else
|
||||
export modules_to_install="$modules_to_install $1"
|
||||
@ -68,7 +70,7 @@ module_install() {
|
||||
}
|
||||
|
||||
#parse command line options
|
||||
TEMP=`getopt -n $PROG -o a,i,l,f,y,t:,r:,n,h -l interactive,list,all,force,type:,release:,dry-run,help -- "$@"` || show_help
|
||||
TEMP=$(getopt -n "$PROG" -o a,i,l,f,y,t:,r:,n,h -l interactive,list,all,force,type:,release:,dry-run,help -- "$@") || show_help
|
||||
eval set -- "$TEMP"
|
||||
|
||||
while :; do
|
||||
@ -94,7 +96,7 @@ while :; do
|
||||
shift
|
||||
done
|
||||
|
||||
if [ -n "$interactive" -a -n "$force" ]; then
|
||||
if [ -n "$interactive" ] && [ -n "$force" ]; then
|
||||
show_usage '--force and --interactive are mutually exclusive options.'
|
||||
fi
|
||||
|
||||
@ -114,7 +116,7 @@ if [ -n "$list" ]; then
|
||||
def=${def#vmlinuz-}
|
||||
echo "List of available kernels${kernel_flavour:+ for $kernel_flavour flavour}:"
|
||||
list_files=$(mktemp)
|
||||
rpm -qa --queryformat '[%{=NAME}\t%{FILENAMES}\n]' 'kernel-*' > $list_files
|
||||
rpm -qa --queryformat '[%{=NAME}\t%{FILENAMES}\n]' 'kernel-*' > "$list_files"
|
||||
list_extras=$(mktemp)
|
||||
set -o pipefail
|
||||
apt-cache list-extras 2>/dev/null | sort > "$list_extras" && extras=1 || extras=
|
||||
@ -124,43 +126,44 @@ if [ -n "$list" ]; then
|
||||
| grep '#' \
|
||||
| grep -v -e '-debuginfo#' -e '^kernel-image-domU-' \
|
||||
| (
|
||||
while read k j; do
|
||||
while read -r k j; do
|
||||
pkg=${k%#*}
|
||||
flv=${pkg#kernel-image-}
|
||||
ev=${k#*#}
|
||||
ver=${ev#+([0-9]):}
|
||||
epo=${ev%$ver}
|
||||
epo=${ev%"$ver"}
|
||||
ver=${ver%%[:@]*}
|
||||
rel=${ver#*-}
|
||||
ver=${ver%-*}
|
||||
ev=$epo$ver
|
||||
|
||||
[ -z "$extras" -o -n "$j" ] && echo -n " " || echo -n " *"
|
||||
[ -z "$extras" ] || [ -n "$j" ] && echo -n " " || echo -n " *"
|
||||
echo -n " $pkg-$ver-$rel"
|
||||
if rpm -q $pkg-$ver-$rel >/dev/null 2>&1; then
|
||||
if rpm -q "$pkg-$ver-$rel" >/dev/null 2>&1; then
|
||||
if [ "$def" = "$ver-$flv-$rel" ]; then
|
||||
echo -n ' [default]'
|
||||
else
|
||||
echo -n ' [installed]'
|
||||
fi
|
||||
elif [ -n "$extras" -a -z "$j" ] && [ "$rflv" = "$flv" ]; then
|
||||
elif [ -n "$extras" ] && [ -z "$j" ] && [ "$rflv" = "$flv" ]; then
|
||||
echo -n " <--- upgrade"
|
||||
fi
|
||||
[ "$rrel" = "$ver-$flv-$rel" ] && echo -n ' RUNNING'
|
||||
|
||||
# shellcheck disable=SC2002
|
||||
addons=$(cat "$list_files" \
|
||||
| grep -e "/lib/modules/$ver-$flv-$rel/" \
|
||||
-e "[[:space:]]/usr/include/linux-$ver-$flv\$" \
|
||||
-e "[[:space:]]/boot/vmlinux-$ver-$flv-$rel\$" \
|
||||
| cut -f1 \
|
||||
| sort -u \
|
||||
| while read m; do
|
||||
| while read -r m; do
|
||||
# Skip kernel-image which is reported above.
|
||||
[ -n "${m#kernel-image-$flv}" ] || continue
|
||||
[ -n "${m#kernel-image-"$flv"}" ] || continue
|
||||
m=${m#kernel-image-}
|
||||
m=${m#$flv-}
|
||||
m=${m#"$flv"-}
|
||||
m=${m#kernel-modules-}
|
||||
m=${m%-$flv}
|
||||
m=${m%-"$flv"}
|
||||
m=${m#kernel-}
|
||||
echo -n " $m"
|
||||
done
|
||||
@ -180,10 +183,10 @@ if [ -n "$list" ]; then
|
||||
fi
|
||||
|
||||
# get running kernel version
|
||||
current_kernel_package=$(rpmquery -qf /lib/modules/$(uname -r)/kernel 2>/dev/null)
|
||||
current_kernel_package=$(rpmquery -qf "/lib/modules/$(uname -r)/kernel" 2>/dev/null)
|
||||
if [ -n "$current_kernel_package" ] ; then
|
||||
current_kernel_pkgname=$(rpmquery --queryformat "%{NAME}-%{SERIAL}:%{VERSION}-%{RELEASE}\n" -q $current_kernel_package)
|
||||
echo $current_kernel_pkgname | grep -q "(none)" && current_kernel_pkgname=$(rpmquery --queryformat "%{NAME}-%{VERSION}-%{RELEASE}\n" -q $current_kernel_package)
|
||||
current_kernel_pkgname=$(rpmquery --queryformat "%{NAME}-%{SERIAL}:%{VERSION}-%{RELEASE}\n" -q "$current_kernel_package")
|
||||
echo "$current_kernel_pkgname" | grep -q "(none)" && current_kernel_pkgname=$(rpmquery --queryformat "%{NAME}-%{VERSION}-%{RELEASE}\n" -q "$current_kernel_package")
|
||||
else
|
||||
current_kernel_pkgname="UNKNOWN"
|
||||
fi
|
||||
@ -200,18 +203,18 @@ if [[ "$release" =~ ^[0-9]+\.[0-9.]+-.*-[^-]+$ ]]; then
|
||||
fi
|
||||
kernel_flavour="$flv"
|
||||
release="$ver-$rel"
|
||||
ver= flv= rel=
|
||||
ver='' flv='' rel=''
|
||||
elif [[ "$release" =~ ^(kernel-image-)?.*[-=#][0-9:]+\.[0-9.]+-[^-]+$ ]]; then
|
||||
# Rewrite release in RPM, APT package format
|
||||
ver="${release#kernel-image-}"
|
||||
flv="${ver%[-=#]*-*}"
|
||||
rel="${ver#$flv[-=#]}"
|
||||
rel="${ver#"$flv"[-=#]}"
|
||||
if [ -n "$kernel_flavour" ] && [ "$kernel_flavour" != "$flv" ]; then
|
||||
fatal "Kernel flavour from '-t $kernel_flavour' does not match flavour from '-r' ($flv)."
|
||||
fi
|
||||
kernel_flavour="$flv"
|
||||
release="$rel"
|
||||
ver= flv= rel=
|
||||
ver='' flv='' rel=''
|
||||
fi
|
||||
|
||||
# set kernel flavour. if not defined with -t option, use current
|
||||
@ -239,9 +242,10 @@ num_available_kernels="$(echo "$KERNEL_PKGS" | grep -c "$kernel_flavour")"
|
||||
|
||||
# get the maximum available kernel package version
|
||||
kmaxver=
|
||||
while read version
|
||||
while read -r version
|
||||
do
|
||||
comparever="$(rpmevrcmp "$kmaxver" "$version")"
|
||||
# shellcheck disable=SC2015
|
||||
[ "$comparever" -lt 0 ] && kmaxver="$version" ||:
|
||||
done <<<"$(echo "$KERNEL_PKGS" | grep "$pgkgrep" | sed -e "s,^kernel-image-$kernel_flavour#,,g")"
|
||||
[ -z "$kmaxver" ] && fatal "Selected kernel not found."
|
||||
@ -262,15 +266,17 @@ fi
|
||||
|
||||
# ask user
|
||||
echo -n "Try to install new kernel kernel-image-$kernel_flavour-$kmaxver and update its modules [y]/n? "
|
||||
[ "$force" = 1 ] && echo "yes" || {
|
||||
read
|
||||
if [ "$force" = 1 ]; then
|
||||
echo "yes"
|
||||
else
|
||||
read -r
|
||||
case "$REPLY" in
|
||||
n|no|N|No|NO|0) exit 0
|
||||
;;
|
||||
*)
|
||||
;;
|
||||
esac
|
||||
}
|
||||
fi
|
||||
|
||||
# is there kernel-image-$kernel_flavour already installed or not?
|
||||
# needed for proper modules selection
|
||||
@ -283,6 +289,7 @@ fi
|
||||
|
||||
# install kernel iff we are working in interactive mode
|
||||
if [ -n "$interactive" ]; then
|
||||
# shellcheck disable=SC2086
|
||||
apt-get install -y $dryrun "kernel-image-$kernel_flavour#$kmaxver" \
|
||||
|| fatal "failed to install kernel-image-$kernel_flavour-$kmaxver"
|
||||
fi
|
||||
@ -294,14 +301,14 @@ fi
|
||||
message "Updating modules for kernel: $kernel_flavour-$kmaxver"
|
||||
|
||||
# get list of all available modules
|
||||
ALLMODULES="$(apt-cache whatdepends kernel-image-$kernel_flavour#$kmaxver | grep "kernel-modules-.*-$kernel_flavour" | sed -re 's/-[^-]*-[^-]*$//' | sort -u)"
|
||||
ALLMODULES="$(apt-cache whatdepends "kernel-image-$kernel_flavour#$kmaxver" | grep "kernel-modules-.*-$kernel_flavour" | sed -re 's/-[^-]*-[^-]*$//' | sort -u)"
|
||||
|
||||
# install modules or set modules_to_install variable
|
||||
modules_to_install=
|
||||
for module in $ALLMODULES; do
|
||||
module_pkgname="${module%%#*}"
|
||||
module_pkgname="${module_pkgname%-$kernel_flavour}"
|
||||
if rpm -q $module_pkgname-"$modules_kernel_flavour" &>/dev/null; then
|
||||
module_pkgname="${module_pkgname%-"$kernel_flavour"}"
|
||||
if rpm -q "$module_pkgname-$modules_kernel_flavour" &>/dev/null; then
|
||||
message "$module_pkgname is installed, trying to update..."
|
||||
elif [ "$all" = 1 ]; then
|
||||
message "$module_pkgname is not istalled, trying to install..."
|
||||
@ -318,6 +325,7 @@ done
|
||||
# now install both kernel and modules iff we are not interactive
|
||||
# (in wich case all of them already installed)
|
||||
if [ -z "$interactive" ]; then
|
||||
# shellcheck disable=SC2086
|
||||
apt-get install -y $dryrun "kernel-image-$kernel_flavour#$kmaxver" $modules_to_install \
|
||||
|| fatal "failed to install kernel-image-$kernel_flavour-$kmaxver with modules"
|
||||
fi
|
||||
@ -334,9 +342,11 @@ case "$ALLMODULES" in
|
||||
*drm*|*fglrx*|*nvidia*)
|
||||
[ -x "$X11SETUPDRV" ] \
|
||||
&& "$X11SETUPDRV"
|
||||
[ -x "$X11PRESETDRV" ] \
|
||||
&& "$X11PRESETDRV" \
|
||||
|| message "You might need to run x11presetdrv, video drivers updated but it's missing"
|
||||
if [ -x "$X11PRESETDRV" ]; then
|
||||
"$X11PRESETDRV"
|
||||
else
|
||||
message "You might need to run x11presetdrv: video drivers updated but $X11PRESETDRV is missing"
|
||||
fi
|
||||
ldconfig
|
||||
;;
|
||||
esac
|
||||
@ -346,8 +356,9 @@ esac
|
||||
# update headers
|
||||
|
||||
for package in kernel-headers kernel-headers-modules; do
|
||||
if rpm -q $package-"$kernel_flavour" &>/dev/null; then
|
||||
if rpm -q "$package-$kernel_flavour" &>/dev/null; then
|
||||
message "$package is installed, trying to update..."
|
||||
# shellcheck disable=SC2086
|
||||
apt-get install -y $dryrun "$package-$kernel_flavour"
|
||||
fi
|
||||
done
|
||||
|
Loading…
x
Reference in New Issue
Block a user