From 19899f3aa0cbc2626ac322897f664ee5e5c2622d Mon Sep 17 00:00:00 2001
From: root <root@zhangxuantong.ihep.ac.cn>
Date: Fri, 6 Sep 2024 10:53:35 +0800
Subject: [PATCH] add remote bootstrap

---
 .gitignore          |  1 +
 bootstrap.sh        |  4 ++--
 bootstrap_remote.sh | 13 +++++++++++++
 delete_legacy.sh    |  5 -----
 4 files changed, 16 insertions(+), 7 deletions(-)
 create mode 100755 bootstrap_remote.sh
 delete mode 100755 delete_legacy.sh

diff --git a/.gitignore b/.gitignore
index 0645745..80a2ce2 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1 +1,2 @@
 src/proxy_pwd
+src/hostlist.txt
diff --git a/bootstrap.sh b/bootstrap.sh
index 55b198b..bf9135a 100755
--- a/bootstrap.sh
+++ b/bootstrap.sh
@@ -41,12 +41,12 @@ function setVim(){
   echo -e "\e[32mConfiguring Vim...\e[0m"
   if [[ ! -f ~/.vim/autoload/plug.vim ]]; then
     wget -q -P ~/.vim/autoload/ https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
-    vim -c PlugUpdate -c PlugClean -c qa
+    vim -E -s -c PlugUpdate -c PlugClean -c qa
   else
     if [[ $(ls -l ~/.vim/autoload/plug.vim | awk '{print $5}') -eq 0 ]]; then
       wget -q -P ~/.vim/autoload/ https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
     fi
-    vim -c PlugUpgrade -c PlugUpdate -c PlugClean -c qa
+    vim -E -s -c PlugUpgrade -c PlugUpdate -c PlugClean -c qa
   fi
   yes | cp -f $PWD/src/vimrc_base ~/.env/vimrc_base &>/dev/null
   if ! grep "source ~/.env/vimrc_base" ~/.vimrc &>/dev/null; then echo -e "source ~/.env/vimrc_base" >> ~/.vimrc; fi
diff --git a/bootstrap_remote.sh b/bootstrap_remote.sh
new file mode 100755
index 0000000..db878f5
--- /dev/null
+++ b/bootstrap_remote.sh
@@ -0,0 +1,13 @@
+#!/bin/bash
+remote_command="cd ~; git -C .mysetting pull || git clone https://code.ihep.ac.cn/zhangxuantong/mysetting.git .mysetting; cd .mysetting; source bootstrap.sh git;"
+host_list="src/hostlist.txt"
+
+while IFS= read -r remote_host
+do
+  if [[ "${remote_host:0:1}" != "#" ]]; then
+    echo "Executing on $remote_host ..."
+    ssh-copy-id root@$remote_host &>/dev/null
+    ssh root@$remote_host "$remote_command"
+    echo "Finished $remote_host ..."
+  fi
+done < $host_list
diff --git a/delete_legacy.sh b/delete_legacy.sh
deleted file mode 100755
index 5eadea0..0000000
--- a/delete_legacy.sh
+++ /dev/null
@@ -1,5 +0,0 @@
-#!/bin/bash
-sed -i "/source ~\/.bashrc_mysetting/d" ~/.bashrc
-sed -i "/source ~\/.vimrc_mysetting/d" ~/.vimrc
-rm -f ~/.bashrc_mysetting
-rm -f ~/.vimrc_mysetting
\ No newline at end of file
-- 
GitLab