如何解决检查根权限时未调用Bash函数
我想制作一个bash脚本来检查是否安装了指定的软件包。这样做通常需要root权限。
我希望整个代码都能正常工作,但是在调用check_requirements
时无法正常工作。
它不会打印任何消息。
代码如下:
#!/bin/bash
# This function installs the specified dependencies when called
install_requirements () {
echo "$BCyan Downloading required packages... $Color_Off"
apt-get install -y ${pkgs[@]}
if [ "$?" -eq 0 ]; then
echo "$Green Requirements are installed."
else
echo "$BRed Error encountered while downloading requirements."
fi
echo "$Blue Cleaning apt leftovers... $Color_Off" && apt-get autoclean && apt-get autoremove
}
# This function check if specified dependencies (aka packages) are installed. If not,install
check_requirements () {
pkgs=( "zip" "unzip" "wget" "curl" "default-jdk" "jq" )
## Run the run_install function if sany of the libraries are missing
dpkg -s "${pkgs[@]}" >/dev/null 2>&1 || install_requirements
}
root_check () {
if [ "$EUID" -ne 0 ];then
sudo "$0" "$@"
if [ "$?" -eq 0 ]; then
check_requirements
else
echo "$Red Couldn't check for updates $Color_Off"
fi
fi
}
root_check
我在这里呆了很长时间。你能帮我找到我的困境的答案吗?
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。