diff --git a/Menus/Automation.sh b/Menus/Automation.sh index dc2da5b..bdfd5c1 100644 --- a/Menus/Automation.sh +++ b/Menus/Automation.sh @@ -57,9 +57,9 @@ bash "${path_script}/Config/${file_name}/${print_array[pick]}.sh" "$path" chmod +x "${path}/${print_array[pick]}.sh" declare cron_job="${cron} ${path}/${print_array[pick]}.sh" -(crontab -l 2>/dev/null | grep -v "${print_array[pick]}.sh") | sudo crontab - -(crontab -l 2>/dev/null; echo "$cron_job") | sudo crontab - +(crontab -l 2>/dev/null | grep -v "${print_array[pick]}.sh") | crontab - +(crontab -l 2>/dev/null; echo "$cron_job") | crontab - -sudo systemctl restart cron 2>> /dev/null || echo "自动任务重启失败" +systemctl restart cron 2>> /dev/null || echo "自动任务重启失败" echo "配置完成" \ No newline at end of file diff --git a/Menus/Docker.sh b/Menus/Docker.sh index cbd34cb..2d357b5 100644 --- a/Menus/Docker.sh +++ b/Menus/Docker.sh @@ -51,12 +51,12 @@ if [[ $pick == '1' ]];then echo "输入错误" exit fi - sudo echo "{\"registry-mirrors\": [\"${url}\"]}" > "/etc/docker/daemon.json" - sudo systemctl restart docker 2>> /dev/null|| echo "docker 重启失败" + echo "{\"registry-mirrors\": [\"${url}\"]}" > "/etc/docker/daemon.json" + systemctl restart docker 2>> /dev/null|| echo "docker 重启失败" echo "换源成功" elif [[ $pick == '2' ]];then - sudo docker system prune -af + docker system prune -af echo "清理完成" elif [[ "${pick}" -gt "$((${pick_number}-${#pick_array[*]}))" && "${pick}" -le "${pick_number}" ]];then declare file_path diff --git a/Menus/Login.sh b/Menus/Login.sh index 731928a..a62fb33 100644 --- a/Menus/Login.sh +++ b/Menus/Login.sh @@ -15,10 +15,10 @@ case $pick in 1) declare password read -p "请输入root密码:" password - echo "root:$password" |sudo chpasswd - sudo sed -i 's/^#\?PermitRootLogin.*/PermitRootLogin yes/g' /etc/ssh/sshd_config - sudo sed -i 's/^#\?PasswordAuthentication.*/PasswordAuthentication yes/g' /etc/ssh/sshd_config - sudo systemctl restart sshd.service + echo "root:$password" |chpasswd + sed -i 's/^#\?PermitRootLogin.*/PermitRootLogin yes/g' /etc/ssh/sshd_config + sed -i 's/^#\?PasswordAuthentication.*/PasswordAuthentication yes/g' /etc/ssh/sshd_config + systemctl restart sshd.service echo "修改成功当前root密码为:$password" ;; 2) @@ -45,18 +45,18 @@ case $pick in chmod 600 "$HOME/.ssh/authorized_keys" chmod 700 "$HOME/.ssh" - sudo sed -i 's/^#\?PubkeyAuthentication.*/PubkeyAuthentication yes/g' /etc/ssh/sshd_config + sed -i 's/^#\?PubkeyAuthentication.*/PubkeyAuthentication yes/g' /etc/ssh/sshd_config declare pick2 echo "是否关闭密码登录:" read -p "输入 n 取消关闭:" pick2 if [[ ! $pick2 =~ [Nn] ]];then - sudo sed -i 's/^#\?PasswordAuthentication.*/PasswordAuthentication no/g' /etc/ssh/sshd_config + sed -i 's/^#\?PasswordAuthentication.*/PasswordAuthentication no/g' /etc/ssh/sshd_config fi - sudo systemctl restart sshd.service + systemctl restart sshd.service echo "密钥安装完成" ;; @@ -72,9 +72,9 @@ case $pick in useradd -m -s /bin/bash "$user_name" if grep -q "^$user_name " /etc/sudoers;then - sudo sed -i "s/^#\?$user_name.*/lsy ALL=(ALL) NOPASSWD: ALL/g" /etc/sudoers + sed -i "s/^#\?$user_name.*/lsy ALL=(ALL) NOPASSWD: ALL/g" /etc/sudoers else - sudo echo "lsy ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers + echo "lsy ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers fi @@ -86,16 +86,16 @@ case $pick in if [[ ! $pick =~ [Nn] ]];then declare password read -p "请输入密码:" password - echo "$user_name:$password" |sudo chpasswd - sudo sed -i 's/^#\?PasswordAuthentication.*/PasswordAuthentication yes/g' /etc/ssh/sshd_config; + echo "$user_name:$password" |chpasswd + sed -i 's/^#\?PasswordAuthentication.*/PasswordAuthentication yes/g' /etc/ssh/sshd_config; echo "创建成功" echo "账号:$user_name" echo "密码:$password" else - sudo sed -i 's/^#\?PubkeyAuthentication.*/PubkeyAuthentication yes/g' /etc/ssh/sshd_config + sed -i 's/^#\?PubkeyAuthentication.*/PubkeyAuthentication yes/g' /etc/ssh/sshd_config su "$user_name" -c "mkdir -p '/home/$user_name/.ssh'" - sudo cp "/root/.ssh/authorized_keys" "/home/$user_name/.ssh/authorized_keys" - sudo chown lsy:lsy "/home/$user_name/.ssh/authorized_keys" + cp "/root/.ssh/authorized_keys" "/home/$user_name/.ssh/authorized_keys" + chown lsy:lsy "/home/$user_name/.ssh/authorized_keys" su "$user_name" -c "chmod 600 '/home/$user_name/.ssh/authorized_keys'" su "$user_name" -c "chmod 700 '/home/$user_name/.ssh/'" @@ -109,11 +109,11 @@ case $pick in read -p "输入 n 取消关闭:" pick2 if [[ ! $pick2 =~ [Nn] ]];then - sudo sed -i 's/^#\?PermitRootLogin.*/PermitRootLogin no/g' /etc/ssh/sshd_config + sed -i 's/^#\?PermitRootLogin.*/PermitRootLogin no/g' /etc/ssh/sshd_config echo "root用户登录已关闭" fi - sudo systemctl restart sshd.service + systemctl restart sshd.service ;; 4) @@ -128,30 +128,30 @@ case $pick in read -p "输入 n 关闭:" pick2_key if [[ ! $pick_root =~ [Nn] ]];then - sudo sed -i 's/^#\?PermitRootLogin.*/PermitRootLogin yes/g' /etc/ssh/sshd_config + sed -i 's/^#\?PermitRootLogin.*/PermitRootLogin yes/g' /etc/ssh/sshd_config echo "root用户登录:开启" else - sudo sed -i 's/^#\?PermitRootLogin.*/PermitRootLogin no/g' /etc/ssh/sshd_config + sed -i 's/^#\?PermitRootLogin.*/PermitRootLogin no/g' /etc/ssh/sshd_config echo "root用户登录:关闭" fi if [[ ! $pick2_password =~ [Nn] ]];then - sudo sed -i 's/^#\?PasswordAuthentication.*/PasswordAuthentication yes/g' /etc/ssh/sshd_config + sed -i 's/^#\?PasswordAuthentication.*/PasswordAuthentication yes/g' /etc/ssh/sshd_config echo "密码登录:开启" else - sudo sed -i 's/^#\?PasswordAuthentication.*/PasswordAuthentication no/g' /etc/ssh/sshd_config + sed -i 's/^#\?PasswordAuthentication.*/PasswordAuthentication no/g' /etc/ssh/sshd_config echo "密码登录:关闭" fi if [[ ! $pick2_key =~ [Nn] ]];then - sudo sed -i 's/^#\?PubkeyAuthentication.*/PubkeyAuthentication yes/g' /etc/ssh/sshd_config + sed -i 's/^#\?PubkeyAuthentication.*/PubkeyAuthentication yes/g' /etc/ssh/sshd_config echo "密钥登录:开启" else - sudo sed -i 's/^#\?PubkeyAuthentication.*/PubkeyAuthentication no/g' /etc/ssh/sshd_config + sed -i 's/^#\?PubkeyAuthentication.*/PubkeyAuthentication no/g' /etc/ssh/sshd_config echo "密钥登录:关闭" fi - sudo systemctl restart sshd.service + systemctl restart sshd.service ;; 5) read -p "请输入需要修改的端口号(默认22): " port_number @@ -165,14 +165,14 @@ case $pick in exit fi - if sudo lsof -i :$port_number -t >/dev/null; then + if lsof -i :$port_number -t >/dev/null; then echo "$port_number 端口已被占用" exit fi - sudo sed -i "s/^#\?Port.*/Port $port_number/g" /etc/ssh/sshd_config + sed -i "s/^#\?Port.*/Port $port_number/g" /etc/ssh/sshd_config - sudo systemctl restart sshd.service + systemctl restart sshd.service echo "端口已经修改为$port_number,记得防火墙放行" ;; diff --git a/Menus/Software.sh b/Menus/Software.sh index c8b0881..c448842 100644 --- a/Menus/Software.sh +++ b/Menus/Software.sh @@ -8,15 +8,15 @@ declare pkg if [[ -f "/usr/bin/apt-get" ]];then pkg='apt-get' install_str+="${pkg} install -y" - sudo apt-get update -y + apt-get update -y elif [[ -f "/usr/bin/apt" ]];then pkg='apt' install_str+="${pkg} install -y" - sudo apt update -y + apt update -y elif [[ -f "/usr/bin/pacman" ]];then pkg='pacman' install_str+="${pkg} -Sy --noconfirm" - sudo pacman -Syu --noconfirm + pacman -Syu --noconfirm else echo "暂不支持该系统一键安装常用软件" exit @@ -92,22 +92,22 @@ if [[ ${soft_dick['docker']} == 2 ]];then fi if [[ ${pkg} == 'apt' || ${pkg} == 'apt-get' ]];then - sudo ${pkg} update - sudo ${pkg} install ca-certificates curl -y - sudo install -m 0755 -d /etc/apt/keyrings - sudo curl -fsSL "${docker_img}/linux/${version}/gpg" -o /etc/apt/keyrings/docker.asc - sudo chmod a+r /etc/apt/keyrings/docker.asc + ${pkg} update + ${pkg} install ca-certificates curl -y + install -m 0755 -d /etc/apt/keyrings + curl -fsSL "${docker_img}/linux/${version}/gpg" -o /etc/apt/keyrings/docker.asc + chmod a+r /etc/apt/keyrings/docker.asc echo \ "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] ${docker_img}/linux/${version} \ $(. /etc/os-release && echo "$VERSION_CODENAME") stable" | \ - sudo tee /etc/apt/sources.list.d/docker.list > /dev/null - sudo ${pkg} update - sudo ${pkg} install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin -y + tee /etc/apt/sources.list.d/docker.list > /dev/null + ${pkg} update + ${pkg} install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin -y elif [[ ${pkg} == 'pacman' ]];then - sudo pacman -Sy docker --noconfirm - sudo systemctl start docker.service - sudo systemctl enable docker.service - sudo usermod -aG docker $USER + pacman -Sy docker --noconfirm + systemctl start docker.service + systemctl enable docker.service + usermod -aG docker $USER newgrp docker fi fi @@ -121,8 +121,8 @@ if [[ ${soft_dick['Beautify-zsh']} == 2 ]];then git clone --depth=1 https://gitee.com/romkatv/powerlevel10k.git ${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/themes/powerlevel10k git clone https://github.com/zsh-users/zsh-syntax-highlighting.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting git clone https://github.com/zsh-users/zsh-autosuggestions ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions - sudo sed -i 's/^#\?ZSH_THEME.*/ZSH_THEME="powerlevel10k\/powerlevel10k"/g' ~/.zshrc - sudo sed -i 's/^#\?plugins.*/plugins=(zsh-syntax-highlighting zsh-autosuggestions command-not-found)/g' ~/.zshrc + sed -i 's/^#\?ZSH_THEME.*/ZSH_THEME="powerlevel10k\/powerlevel10k"/g' ~/.zshrc + sed -i 's/^#\?plugins.*/plugins=(zsh-syntax-highlighting zsh-autosuggestions command-not-found)/g' ~/.zshrc chsh -s /bin/zsh exec zsh -l fi diff --git a/Menus/Sources.sh b/Menus/Sources.sh index 1a8ad85..ce48efe 100644 --- a/Menus/Sources.sh +++ b/Menus/Sources.sh @@ -40,8 +40,8 @@ deb ${url}/debian/ bookworm main contrib non-free non-free-firmware deb ${url}/debian/ bookworm-updates main contrib non-free non-free-firmware deb ${url}/debian/ bookworm-backports main contrib non-free non-free-firmware EOF - sudo apt update -y - sudo apt-get update -y + apt update -y + apt-get update -y status=1 ;; 'bullseye') @@ -50,18 +50,18 @@ deb ${url}/debian/ bullseye main contrib non-free deb ${url}/debian/ bullseye-updates main contrib non-free deb ${url}/debian/ bullseye-backports main contrib non-free EOF - sudo apt update -y - sudo apt-get update -y + apt update -y + apt-get update -y status=1 ;; esac case "$system" in 'arch') - sudo pacman -Sy pacman-key --noconfirm + pacman -Sy pacman-key --noconfirm sed -i '/^Server.*/d' "/etc/pacman.conf" echo "Server = ${url}/archlinuxcn/\$arch" - sudo pacman-key --lsign-key "farseerfc@archlinux.org" + pacman-key --lsign-key "farseerfc@archlinux.org" pacman -Syyu status=1 ;; @@ -72,8 +72,8 @@ deb ${url}/ubuntu/ ${version}-security main restricted universe multiverse deb ${url}/ubuntu/ ${version}-updates main restricted universe multiverse deb ${url}/ubuntu/ ${version}-backports main restricted universe multiverse EOF - sudo apt update -y - sudo apt-get update -y + apt update -y + apt-get update -y status=1 ;; esac diff --git a/Run.sh b/Run.sh index 274f35a..ba5b32e 100644 --- a/Run.sh +++ b/Run.sh @@ -1,10 +1,10 @@ #!/bin/bash -if ! command -v sudo &> /dev/null; then - echo "sudo未安装,部分命令无法正常运行" +if [[ $UID != 0 ]]; then + echo "请以root权限执行该脚本" + exit fi - declare -a pick_array declare pick_number declare pick