All of lore.kernel.org
 help / color / mirror / Atom feed
From: Bhaskar Chowdhury <unixbhaskar@gmail.com>
To: rdunlap@infradead.org, bfields@fieldses.org
Cc: yamada.masahiro@socionext.com, michal.lkml@markovi.net,
	linux-kbuild@vger.kernel.org, linux-kernel@vger.kernel.org,
	Bhaskar Chowdhury <unixbhaskar@gmail.com>
Subject: [PATCH] scripts:prune-kernel:prune kernel and modules dir from the system
Date: Tue, 29 Oct 2019 08:30:30 +0530	[thread overview]
Message-ID: <20191029030030.31659-1-unixbhaskar@gmail.com> (raw)

This patch will remove old kernel and modules directory from 
the system interactive way and also at once ,provied the parameter
given to the invoking script.

Signed-off-by: Bhaskar Chowdhury <unixbhaskar@gmail.com>
---
 scripts/prune-kernel | 58 ++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 58 insertions(+)

diff --git a/scripts/prune-kernel b/scripts/prune-kernel
index 58a7650ce592..a6c990450ddc 100755
--- a/scripts/prune-kernel
+++ b/scripts/prune-kernel
@@ -1,2 +1,60 @@
 #!/bin/bash
 # SPDX-License-Identifier: GPL-2.0
+#This script will delete old kernels and modules directory related to it,both
+#automated and interactive way, if you choose -i or --interactive as parameter.
+#For normal operation you have to invoke this script like below
+#prune-kernel -r kernel_ver modules_dir_name
+flag=$1
+kernel_ver=$2
+modules_dir_name=$3
+boot_dir=/boot
+modules_dir=/lib/modules
+
+remove_old_kernel() {
+	cd $boot_dir
+	rm -If vmlinuz-$kernel_version System.map-$kernel_version config-$kernel_version
+	return 0
+}
+
+remove_old_modules_dir() {
+	cd $modules_dir
+	rm -rf $modules_version
+	return 0
+}
+
+usage() {
+	printf "Usage: $(basename $0) [-ri] \n"
+	printf "\n -r | --remove kernel_ver modules_dir_name \n"
+	printf "\n -i | --interactive use as interactive way \n"
+}
+
+while getopts :hir opt;do
+	case "$flag" in
+		-i | --interactive)
+			printf "\nEnter kernel version to remove or blank/empty to exit:%s"
+			read kernel_version
+			if [[ $kernel_version != "" ]]; then
+				remove_old_kernel
+				printf "Please give the full modules directory name to remove:%s"
+				read modules_version
+				remove_old_modules_dir
+				printf "\n\n\n Removed kernel version:$kernel_version and associated modules directory:$modules_version ..Done.\n"
+			else
+				exit 1
+			fi
+			;;
+		-h | --help)
+			usage
+			exit 1
+			;;
+		-r | --remove)
+			shift $(( OPTIND -1 ))
+			cd $boot_dir
+			rm -f $kernel_ver
+			cd $modules_dir
+			rm -rf $modules_dir_name
+			printf "Removed kernel version:$kernel_ver and modules directory:$modules_dir_name from the system. \n\n"
+			exit 0
+			;;
+	esac
+done
--
2.23.0

             reply	other threads:[~2019-10-29  3:01 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-10-29  3:00 Bhaskar Chowdhury [this message]
2019-10-30  0:05 ` [PATCH] scripts:prune-kernel:prune kernel and modules dir from the system Randy Dunlap
2019-10-30  2:43   ` Bhaskar Chowdhury
2019-10-30  3:58     ` Randy Dunlap

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20191029030030.31659-1-unixbhaskar@gmail.com \
    --to=unixbhaskar@gmail.com \
    --cc=bfields@fieldses.org \
    --cc=linux-kbuild@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=michal.lkml@markovi.net \
    --cc=rdunlap@infradead.org \
    --cc=yamada.masahiro@socionext.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.