@@ -142,11 +142,57 @@ __install() {
142142 fi
143143}
144144
145+ __can_install () {
146+ # Refresh local package databases
147+ if test -f /etc/debian_version; then
148+ apt-get -y update
149+ elif test -f /etc/alpine-release; then
150+ apk update
151+ elif test -f /etc/arch-release; then
152+ pacman --sync --refresh --quiet --noconfirm || :
153+ fi
154+ # If more than one package, test each one individually:
155+ if test $# -ne 1; then
156+ for pkg in " $@ " ; do
157+ __can_install_1 " $pkg " || return
158+ done
159+ return 0
160+ fi
161+ __can_install_1 " $1 "
162+ }
163+
164+ __can_install_1 () {
165+ local package=" $1 "
166+ # Package checks:
167+ if test -f /etc/debian_version; then
168+ __silent apt-cache show -- " $package "
169+ return
170+ elif test -f /etc/redhat-release; then
171+ # "Yum" may be an alias for dnf, but this still works:
172+ __silent yum info " $package "
173+ return
174+ elif test -f /etc/arch-release; then
175+ __silent pacman --sync --info -- " $package "
176+ return
177+ elif test -f /etc/alpine-release; then
178+ __silent apk info -- " $package "
179+ return
180+ else
181+ echo " $0 : We don't know how to manage packages on this system" 1>&2
182+ return 1
183+ fi
184+ }
185+
186+ __silent () {
187+ " $@ " > /dev/null 2>&1
188+ }
189+
145190__init () {
146- __alias __alias __tool __alias
147- __alias __install __tool __install
148- __alias __bool __tool __bool
149- __alias __boolstr __tool __boolstr
191+ __alias __alias __tool __alias
192+ __alias __install __tool __install
193+ __alias __bool __tool __bool
194+ __alias __boolstr __tool __boolstr
195+ __alias __can_install __tool __can_install
150196}
151197
152198cmd=$1
0 commit comments