From 4d7a9cbe0e99239399833ca3950a1f0281958084 Mon Sep 17 00:00:00 2001 From: qiansong <2744588786@qq.com> Date: Sun, 24 Sep 2023 02:25:26 +0800 Subject: [PATCH] =?UTF-8?q?=E8=87=AA=E5=8A=A8=E7=BC=A9=E8=BF=9B=E4=B8=8Eta?= =?UTF-8?q?b=E9=94=AE=EF=BC=8C=E4=B8=8D=E5=86=8D=E5=B1=95=E5=BC=80?= =?UTF-8?q?=E4=B8=BA=E7=A9=BA=E6=A0=BC=E5=A1=AB=E5=85=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- install.sh | 328 ++++++++++++++++++++++++++--------------------------- 1 file changed, 164 insertions(+), 164 deletions(-) diff --git a/install.sh b/install.sh index af0bfc1..2d710c9 100644 --- a/install.sh +++ b/install.sh @@ -17,221 +17,221 @@ nvim_install_dir="${HOME}/.soft" # source os-release fiele if [[ -f /etc/os-release ]]; then - . /etc/os-release + . /etc/os-release fi function create_dir () { - # create nvim config dir - if [[ ! -d ${nvim_config_dir} ]]; then - mkdir -p ${nvim_config_dir} - fi - - # create nvim plugin dir - if [[ ! -d ${nvim_plugin_dir} ]]; then - mkdir -p ${nvim_plugin_dir} - fi - - # create nvim insatll dir - if [[ ! -d ${nvim_install_dir} ]]; then - mkdir -p ${nvim_install_dir} - fi + # create nvim config dir + if [[ ! -d ${nvim_config_dir} ]]; then + mkdir -p ${nvim_config_dir} + fi + + # create nvim plugin dir + if [[ ! -d ${nvim_plugin_dir} ]]; then + mkdir -p ${nvim_plugin_dir} + fi + + # create nvim insatll dir + if [[ ! -d ${nvim_install_dir} ]]; then + mkdir -p ${nvim_install_dir} + fi } # un tar file in to dir function un_tar_file () { - # untar nvim_install file - if [[ -d ${nvim_install_dir}/nvim-linux64 ]]; then - rm -rf ${nvim_install_dir}/nvim-linux64 >/dev/null 2>&1 - cd ${work_dir} - echo -e "\033[1;33mUntaring neovim installeler package....\033[1;32mOK\033[0m" - tar -xf nvim-installer.tar.gz -C ${nvim_install_dir} - else - cd ${work_dir} - echo -e "\033[1;33mUntaring neovim installeler package....\033[1;32mOK\033[0m" - tar -xf nvim-installer.tar.gz -C ${nvim_install_dir} - fi - echo " " - sleep 1 - - # untar nvim_config file - if [[ -d ${nvim_config_dir}/nvim ]]; then - mv ${nvim_config_dir}/nvim ${nvim_config_dir}/nvim.bak$(date +"%F_%H%M%S") - cd ${work_dir} - echo -e "\033[1;33mUntaring neovim config file....\033[1;32mOK\033[0m" - tar -xf nvim-config.tar.gz -C ${nvim_config_dir} - else - cd ${work_dir} - echo -e "\033[1;33mUntaring neovim config file....\033[1;32mOK\033[0m" - tar -xf nvim-config.tar.gz -C ${nvim_config_dir} - fi - echo " " - sleep 1 - - # untar nvim_plugin file - if [[ -d ${nvim_plugin_dir}/nvim ]]; then - mv ${nvim_plugin_dir}/nvim ${nvim_plugin_dir}/nvim.bak$(date +"%F_%H%M%S") - cd ${work_dir} - echo -e "\033[1;33mUntaring neovim plugin file....\033[1;32mOK\033[0m" - tar -xf nvim-plugin.tar.gz -C ${nvim_plugin_dir} - else - cd ${work_dir} - echo -e "\033[1;33mUntaring neovim plugin file....\033[1;32mOK\033[0m" - tar -xf nvim-plugin.tar.gz -C ${nvim_plugin_dir} - fi - echo " " - sleep 1 + # untar nvim_install file + if [[ -d ${nvim_install_dir}/nvim-linux64 ]]; then + rm -rf ${nvim_install_dir}/nvim-linux64 >/dev/null 2>&1 + cd ${work_dir} + echo -e "\033[1;33mUntaring neovim installeler package....\033[1;32mOK\033[0m" + tar -xf nvim-installer.tar.gz -C ${nvim_install_dir} + else + cd ${work_dir} + echo -e "\033[1;33mUntaring neovim installeler package....\033[1;32mOK\033[0m" + tar -xf nvim-installer.tar.gz -C ${nvim_install_dir} + fi + echo " " + sleep 1 + + # untar nvim_config file + if [[ -d ${nvim_config_dir}/nvim ]]; then + mv ${nvim_config_dir}/nvim ${nvim_config_dir}/nvim.bak$(date +"%F_%H%M%S") + cd ${work_dir} + echo -e "\033[1;33mUntaring neovim config file....\033[1;32mOK\033[0m" + tar -xf nvim-config.tar.gz -C ${nvim_config_dir} + else + cd ${work_dir} + echo -e "\033[1;33mUntaring neovim config file....\033[1;32mOK\033[0m" + tar -xf nvim-config.tar.gz -C ${nvim_config_dir} + fi + echo " " + sleep 1 + + # untar nvim_plugin file + if [[ -d ${nvim_plugin_dir}/nvim ]]; then + mv ${nvim_plugin_dir}/nvim ${nvim_plugin_dir}/nvim.bak$(date +"%F_%H%M%S") + cd ${work_dir} + echo -e "\033[1;33mUntaring neovim plugin file....\033[1;32mOK\033[0m" + tar -xf nvim-plugin.tar.gz -C ${nvim_plugin_dir} + else + cd ${work_dir} + echo -e "\033[1;33mUntaring neovim plugin file....\033[1;32mOK\033[0m" + tar -xf nvim-plugin.tar.gz -C ${nvim_plugin_dir} + fi + echo " " + sleep 1 } # define shell env fire VAR function define_shell_env_file () { - shell_type=$(echo ${SHELL}|awk -F '/' '{print $NF}') - case "${shell_type}" in - "zsh") - env_file="${HOME}/.zshrc" - ;; - "bash"|"sh") - env_file="${HOME}/.bashrc" - ;; - *) - echo -e "\033[1;31mError for set env file type. Exitting.....\033[0m" - exit 1 - ;; - esac + shell_type=$(echo ${SHELL}|awk -F '/' '{print $NF}') + case "${shell_type}" in + "zsh") + env_file="${HOME}/.zshrc" + ;; + "bash"|"sh") + env_file="${HOME}/.bashrc" + ;; + *) + echo -e "\033[1;31mError for set env file type. Exitting.....\033[0m" + exit 1 + ;; + esac } # install nvim function install_nvim () { - create_dir - un_tar_file - define_shell_env_file - sed -ri '/# config neovim PATH/d' "${env_file}" - sed -ri '/n(.*)vim(.*)\/bin/d' "${env_file}" - echo '# config neovim PATH' >> "${env_file}" - echo "export PATH=\"${nvim_install_dir}/nvim-linux64/bin:\$PATH\"" >> "${env_file}" - export PATH="${nvim_install_dir}/nvim-linux64/bin:$PATH" - sleep 1 - echo -e "\033[1;32mInsatll sucessfully.You can run \033[34mexec ${shell_type} && nvim\033[0m \033[1;32mto start editer!!!\033[0m" - exit + create_dir + un_tar_file + define_shell_env_file + sed -ri '/# config neovim PATH/d' "${env_file}" + sed -ri '/n(.*)vim(.*)\/bin/d' "${env_file}" + echo '# config neovim PATH' >> "${env_file}" + echo "export PATH=\"${nvim_install_dir}/nvim-linux64/bin:\$PATH\"" >> "${env_file}" + export PATH="${nvim_install_dir}/nvim-linux64/bin:$PATH" + sleep 1 + echo -e "\033[1;32mInsatll sucessfully.You can run \033[34mexec ${shell_type} && nvim\033[0m \033[1;32mto start editer!!!\033[0m" + exit } # print excuting msg function print_excuting_msg () { - message=$1 - local cahr_1="${message}." - local cahr_2="${message}.." - local cahr_3="${message}..." - local cahr_4="${message}...." - local cahr_5="${message}....." + message=$1 + local cahr_1="${message}." + local cahr_2="${message}.." + local cahr_3="${message}..." + local cahr_4="${message}...." + local cahr_5="${message}....." i=1 - while [[ $i -le 5 ]]; do - r_char="\$cahr_${i}" - msg=$(eval "echo -e \"${r_char}\"") - echo -ne "\033[?25l${msg}\033[0m" - echo -ne "\r\r" + while [[ $i -le 5 ]]; do + r_char="\$cahr_${i}" + msg=$(eval "echo -e \"${r_char}\"") + echo -ne "\033[?25l${msg}\033[0m" + echo -ne "\r\r" let i++ - sleep 0.3 - done - echo -e "\033[?25h\033[0m" - echo -e "\033[2A\033[0m" + sleep 0.3 + done + echo -e "\033[?25h\033[0m" + echo -e "\033[2A\033[0m" } # uninstall nvim function uninstall_nvim () { - if [[ -d ${nvim_install_dir}/nvim-linux64 ]]; then - print_excuting_msg "Uninstalling" - echo -e "\033[1;31mUninstalling.....\033[32mOK\033[0m" - rm -rf ${nvim_install_dir}/nvim-linux64 >/dev/null 2>&1 - rm -rf ${nvim_config_dir}/nvim* >/dev/null 2>&1 - rm -rf ${nvim_plugin_dir}/nvim* >/dev/null 2>&1 - rm -rf ${HOME}/.cache/nvim* >/dev/null 2>&1 - rm -rf ${HOME}/.local/state/nvim* >/dev/null 2>&1 - exit - else - echo -e "\033[1;33mIt seems you have not install neovim yet, do you want to install?\033[0m [y/N]" - read -p "> " you_zl - while true - do - case ${you_zl} in - y|yes|Y) - install_nvim - ;; - n|no|N) - echo -e "\033[34mGood Bye!!!\033[0m" - print_excuting_msg "Quiting" - exit - ;; - *) - echo -e "\033[1;33mIt seems you have not install neovim yet, do you want to install?\033[0m [y/N]" - read -p "> " you_zl - ;; - esac - done - fi + if [[ -d ${nvim_install_dir}/nvim-linux64 ]]; then + print_excuting_msg "Uninstalling" + echo -e "\033[1;31mUninstalling.....\033[32mOK\033[0m" + rm -rf ${nvim_install_dir}/nvim-linux64 >/dev/null 2>&1 + rm -rf ${nvim_config_dir}/nvim* >/dev/null 2>&1 + rm -rf ${nvim_plugin_dir}/nvim* >/dev/null 2>&1 + rm -rf ${HOME}/.cache/nvim* >/dev/null 2>&1 + rm -rf ${HOME}/.local/state/nvim* >/dev/null 2>&1 + exit + else + echo -e "\033[1;33mIt seems you have not install neovim yet, do you want to install?\033[0m [y/N]" + read -p "> " you_zl + while true + do + case ${you_zl} in + y|yes|Y) + install_nvim + ;; + n|no|N) + echo -e "\033[34mGood Bye!!!\033[0m" + print_excuting_msg "Quiting" + exit + ;; + *) + echo -e "\033[1;33mIt seems you have not install neovim yet, do you want to install?\033[0m [y/N]" + read -p "> " you_zl + ;; + esac + done + fi } # menu function select_menu () { - echo -e "\033[33mPlease selsct one option to work\033[0m" - echo '---------' - echo -e "\033[1;33m1.\033[0m Install neovim" - echo -e "\033[1;33m2.\033[0m UnInstall neovim" - echo '---------' - echo - read -p "> " you_zl + echo -e "\033[33mPlease selsct one option to work\033[0m" + echo '---------' + echo -e "\033[1;33m1.\033[0m Install neovim" + echo -e "\033[1;33m2.\033[0m UnInstall neovim" + echo '---------' + echo + read -p "> " you_zl } # select install or uninstall_nvim function select_option () { - clear - select_menu - case "${you_zl}" in - 1) - install_nvim - ;; - 2) - uninstall_nvim - ;; - *) - select_option - ;; - esac + clear + select_menu + case "${you_zl}" in + 1) + install_nvim + ;; + 2) + uninstall_nvim + ;; + *) + select_option + ;; + esac } # exit SIG capture function exit_shell () { - echo - echo -e "\033[31m\033[1mAre you sure want exit now? [y/N]:\033[0m " - echo -n "> " - read you_zl - case ${you_zl} in - y|Y|yes) - echo -e "\033[34mGood Bye!!!\033[0m" - print_excuting_msg "Quiting" - exit - ;; - n|N|no) - select_option - ;; - *) - exit_shell - ;; - esac + echo + echo -e "\033[31m\033[1mAre you sure want exit now? [y/N]:\033[0m " + echo -n "> " + read you_zl + case ${you_zl} in + y|Y|yes) + echo -e "\033[34mGood Bye!!!\033[0m" + print_excuting_msg "Quiting" + exit + ;; + n|N|no) + select_option + ;; + *) + exit_shell + ;; + esac } # 捕获目标信号执行对应操作函数exit_shell for i in HUP INT QUIT TSTP do - trap_cmd="trap \"exit_shell\" ${i}" - eval "${trap_cmd}" + trap_cmd="trap \"exit_shell\" ${i}" + eval "${trap_cmd}" done select_option