#!/bin/bash # Copyright (C) 2014 Ian Kelling # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # http://www.apache.org/licenses/LICENSE-2.0 # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # basic yum/apt package manager abstraction, plus a few minor conveniences if type -p yum > /dev/null; then # package manager p() { local x [[ $EUID == 0 ]] && x=sudo $x yum "$@" } # package install pi() { local x [[ $EUID == 0 ]] && x=sudo $x yum -y install "$@" } # package find pf() { local x [[ $EUID == 0 ]] && x=sudo $x yum search "$@" } # package remove/uninstall pu() { local x [[ $EUID == 0 ]] && x=sudo $x yum autoremove "$@" } pup() { # upgrade local x [[ $EUID == 0 ]] && x=sudo $x yum -y distro-sync full } # package list info pl() { yum info "$@" } else p() { local x [[ $EUID == 0 ]] && x=sudo $x aptitude "$@" } pi() { local x [[ $EUID == 0 ]] && x=sudo # update package list if its more than an hour old if (( $(( $(date +%s) - $(stat -c %Y /var/lib/apt/periodic/update-success-stamp) )) > 60*60 )); then $x aptitude update fi $x aptitude -y install "$@" } pf() { # scratch a very annoying itch. # package description width as wide as the screen, and package name field small # aptitude manual can't figure out how wide emacs terminal is, # of course it doesn't consult the $COLUMNS variable... # and in a normal terminal, it makes the package name field ridiculously big # also, remove that useless dash before the description local x [[ $EUID == 0 ]] && x=sudo $x aptitude -F "%c%a%M %p %$((COLUMNS - 30))d" -w $COLUMNS search "$@" } pu() { local x [[ $EUID == 0 ]] && x=sudo $x aptitude -y purge "$@" } pup() { # upgrade local x [[ $EUID == 0 ]] && x=sudo $x aptitude -y full-upgrade "$@" } # package info pl() { aptitude show "$@" } fi