77965bbce02f1f318887042e67cacf1575bb5f90
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
52 local s
; [[ $EUID != 0 ]] && s
=sudo
56 local s f
; [[ $EUID != 0 ]] && s
=sudo
57 # update package list if its more than an 2 hours old
58 f
=/var
/cache
/apt
/pkgcache.bin
60 ||
(( $
(( $
(date +%s
) - $
(stat
-c %Y
$f ) )) > 60*60*2 )); then
66 local s
; [[ $EUID != 0 ]] && s
=sudo
67 $s apt-get
-y install "$@"
70 local s
; [[ $EUID != 0 ]] && s
=sudo
71 local f
=/usr
/sbin
/policy-rc.d
81 # scratch a very annoying itch. package description width as
82 # wide as the screen, and package name field small aptitude
83 # manual can't figure out how wide emacs terminal is, of course
84 # it doesn't consult the $COLUMNS variable... and in a normal
85 # terminal, it makes the package name field ridiculously big
86 # also, remove that useless dash before the description
87 local s
; [[ $EUID != 0 ]] && s
=sudo
88 $s aptitude
-F "%c%a%M %p %$((COLUMNS - 30))d" -w $COLUMNS search
"$@"
91 local s
; [[ $EUID != 0 ]] && s
=sudo
92 $s apt-get
-y remove
--purge --auto-remove "$@"
96 local s
; [[ $EUID != 0 ]] && s
=sudo
97 $s apt-get
-y dist-upgrade
"$@"
98 $s apt-get
-y autoremove
106 # ucfq can tell us about config files which are not tracked
107 # with apt-file. but, for at least a few files I tested
108 # which are tracked with apt-file, ucfq doesn't show their
109 # package name. So, commenting this, waiting to find
110 # a config file only tracked by ucfq to see if it gives the
111 # package name and if I can identify this kind of file.
112 # if [[ $file == /* ]] && ! ucfq -w $file | grep ::: &>/dev/null; then
115 if [[ $file == */* ]]; then
116 apt-file
find -x "$file"\$
118 apt-file
find -x /"$file"\$
122 if dpkg
-s "$1" &>/dev
/null
; then
125 apt-file
-x list
"^$1$"
129 elif command -v pacman
&>/dev
/null
; then
134 pacaur
-S --noconfirm --needed --noedit "$@"
140 pacaur
-Rs --noconfirm "$@"
141 if p
=$
(pacaur
-Qdtq); then
147 aur
='https://aur.archlinux.org'
148 curl
-s $aur/$
(curl
-s "$aur/rpc.php?type=info&arg=$p" \
149 | jq
-r .results.URLPath
) |
tar xz
154 local s
; [[ $EUID != 0 ]] && s
=sudo
156 curl
-s "https://www.archlinux.org/mirrorlist/\
157 ?country=US&protocol=https&ip_version=4&ip_version=6&use_mirror_status=on" \
158 |
sed -r 's/^[ #]*(Server *=)/\1/' > $x
159 if (( $
(stat
-c %s
$x ) > 10 )); then
160 $s cp $x /etc
/pacman.d
/mirrorlist
165 local s
; [[ $EUID != 0 ]] && s
=sudo
166 # file_time + 24 hours > current_time
167 if ! (( $
(stat
-c%Y
/etc
/pacman.d
/mirrorlist
) + 60*60*24 > $
(date +%s
) ))
171 pacaur
-Syu --noconfirm "$@"
181 if pacaur
-Qs "^$1$" &>/dev
/null
; then