Skip to content
This repository has been archived by the owner on Feb 24, 2024. It is now read-only.

Commit

Permalink
添加root用户相关判定
Browse files Browse the repository at this point in the history
  • Loading branch information
yechentide committed Oct 22, 2022
1 parent 6a1a898 commit 6729f28
Showing 1 changed file with 31 additions and 7 deletions.
38 changes: 31 additions & 7 deletions bin/environment/install_dependencies
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ echo ''
color_print info '需要下载或更新的软件: '
echo "${requires[@]}"

if [[ $is_sudoer == 'no' ]]; then
if [[ $is_sudoer == 'no' ]] && [[ $(whoami) != 'root' ]]; then
color_print warn '以上软件是否已安装?没有安装的话请联系该服务器的管理员...'
confirm warn '是否已安装?'
if [[ $(cat ANSWER_PATH) == 'yes' ]]; then return 0; fi
Expand All @@ -58,6 +58,12 @@ if [[ $is_sudoer == 'no' ]]; then
exit 1
fi

which sudo > /dev/null 2>&1
if [[ $? == 1 ]] && [[ $(whoami) != 'root' ]]; then
color_print error '没有sudo命令,无权限下载安装必须软件,终止运行脚本。请联系服务器管理员解决。'
exit 1
fi

confirm warn '是否要开始安装依赖?'
if [[ $(cat $ANSWER_PATH) == 'no' ]]; then
color_print error '终止安装依赖包, 结束脚本'
Expand All @@ -66,23 +72,41 @@ fi

color_print -n info '即将以管理员权限下载更新软件,可能会要求输入当前用户的密码 '
count_down 3

if [[ $1 == 'Ubuntu' ]]; then
sudo apt update && sudo apt upgrade -y
if [[ $(whoami) == 'root' ]] then
apt update && sudo apt upgrade -y
else
sudo apt update && sudo apt upgrade -y
fi
declare -r manager='apt'
elif [[ $1 == 'CentOS' ]]; then
sudo yum update -y
fi

if [[ $1 == 'CentOS' ]]; then
if [[ $(whoami) == 'root' ]] then
yum update -y
else
sudo yum update -y
fi
declare -r manager='yum'
fi

declare package
for package in ${requires[@]}; do
eval "sudo $manager install -y $package"
if [[ $(whoami) == 'root' ]] then
eval "$manager install -y $package"
else
eval "sudo $manager install -y $package"
fi
done

if [[ $1 == 'CentOS' ]] && [[ ! -e /usr/lib64/libcurl-gnutls.so.4 ]]; then
# To fix: libcurl-gnutls.so.4: cannot open shared object file: No such file or directory
sudo ln -s /usr/lib64/libcurl.so.4 /usr/lib64/libcurl-gnutls.so.4
if [[ $(whoami) == 'root' ]] then
ln -s /usr/lib64/libcurl.so.4 /usr/lib64/libcurl-gnutls.so.4
else
sudo ln -s /usr/lib64/libcurl.so.4 /usr/lib64/libcurl-gnutls.so.4
fi
fi

declare flag=1
Expand Down

0 comments on commit 6729f28

Please sign in to comment.