2 # Copyright (C) 2014 Ian Kelling
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
8 # http://www.apache.org/licenses/LICENSE-2.0
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.
16 # basic yum/apt package manager abstraction, plus a few minor conveniences
17 if command -v yum
&> /dev
/null
; then
20 local s
; [[ $EUID != 0 ]] && s
=sudo
25 local s
; [[ $EUID != 0 ]] && s
=sudo
26 $s yum
-y install "$@"
30 local s
; [[ $EUID != 0 ]] && s
=sudo
33 # package remove/uninstall
35 local s
; [[ $EUID != 0 ]] && s
=sudo
36 $s yum autoremove
"$@"
39 local s
; [[ $EUID != 0 ]] && s
=sudo
40 $s yum
-y distro-sync full
"$@"
47 yum whatprovides \
*/$1
50 elif command -v apt-get
&>/dev
/null
; then
54 while fuser
/var
/lib
/dpkg
/lock
&>/dev
/null
; do
57 if (( i
> 300 )); then
58 echo "error: timed out waiting for /var/lib/dpkg/lock" >&2
65 if [[ $1 == -* ]]; then
71 if dpkg
-s -- "$@" |
& grep -Fx "Status: install ok installed" &>/dev
/null
; then
76 pp
() { # package policy
80 local s
; [[ $EUID != 0 ]] && s
=sudo
83 $s apt-get
--purge --auto-remove "$@"
91 local now t s f cachetime limittime
; [[ $EUID != 0 ]] && s
=sudo
92 # update package list if its more than an 2 hours old
93 f
=/var
/cache
/apt
/pkgcache.bin
95 cachetime
=$
(stat
-c %Y
$f )
100 limittime
=$
(( now
- 60*60*2 ))
101 for f
in /etc
/apt
/sources.list
/etc
/apt
/sources.list.d
/*.list
; do
104 if (( t
> limittime
)); then
109 if (( cachtime
> limittime
)); then
114 pcheck
"$@" ||
return 0
116 if [[ $
- != *i
* ]]; then
119 if [[ $EUID == 0 ]]; then
120 DEBIAN_FRONTEND
=noninteractive apt-get
-y install --purge --auto-remove "$@"
122 sudo DEBIAN_FRONTEND
=noninteractive apt-get
-y install --purge --auto-remove "$@"
129 pcheck
"$@" ||
return 0
132 local f
=/usr
/sbin
/policy-rc.d
133 if [[ $
- != *i
* ]]; then
136 if [[ $EUID == 0 ]]; then
137 dd of
=$f 2>/dev
/null
<<EOF
142 DEBIAN_FRONTEND
=noninteractive apt-get
-y install --purge --auto-remove "$@" || ret
=$?
145 sudo
dd of
=$f 2>/dev
/null
<<EOF
150 sudo DEBIAN_FRONTEND
=noninteractive apt-get
-y install --purge --auto-remove "$@" || ret
=$?
155 # package find description
157 # package name and descriptions
158 apt-cache search
"$@"
162 local s
; [[ $EUID != 0 ]] && s
=sudo
163 # nice aptitude search from emacs shell. package description width as
164 # wide as the screen, and package name field small aptitude
165 # manual can't figure out how wide emacs terminal is, of course
166 # it doesn't consult the $COLUMNS variable... and in a normal
167 # terminal, it makes the package name field ridiculously big
168 # also, remove that useless dash before the description
169 aptitude
-F "%c%a%M %p %$((COLUMNS - 30))d" -w $COLUMNS search
"$@"
172 local s
; [[ $EUID != 0 ]] && s
=sudo
175 if dpkg
-s -- "$arg" &>/dev
/null
; then
182 $s apt-get
-y remove
--purge --auto-remove "$@"
183 # seems slightly redundant, but it removes more stuff sometimes.
184 $s apt-get
-y autoremove
189 local s
; [[ $EUID != 0 ]] && s
=sudo
190 $s apt-get
-y dist-upgrade
--purge --auto-remove "$@"
191 $s apt-get
-y autoremove
195 if type -p aptitude
&>/dev
/null
; then
202 # -a = search all repos
212 # ucfq can tell us about config files which are not tracked
213 # with apt-file. but, for at least a few files I tested
214 # which are tracked with apt-file, ucfq doesn't show their
215 # package name. So, commenting this, waiting to find
216 # a config file only tracked by ucfq to see if it gives the
217 # package name and if I can identify this kind of file.
218 # if [[ $file == /* ]] && ! ucfq -w $file | grep ::: &>/dev/null; then
221 if [[ $file == /* ]]; then
225 arg
=(--filter-origins "$(positive-origins)")
227 if [[ $file == /* ]]; then
228 apt-file
"${arg[@]}" find -x /"$file"\$
229 update-alternatives
--list "$file" 2>/dev
/null
231 apt-file
"${arg[@]}" find -x "$file"\$
236 if dpkg
-s "$1" &>/dev
/null
; then
239 apt-file
-x list
"^$1$"
243 elif command -v pacman
&>/dev
/null
; then
248 pacaur
-S --noconfirm --needed --noedit "$@"
254 pacaur
-Rs --noconfirm "$@"
255 if p
=$
(pacaur
-Qdtq); then
261 aur
='https://aur.archlinux.org'
262 curl
-s $aur/$
(curl
-s "$aur/rpc.php?type=info&arg=$p" \
263 | jq
-r .results.URLPath
) |
tar xz
268 local s
; [[ $EUID != 0 ]] && s
=sudo
270 curl
-s "https://www.archlinux.org/mirrorlist/\
271 ?country=US&protocol=https&ip_version=4&ip_version=6&use_mirror_status=on" \
272 |
sed -r 's/^[ #]*(Server *=)/\1/' > $x
273 if (( $
(stat
-c %s
$x ) > 10 )); then
274 $s cp $x /etc
/pacman.d
/mirrorlist
279 local s
; [[ $EUID != 0 ]] && s
=sudo
280 # file_time + 24 hours > current_time
281 if ! (( $
(stat
-c%Y
/etc
/pacman.d
/mirrorlist
) + 60*60*24 > $
(date +%s
) ))
285 pacaur
-Syu --noconfirm "$@"
295 if pacaur
-Qs "^$1$" &>/dev
/null
; then