|
| 1 | +sk-apt-rmadison(){ |
| 2 | + sk_help "$FUNCNAME: package. Search multiple distro versions for a package" "$@" && return |
| 3 | + sk-pack-install rmadison -p devscripts |
| 4 | + rmadison $@ |
| 5 | +} |
| 6 | + |
| 7 | +sk-apt-versions(){ |
| 8 | + local package=${1:-docker} |
| 9 | + apt-cache madison $package |
| 10 | +} |
| 11 | + |
| 12 | +sk-dpkg-sort-size() { |
| 13 | + dpkg-query -W --showformat='${Installed-Size;10}\t${Package}\n' | sort -k1,1nr |
| 14 | +} |
| 15 | + |
| 16 | +sk-apt-key-add() { |
| 17 | + sk_help "$FUNCNAME: <key>(pgdg default). Add a missing apt key" "$@" && return |
| 18 | + key=${1:-7FCC7D46ACCC4CF8} |
| 19 | + sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys $key |
| 20 | +} |
| 21 | + |
| 22 | + |
| 23 | +sk-apt-distupgrade-prep(){ |
| 24 | + sk_help "$FUNCNAME: Prep for a distupgrade by upgrading current release to latest packages. Pass in -f to force upgrade with no prompts." "$@" && return |
| 25 | + local force=$1 |
| 26 | + echo "Prepping OS for upgrade" |
| 27 | + [ "$force" ] || confirm "This will potentially break the distribution, have you taken backups?" || return 1 |
| 28 | + sudo apt-get update |
| 29 | + sudo DEBIAN_FRONTEND=noninteractive apt-get -y -q -o 'DPkg::Options::=--force-confold' upgrade |
| 30 | + sudo apt-get clean all |
| 31 | +} |
| 32 | + |
| 33 | +sk-apt-distupgrade-post(){ |
| 34 | + sk_help "$FUNCNAME: Cleanup after a dist-upgrade. Pass in -f to force upgrade with no prompts." "$@" && return |
| 35 | + local force=$1 |
| 36 | + echo "Checking edge cases after upgrade" |
| 37 | + [ "$force" ] || confirm "This will potentially break the distribution, have you taken backups?" || return 1 |
| 38 | + sudo apt-get -y -q autoremove |
| 39 | + if ! grep -q open-vm-dkms <<< $(dpkg -l) ;then |
| 40 | + sudo apt-get -y install open-vm-dkms |
| 41 | + fi |
| 42 | + |
| 43 | + echo "Running kernel: `uname -va`" |
| 44 | + echo "Installed kernels: `dpkg -l | grep linux`" |
| 45 | + echo "Next bootup kernel: `cat /boot/grub/menu.lst | grep default`" |
| 46 | + echo "`cat /boot/grub/menu.lst | grep title | grep Ubuntu`" |
| 47 | + echo "Ensure you are booting up with the latest kernel if not selected" |
| 48 | + echo "Testing logrotate" |
| 49 | + sudo logrotate /etc/logrotate.conf |
| 50 | + [ "$force" ] || confirm "Perform reboot?" || return 1 |
| 51 | + sudo shutdown -r now |
| 52 | +} |
| 53 | + |
| 54 | + |
| 55 | +# https://www.queryxchange.com/q/3_658047/ubuntu-8-04-lts-upgrade-to-10-04-python-problem-39-with-39-will-become-a-reserved-keyword-in-python-2-6/ |
| 56 | +# http://askubuntu.com/questions/719465/why-does-do-release-upgrade-skip-a-version |
| 57 | +sk-apt-distupgrade-manual(){ |
| 58 | + sk_help_noarg "$FUNCNAME: <LTS RELEASE TO UPGRADE TO> <-f (force)>. Upgrade a system using dist-upgrade NOT do-release-upgrade due to it's limitations of selecting the lts version to upgrade to." "$@" && return |
| 59 | + local upgrade_distro=$1 |
| 60 | + local force=$2 |
| 61 | + sk-apt-distupgrade-prep $force |
| 62 | + current_distro=$(lsb_release -c | awk '{print $2}') |
| 63 | + sudo perl -pi -e "s/${current_distro}/${upgrade_distro}/g" /etc/apt/sources.list /etc/apt/sources.list.d/*.list |
| 64 | + sudo apt-get update |
| 65 | + sudo env DEBIAN_FRONTEND=noninteractive apt-get -y -q -o 'DPkg::Options::=--force-confold' dist-upgrade & |
| 66 | + while [ $(lsof /var/lib/dpkg/lock >> /dev/null;) ];do sleep 2;done |
| 67 | + sk-apt-distupgrade-post $force |
| 68 | +} |
| 69 | + |
| 70 | + |
| 71 | + |
| 72 | + |
| 73 | + |
| 74 | +sk-apt-support-eol(){ |
| 75 | + sk_help "Usage: $FUNCNAME. Migrate an EOL Ubuntu server to the old-releases apt repo. This should be a last resort as we should be upgrading them. Use when OS and code dependencies exist that block an upgrade." "$@" && return |
| 76 | + sudo perl -pi -e 's/us-east-1\.ec2\.archive\.ubuntu\.com/old-releases\.ubuntu\.com/g' /etc/apt/sources.list |
| 77 | + sudo perl -pi -e 's/gb\.archive\.ubuntu\.com/old-releases\.ubuntu\.com/g' /etc/apt/sources.list |
| 78 | + sudo perl -pi -e 's/security\.ubuntu\.com/old-releases\.ubuntu\.com/g' /etc/apt/sources.list |
| 79 | + sudo perl -pi -e 's/deb-src.*$//g' /etc/apt/sources.list |
| 80 | + sudo apt-get clean all |
| 81 | + sudo apt-get update |
| 82 | +} |
| 83 | + |
| 84 | +sk-apt-purge-sources(){ |
| 85 | + sk_help "$FUNCNAME . Clean out any src lines from /etc/apt/sources.list" "$@" && return |
| 86 | + sudo perl -pi -e 's/deb-src.*//g' /etc/apt/sources.list |
| 87 | +} |
| 88 | + |
| 89 | +sk-apt-add-custom-source(){ |
| 90 | + sk_help_noarg "$FUNCNAME <filename_of_source> (/etc/apt/sources.list.d/wibble.conf) <line to add> Add /etc/apt/sources.list.d/<listname>.list" "$@" && return |
| 91 | + local source_filename=$1 |
| 92 | + shift |
| 93 | + if [[ ! -f "$source_filename" ]];then |
| 94 | + sudo bash -c "echo $@ > $source_filename" |
| 95 | + fi |
| 96 | +} |
| 97 | + |
| 98 | +sk-apt-add-distro-source(){ |
| 99 | + sk_help_noarg "$FUNCNAME <distro> <listname>. Add /etc/apt/sources.list.d/<listname>.list" "$@" && return |
| 100 | + local distribution=$1 |
| 101 | + local listfile=${2:-/etc/apt/sources.list.d/$distribution} |
| 102 | + |
| 103 | + # sources.list format: deb uri distribution [component1] [component2] [...] |
| 104 | + [ ! -d /etc/apt/sources.list.d ] && sudo mkdir /etc/apt/sources.list.d |
| 105 | + |
| 106 | + # start with a new file |
| 107 | + sudo rm -f $listfile |
| 108 | + |
| 109 | + lsbdistid=$(lsb_release -i | awk '{print $3}') |
| 110 | + case $lsbdistid in |
| 111 | + Ubuntu) local components="main restricted universe multiverse";; |
| 112 | + Debian) local components="main contrib non-free";; |
| 113 | + *) local components="main restricted universe multiverse";; |
| 114 | + esac |
| 115 | + |
| 116 | + local distribution_list="$distribution ${distribution}-updates ${distribution}-backports" |
| 117 | + echo $distribution_list |
| 118 | + case $distribution in |
| 119 | + lucid) local uri_list="http://old-releases.ubuntu.com/ubuntu/";; |
| 120 | + *) local uri_list="http://gb.archive.ubuntu.com/ubuntu/ http://security.ubuntu.com/ubuntu";; |
| 121 | + esac |
| 122 | + |
| 123 | + for uri in $uri_list;do |
| 124 | + grep -q security <<< $(echo "$uri") && distribution_list="${distribution}-security" |
| 125 | + for distribution_name in $distribution_list;do |
| 126 | + sudo bash -c "echo 'deb-src $uri $distribution_name $components' >> $listfile" |
| 127 | + done |
| 128 | + done |
| 129 | + |
| 130 | +} |
| 131 | +sk-apt-update-repos(){ |
| 132 | + sk_help_noarg "$FUNCNAME <listnames> Update multiple listnames (/etc/apt/sources.list.d/wibble). Avoiding lengthy update of /etc/apt/sources.list " "$@" && return |
| 133 | + for source in "$@"; do |
| 134 | + sudo apt-get update -o Dir::Etc::sourcelist="${source}" \ |
| 135 | + -o Dir::Etc::sourceparts="-" -o APT::Get::List-Cleanup="0" |
| 136 | + done |
| 137 | +} |
| 138 | + |
| 139 | +sk-apt-source-from-repo(){ |
| 140 | + sk_help_noarg "$FUNCNAME <package> <listname>. Source package from listname <listname>(/etc/apt/sources.list.d/wibble) . Avoiding lengthy update of /etc/apt/sources.list " "$@" && return |
| 141 | + apt-get source $1 -o Dir::Etc::sourcelist="$2" \ |
| 142 | + -o Dir::Etc::sourceparts="-" -o APT::Get::List-Cleanup="0" |
| 143 | +} |
| 144 | + |
| 145 | + |
| 146 | + |
0 commit comments