# Remove old kernels
def removekernel():
-
def get_oldkernels():
- #return subprocess.run(['dpkg', '--list', '|', 'grep', '-E', '-o', '"linux-image-[0-9]+\\.[0-9]+\\.[0-9]+-[0-9]+-generic"', '|', 'grep', '-o', '-E', '"[0-9]+\\.[0-9]+\\.[0-9]+-[0-9]+"', '|', 'uniq', '|', 'grep', '-E', '-v', '${dpkg', '--list', '|', 'grep', '-E', '-o', '"linux-image-[0-9]+\\.[0-9]+\\.[0-9]+-[0-9]+-generic"', '|', 'grep', '-o', '-E', '"[0-9]+\\.[0-9]+\\.[0-9]+-[0-9]+"', '|', 'uniq', '|', 'sort', '-n', '-r', '|', 'head', '-1}'],stdout = subprocess.PIPE, stderr = subprocess.PIPE)
- return 4.15 # testing
+ olders = subprocess.run(["../scripts/removekernel.sh"],stdout = subprocess.PIPE, stderr = subprocess.PIPE)
+ return olders
def formating(*args):# args type = string ! Do not number
- olders = (i for i in args)
+ olders = (i for i in str(args))
terget = ("linux-headers-", "linux-image-")
removed = [version + tgt for tgt in olders for version in terget]
return removed
removed = args
return subprocess.run(["apt-get", "autoremove", "--purge", "-y", removed],stderr = subprocess.PIPE)
+ #Main
print("These kernels removed. {}".format(get_oldkernels()))
print("Are you remove them? Y/n")
anser = yesno(input())
else:
return "Error"
-print(yesno(input()))
-#removekernel()
\ No newline at end of file
+removekernel()
\ No newline at end of file
#!/bin/bash
-if [[ $UID != 0 ]]; then
- echo "You have to run this as root."
- exit 1
-fi
-get_oldkernels(){
- TARGETS=$(dpkg --list | grep -E -o "linux-image-[0-9]+\.[0-9]+\.[0-9]+-[0-9]+-generic" | grep -o -E "[0-9]+\.[0-9]+\.[0-9]+-[0-9]+" | uniq | grep -E -v ${dpkg --list | grep -E -o "linux-image-[0-9]+\.[0-9]+\.[0-9]+-[0-9]+-generic" | grep -o -E "[0-9]+\.[0-9]+\.[0-9]+-[0-9]+" | uniq | sort -n -r | head -1})
- echo $TARGETS
-}
-
-remove_oldkernels(){
- # $1 = $TARGETS
- for pkg_ver in $1
- do
- for pkg_prefix in linux-headers- linux-image-
- do
- apt-get autoremove --purge -y ${pkg_prefix}${pkg_ver}*
- done
- done
- update-grub
-}
\ No newline at end of file
+LATEST=$(dpkg --list | grep -E -o "linux-image-[0-9]+\.[0-9]+\.[0-9]+-[0-9]+-generic" | grep -o -E "[0-9]+\.[0-9]+\.[0-9]+-[0-9]+" | uniq | sort -n -r | head -1)
+TARGETS=$(dpkg --list | grep -E -o "linux-image-[0-9]+\.[0-9]+\.[0-9]+-[0-9]+-generic" | grep -o -E "[0-9]+\.[0-9]+\.[0-9]+-[0-9]+" | uniq | grep -E -v ${LATEST})
+echo $TARGETS
\ No newline at end of file