#! /usr/bin/env bash # -*- coding: utf-8; indent-tabs-mode: nil; tab-width: 4; c-basic-offset: 4; -*- # # Copyright (C) 2020 Shih-Yuan Lee (FourDollars) # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see . url='https://kernel.ubuntu.com/~kernel-ppa/mainline' script="$0" set -e eval set -- $(getopt -o "dhlruf:t:" -l "download-only,help,list,remove,update,from:,to:" -- $@) while :; do case "$1" in ('-h'|'--help') cat <&1 >/dev/tty) } remove_installed_mainline_kernels () { installed="" for i in $(dpkg-query -W | grep linux-image-[2-9] | cut -d '-' -f 3-4); do if [ $(echo $i | cut -d '-' -f 2 | wc -c) -gt 6 ]; then installed="$installed $i" fi done for i in $(dpkg-query -W | grep linux-image-unsigned-[2-9] | cut -d '-' -f 4-5); do if [ $(echo $i | cut -d '-' -f 2 | wc -c) -gt 6 ]; then installed="$installed $i" fi done if [ -z "$installed" ]; then echo "There is no mainline kernel to remove." exit fi num=$(echo $installed | xargs -n1 | wc -l) installed=$(echo $installed | xargs -n1 | awk '{ print $1, "kernel", "off" }' | xargs echo) packages="" for i in $(whiptail --clear --checklist 'Select kernels to remove...' 0 0 $num $installed 2>&1 >/dev/tty); do packages="$packages $(dpkg-query -W | eval grep linux.*$i | awk '{print $1}')" done if [ -n "$packages" ]; then sudo apt-get purge $packages --yes fi } if [ -n "$update" ]; then wget https://raw.githubusercontent.com/fourdollars/scripts/master/mainline-kernels.sh -O $script exit fi if [ -n "$remove" ]; then remove_installed_mainline_kernels exit fi if [ -n "$*" ]; then noprompt=1 downloads="$*" fi if [ -z "$download_only" ]; then action="install" else action="download" fi if [ -z "$downloads" ]; then check_available_kernels if [ -z "$list" ]; then select_kernels_to_install else echo $downloads | xargs -n6 | column -t | sed 's/-rc/~rc/g' exit fi fi if [ -z "$noprompt" ] && [ -n "$downloads" ] && ! whiptail --title "Would you like to $action these kernels?" --yesno "$(echo $downloads | xargs -n1)" 0 0; then exit fi download_and_install_kernels # vim:fileencodings=utf-8:expandtab:tabstop=4:shiftwidth=4:softtabstop=4