linux中yum脚本安装,linux – 一个通用的bash脚本,用于安装apt-get和yum

我正在尝试编写一个简单的bash包装器,它抽象yum和apt-get.基本上所以我们可以做一些像通用安装卷曲这是我到目前为止:

# universal-install

package=$1

apt=`command -v apt-get`

yum=`command -v yum`

if [ -n "$apt" ]; then

apt-get update

apt-get -y install $package

elif [ -n "$yum" ]; then

yum -y install $package

else

echo "Err: no path to apt-get or yum" >&2;

exit 1;

fi

是否有任何错误或改进/优化可以做出?

解决方法:

# Detect package type from /etc/issue

_found_arch() {

local _ostype="$1"

shift

grep -qis "$*" /etc/issue && _OSTYPE="$_ostype"

}

# Detect package type

_OSTYPE_detect() {

_found_arch PACMAN "Arch Linux" && return

_found_arch DPKG "Debian GNU/Linux" && return

_found_arch DPKG "Ubuntu" && return

_found_arch YUM "CentOS" && return

_found_arch YUM "Red Hat" && return

_found_arch YUM "Fedora" && return

_found_arch ZYPPER "SUSE" && return

[[ -z "$_OSTYPE" ]] || return

# See also https://github.com/icy/pacapt/pull/22

# Please not that $OSTYPE (which is `linux-gnu` on Linux system)

# is not our $_OSTYPE. The choice is not very good because

# a typo can just break the logic of the program.

if [[ "$OSTYPE" != "darwin"* ]]; then

_error "Can't detect OS type from /etc/issue. Running fallback method."

fi

[[ -x "/usr/bin/pacman" ]] && _OSTYPE="PACMAN" && return

[[ -x "/usr/bin/apt-get" ]] && _OSTYPE="DPKG" && return

[[ -x "/usr/bin/yum" ]] && _OSTYPE="YUM" && return

[[ -x "/opt/local/bin/port" ]] && _OSTYPE="MACPORTS" && return

command -v brew >/dev/null && _OSTYPE="HOMEBREW" && return

[[ -x "/usr/bin/emerge" ]] && _OSTYPE="PORTAGE" && return

[[ -x "/usr/bin/zypper" ]] && _OSTYPE="ZYPPER" && return

if [[ -z "$_OSTYPE" ]]; then

_error "No supported package manager installed on system"

_error "(supported: apt, homebrew, pacman, portage, yum)"

exit 1

fi

}

正如您所看到的,它首先检查/ etc / issue,然后失败,脚本会查找每个包管理器的关联可执行文件.

但是,为什么不只是使用pacapt,而不是自己滚动?

标签:bash,linux,yum,apt-get

来源: https://codeday.me/bug/20190825/1717157.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值