Re: [PATCH] scripts: prune-kernel:remove old kernels and modules dir from system

From: Randy Dunlap
Date: Fri Nov 01 2019 - 01:45:20 EST


On 10/31/19 10:11 PM, Bhaskar Chowdhury wrote:
> On 09:53 Fri 01 Nov 2019, Bhaskar Chowdhury wrote:
>> On 08:06 Thu 31 Oct 2019, Randy Dunlap wrote:
>>> On 10/31/19 12:18 AM, Bhaskar Chowdhury wrote:
>>>> On 22:27 Wed 30 Oct 2019, Randy Dunlap wrote:
>>>>> On 10/30/19 9:52 PM, Bhaskar Chowdhury wrote:
>>>>>>>>> ThatÂ'rm'Âdoesn'tÂremoveÂanyÂfiles.ÂÂCompareÂwhatÂremove_old_kernel()Âdoes.
>>>>>>>> No,itÂisÂnotÂusingÂthatÂfunctionÂratherÂtakeÂtheÂparameterÂfromÂthe
>>>>>>>> commandlineÂandÂgetÂintoÂbootÂdirÂmatchÂwithÂitÂandÂremoveÂit.
>>>>>>>
>>>>>>> ButÂitÂdoesn'tÂdoÂthat.ÂÂIÂtestedÂit.ÂÂItÂshouldÂbeÂmoreÂlikeÂwhat
>>>>>>> rmeove_old_kernel()Âdoes:
>>>>>>>
>>>>>>> ÂÂÂÂÂÂÂÂrmÂ-IfÂvmlinuz-$kernel_verÂSystem.map-$kernel_verÂconfig-$kernel_ver
>>>>>>>
>>>>>>> andÂifÂnot,ÂpleaseÂexplainÂwhyÂnot.
>>>>>> Okay,ÂagainÂsomeÂuniformityÂmissingÂinÂtheÂcode,ÂIÂwouldÂlikeÂtoÂyour
>>>>>> suggested method,i.e call remove_old_kernel to do the job instead of dependingÂonÂindividualÂkernel.
>>>>>
>>>>> The simplest thing to do is set kernel_version=$kernel_ver
>>>>> and then call remove_old_kernel().
>>>>> And set modules_version=$modules_dir_name and call remove_old_modules_dir().
>>>>>
>>>>> But it would be cleaner to pass a parameter (kernel_version) to the
>>>>> remove_old_kernel() function and to pass a parameter (modules_dir) to the
>>>>> remove_old_modules_dir() function.
>>>>
>>>>>
>>>>
>>>> Thank you...I have just modified the code and call both the function
>>>> under remove option. BTW I didn't set the extra variable $kernel_ver name it $kernel_version and instead of $modules_dir_name name it $mo
>>>> dules_version.
>>>>
>>>> Capturing command line parameter in $kernel_version and $modules_version
>>>>
>>>> Is that fine? Here is a code snippet:
>>>
>>> Yes, that should be OK.
>>>
>>>> -r | --remove)
>>>> Â if [[ $# -ne 3 ]]; then
>>>> ÂÂ printf "You need to provide kernel version and modules directory
>>>> ÂÂ name \n"
>>>> ÂÂ exit 1
>>>> ÂÂ else
>>>> ÂÂ remove_old_kernel
>>>> ÂÂ remove_old_modules_dir
>>>> ÂÂ fi
>>>>
>>>>
>>>> I have just test it and it works.
>>>>
>>>>
>>>> And about solitary r option without hypen is ignoring and doing nothing.
>>>>
>>>> Means, if I pass ./scripts/prune-kernel r 5.3.3
>>>> it simply ignore and does nothing.Only with the hypen it can work.
>>>
>>> Is that how it should be?
>>> or what would you expect that to do?
>> Yes it should be. Any malformed parameter should be discarded,except
>> what explicitly given in code form,as help reminder.
>> OR
>> Do you want me to reminds user that they are missing thing to operate
>> correctly??
>>>
>>> --Â
>>> ~Randy
>> Bhaskar
>>>
> Randy,
>
> I think we should show the help message , whenever user put a malformed
> parameter, say they put something like this :
>
> ./scripts/prune-kernel f 5.3.3
>
> It should show the help message to indicate what exactly need to pass
> with the script to get the desired result.
>
> What do you think??

I agree. Entering garbage junk should spit out help.

--
~Randy