Lazy APT Management
In preparation for the Sekati Reboot I did a major infrastructure overhaul. Part of this involved rolling my own Xen dom0 on new, collocated hardware to host service separated para-virtualized domU server instances.
In the process of preparing the VPS‘s a new, linux based operating system was selected; specifically Debian (where historically OpenBSD was my flavor of choice) – this was done for it’s strong Xen support & superior (compared with the OpenBSD ports tree) package management system.
Of course what I’m referring to is APT & it’s wonderful management tools apt-get, dpkg & aptitude. Let me be clear in saying; these tools are ridiculously easy to use, have solid man pages & too many blog tutorials to mention.
The problem? Simply put: I’m lazy (the good lazy). And I want to do things in one simple terminal command. And I want to engineer mindless maintenance away via cron as much and as often as is safe or sane. In other words; I want a good control script that bundles & wraps all the apt-get love into short sweet commands & parallel-ssh execute them across all my virtual machines for day-to-day admin stuff.
So, of course, I wrote AptManager to fill this little lazy niche of mine. And now I’m sharing it with you; enjoy!
AptManager v1.2.3 [download]
001 002 003 004 005 006 007 008 009 010 011 012 013 014 015 016 017 018 019 020 021 022 023 024 025 026 027 028 029 030 031 032 033 034 035 036 037 038 039 040 041 042 043 044 045 046 047 048 049 050 051 052 053 054 055 056 057 058 059 060 061 062 063 064 065 066 067 068 069 070 071 072 073 074 075 076 077 078 079 080 081 082 083 084 085 086 087 088 089 090 091 092 093 094 095 096 097 098 099 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 | #!/bin/sh # Sekati: Apt Manager # @author jason m horwitz | sekati.com # Copyright (C) 2010 jason m horwitz, Sekat LLC. All Rights Reserved. # # CHANGELOG # 1.2.0 - now compatible with Bash4 # 1.2.2 - adding maintenance NAME= "AptManager" VERSION= "1.2.3" DEL= "******************************************************" printHeader() { echo "\n$DEL\n$NAME v$VERSION\n$DEL\n" } printUsage() { echo "Usage: $0 { \n\tupdate | upgrade | [maint|maintenance] | dselect-upgrade | dist-upgrade \n\tsetup | [find|search] | install | reinstall \n\t[remove,uninstall] | autoremove | clean | autoclean \n\trepair | reconfigure | [list|installed] | show | showpkg | depends |status \n\t} package_name\n" } # die [goodbye_message] die() { echo $@ exit 1 } # confirm [question] confirm() { read -p "$1 (y/n) " [ "$REPLY" == y ] || die "\n$NAME Exiting..." } # checkArg [argument_name, value] checkArg() { if test -z "$2" ; then die "Missing Argument: $1!\n" fi } printHeader case $1 in update) echo "Updating Package Database ...\n" apt-get update ;; upgrade) echo "Upgrading All Installed Packages ...\n" apt-get -u upgrade ;; maint|maintenance) echo "Updating, Upgrading & Cleaning ...\n" apt-get update apt-get -u upgrade apt-get autoclean apt-get autoremove ;; dselect-upgrade) echo "Upgrading All Installed Packages with DSelect ...\n" apt-get -u dselect-upgrade ;; dist-upgrade) echo "Upgrading Distribution Packages ...\n" apt-get -u dist-upgrade ;; setup) echo "Setup: Changing list of apt mirrors ...\n" apt-setup ;; search| find ) checkArg "Package Name" $2 echo "Searching for package: $2 ...\n" apt-cache search $2 ;; install ) checkArg "Package Name" $2 echo "Attempting to install package: $2 ...\n" apt-get install $2 ;; reinstall) checkArg "Package Name" $2 echo "Attempting to Reinstall package: $2 ...\n" apt-get --reinstall install $2 ;; remove|uninstall) checkArg "Package Name" $2 echo "Attempting to Remove & Purge Package: $2 ...\n" apt-get --purge remove $2 ;; autoremove) echo "Auto-Removing Unused Packages ...\n" apt-get autoremove ;; clean) echo "Cleaning ...\n" apt-get clean ;; autoclean) echo "Auto-Cleaning ...\n" apt-get autoclean ;; repair|fix) confirm "Are you sure you want to attempt to fix/repair the apt package error?\nThis will run the commands: `apt-get -f install && dpkg --configure -a`" apt-get -f install dpkg --configure -a ;; reconfigure) checkArg "Package Name" $2 confirm "Are you sure you want to reconfigure $2?" dpkg --reconfigure $2 ;; list|installed) echo "Listing Installed & Removed Packages ...\n" dpkg -l ;; show) checkArg "Package Name" $2 echo "Showing Package Info ...\n" apt-cache show $2 ;; showpkg) checkArg "Package Name" $2 echo "Showing Package ...\n" apt-cache showpkg $2 ;; depends) checkArg "Package Name" $2 echo "Showing Package Dependencies ...\n" apt-cache depends $2 ;; status) checkArg "Package Name" $2 echo "Showing package status: $2 ...\n" dpkg -l $2 ;; *|?) printUsage exit 1 ;; esac exit 0 |
—