Skip to content

Commit

Permalink
Remove unnecessary sudo commands, since scripts run with root user pr…
Browse files Browse the repository at this point in the history
…ivileges by default.
  • Loading branch information
loyess committed Apr 10, 2024
1 parent 19e44dc commit 721565d
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 25 deletions.
8 changes: 4 additions & 4 deletions utils/dependencies.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ error_detect_deps_of_ubuntu(){
package_install "psmisc" > /dev/null 2>&1
fi
sleep 3
sudo killall -q apt apt-get
killall -q apt apt-get
${command} > /dev/null 2>&1
if [ $? -ne 0 ]; then
_echo -e "依赖包${Red}${depend}${suffix}安装失败,请检查. "
Expand All @@ -35,12 +35,12 @@ error_asciidos_deps_of_ubuntu1901(){
local depend=$2

sleep 3
sudo dpkg --configure -a > /dev/null 2>&1
dpkg --configure -a > /dev/null 2>&1
${command} > /dev/null 2>&1
if [ $? -ne 0 ]; then
if ls -l /var/lib/dpkg/info | grep -qi 'python-sympy'; then
sudo mv -f /var/lib/dpkg/info/python-sympy.* /tmp
sudo apt update > /dev/null 2>&1
mv -f /var/lib/dpkg/info/python-sympy.* /tmp
apt update > /dev/null 2>&1
fi
${command} > /dev/null 2>&1
if [ $? -ne 0 ]; then
Expand Down
4 changes: 2 additions & 2 deletions utils/uninstall.sh
Original file line number Diff line number Diff line change
Expand Up @@ -224,10 +224,10 @@ caddy_uninstall(){
nginx_uninstall(){
if [[ -e ${NGINX_BIN_PATH} ]] && [[ -e ${WEB_INSTALL_MARK} ]]; then
if check_sys packageManager yum; then
sudo yum remove -y nginx > /dev/null 2>&1
yum remove -y nginx > /dev/null 2>&1
rm -rf $(dirname ${NGINX_CONFIG})
elif check_sys packageManager apt; then
sudo apt remove -y nginx --purge > /dev/null 2>&1
apt remove -y nginx --purge > /dev/null 2>&1
rm -rf $(dirname ${NGINX_CONFIG})
fi
rm -rf ${WEB_INSTALL_MARK}
Expand Down
38 changes: 19 additions & 19 deletions webServer/nginx_install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ check_sys_and_add_source(){

if check_sys sysRelease centos; then
# 安装依赖
sudo yum install -y yum-utils
yum install -y yum-utils

# 添加 Nginx 源
touch /etc/yum.repos.d/nginx.repo
Expand All @@ -28,12 +28,12 @@ check_sys_and_add_source(){

if [[ ${PKG_FLAG} = "1" ]]; then
# 安装nginx 稳定版
sudo yum-config-manager --disable nginx-mainline
sudo yum install -y nginx
yum-config-manager --disable nginx-mainline
yum install -y nginx
elif [[ ${PKG_FLAG} = "2" ]]; then
# 安装nginx 主线版
sudo yum-config-manager --enable nginx-mainline
sudo yum install -y nginx
yum-config-manager --enable nginx-mainline
yum install -y nginx
fi

if [ $? -eq 0 ]; then
Expand All @@ -42,59 +42,59 @@ check_sys_and_add_source(){

elif check_sys sysRelease debian; then
# 安装依赖
sudo apt install -y curl gnupg2 ca-certificates lsb-release
apt install -y curl gnupg2 ca-certificates lsb-release

if [[ ${PKG_FLAG} = "1" ]]; then
# 添加 Nginx稳定版 源
echo "deb https://nginx.org/packages/debian `lsb_release -cs` nginx" | sudo tee /etc/apt/sources.list.d/nginx.list
echo "deb https://nginx.org/packages/debian `lsb_release -cs` nginx" | tee /etc/apt/sources.list.d/nginx.list
elif [[ ${PKG_FLAG} = "2" ]]; then
# 添加 Nginx主线版 源
echo "deb https://nginx.org/packages/mainline/debian `lsb_release -cs` nginx" | sudo tee /etc/apt/sources.list.d/nginx.list
echo "deb https://nginx.org/packages/mainline/debian `lsb_release -cs` nginx" | tee /etc/apt/sources.list.d/nginx.list
fi

# 导入官方的nginx签名密钥
curl -fsSL https://nginx.org/keys/nginx_signing.key | sudo apt-key add -
curl -fsSL https://nginx.org/keys/nginx_signing.key | apt-key add -

# 验证key是否正确
# 打印如下:
# pub rsa2048 2011-08-19 [SC] [expires: 2024-06-14]
# 573B FD6B 3D8F BC64 1079 A6AB ABF5 BD82 7BD9 BF62
# uid [ unknown] nginx signing key <[email protected]>
sudo apt-key fingerprint ABF5BD827BD9BF62
apt-key fingerprint ABF5BD827BD9BF62

# 安装nginx
sudo apt update
sudo apt install -y nginx
apt update
apt install -y nginx

if [ $? -eq 0 ]; then
_echo -i "nginx安装成功."
fi

elif check_sys sysRelease ubuntu && version_ge ${version} 16.04; then
# 安装依赖
sudo apt install -y curl gnupg2 ca-certificates lsb-release
apt install -y curl gnupg2 ca-certificates lsb-release

if [[ ${PKG_FLAG} = "1" ]]; then
# 添加 Nginx稳定版 源
echo "deb https://nginx.org/packages/ubuntu `lsb_release -cs` nginx" | sudo tee /etc/apt/sources.list.d/nginx.list
echo "deb https://nginx.org/packages/ubuntu `lsb_release -cs` nginx" | tee /etc/apt/sources.list.d/nginx.list
elif [[ ${PKG_FLAG} = "2" ]]; then
# 添加 Nginx主线版 源
echo "deb https://nginx.org/packages/mainline/ubuntu `lsb_release -cs` nginx" | sudo tee /etc/apt/sources.list.d/nginx.list
echo "deb https://nginx.org/packages/mainline/ubuntu `lsb_release -cs` nginx" | tee /etc/apt/sources.list.d/nginx.list
fi

# 导入官方的nginx签名密钥
curl -fsSL https://nginx.org/keys/nginx_signing.key | sudo apt-key add -
curl -fsSL https://nginx.org/keys/nginx_signing.key | apt-key add -

# 验证key是否正确
# 打印如下:
# pub rsa2048 2011-08-19 [SC] [expires: 2024-06-14]
# 573B FD6B 3D8F BC64 1079 A6AB ABF5 BD82 7BD9 BF62
# uid [ unknown] nginx signing key <[email protected]>
sudo apt-key fingerprint ABF5BD827BD9BF62
apt-key fingerprint ABF5BD827BD9BF62

# 安装nginx
sudo apt update
sudo apt install -y nginx
apt update
apt install -y nginx

if [ $? -eq 0 ]; then
_echo -i "nginx安装成功."
Expand Down

0 comments on commit 721565d

Please sign in to comment.