initial commit
[distro-functions] / src / package-manager-abstractions
1 #!/bin/bash
2 # Copyright (C) 2014 Ian Kelling
3
4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at
7
8 # http://www.apache.org/licenses/LICENSE-2.0
9
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
15
16 # basic yum/apt package manager abstraction, plus a few minor conveniences
17 if type -p yum > /dev/null; then
18 # package manager
19 p() {
20 local x
21 [[ $EUID == 0 ]] && x=sudo
22 $x yum "$@"
23 }
24 # package install
25 pi() {
26 local x
27 [[ $EUID == 0 ]] && x=sudo
28 $x yum -y install "$@"
29 }
30 # package find
31 pf() {
32 local x
33 [[ $EUID == 0 ]] && x=sudo
34 $x yum search "$@"
35 }
36 # package remove/uninstall
37 pu() {
38 local x
39 [[ $EUID == 0 ]] && x=sudo
40 $x yum autoremove "$@"
41 }
42 pup() { # upgrade
43 local x
44 [[ $EUID == 0 ]] && x=sudo
45 $x yum -y distro-sync full
46 }
47 # package list info
48 pl() {
49 yum info "$@"
50 }
51
52 else
53 p() {
54 local x
55 [[ $EUID == 0 ]] && x=sudo
56 $x aptitude "$@"
57 }
58 pi() {
59 local x
60 [[ $EUID == 0 ]] && x=sudo
61 # update package list if its more than an hour old
62 if (( $(( $(date +%s) - $(stat -c %Y /var/lib/apt/periodic/update-success-stamp) )) > 60*60 )); then
63 $x aptitude update
64 fi
65 $x aptitude -y install "$@"
66 }
67 pf() {
68 # scratch a very annoying itch.
69 # package description width as wide as the screen, and package name field small
70 # aptitude manual can't figure out how wide emacs terminal is,
71 # of course it doesn't consult the $COLUMNS variable...
72 # and in a normal terminal, it makes the package name field ridiculously big
73 # also, remove that useless dash before the description
74 local x
75 [[ $EUID == 0 ]] && x=sudo
76 $x aptitude -F "%c%a%M %p %$((COLUMNS - 30))d" -w $COLUMNS search "$@"
77 }
78 pu() {
79 local x
80 [[ $EUID == 0 ]] && x=sudo
81 $x aptitude -y purge "$@"
82 }
83 pup() { # upgrade
84 local x
85 [[ $EUID == 0 ]] && x=sudo
86 $x aptitude -y full-upgrade "$@"
87 }
88 # package info
89 pl() {
90 aptitude show "$@"
91 }
92
93 fi