浏览代码

fix(installer): better handling of existing files (#2066)

kylo252 3 年之前
父节点
当前提交
872061e179
共有 1 个文件被更改,包括 24 次插入18 次删除
  1. 24 18
      utils/installer/install.sh

+ 24 - 18
utils/installer/install.sh

@@ -12,6 +12,8 @@ declare -r XDG_CONFIG_HOME="${XDG_CONFIG_HOME:-"$HOME/.config"}"
 
 declare -r LUNARVIM_RUNTIME_DIR="${LUNARVIM_RUNTIME_DIR:-"$XDG_DATA_HOME/lunarvim"}"
 declare -r LUNARVIM_CONFIG_DIR="${LUNARVIM_CONFIG_DIR:-"$XDG_CONFIG_HOME/lvim"}"
+declare -r LUNARVIM_BASE_DIR="${LUNARVIM_BASE_DIR:-"$LUNARVIM_RUNTIME_DIR/lvim"}"
+
 # TODO: Use a dedicated cache directory #1256
 declare -r LUNARVIM_CACHE_DIR="$XDG_CACHE_HOME/nvim"
 
@@ -109,17 +111,16 @@ function main() {
 
   verify_lvim_dirs
 
-  if [ -e "$LUNARVIM_RUNTIME_DIR/lvim/init.lua" ]; then
-    update_lvim
+  if [ "$ARGS_LOCAL" -eq 1 ]; then
+    link_local_lvim
+  elif [ -e "$LUNARVIM_BASE_DIR/init.lua" ]; then
+    validate_lunarvim_files
   else
-    if [ "$ARGS_LOCAL" -eq 1 ]; then
-      link_local_lvim
-    else
-      clone_lvim
-    fi
-    setup_lvim
+    clone_lvim
   fi
 
+  setup_lvim
+
   msg "Thank you for installing LunarVim!!"
   echo "You can start it by running: $INSTALL_PREFIX/bin/lvim"
   echo "Do not forget to use a font with glyphs (icons) support [https://github.com/ryanoasis/nerd-fonts]"
@@ -181,6 +182,15 @@ function check_neovim_min_version() {
   fi
 }
 
+function validate_lunarvim_files() {
+  local verify_version_cmd='if v:errmsg != "" | cquit | else | quit | endif'
+  if ! "$INSTALL_PREFIX/bin/lvim" --headless -c 'LvimUpdate' -c "$verify_version_cmd" &>/dev/null; then
+    msg "Removing old installation files"
+    rm -rf "$LUNARVIM_BASE_DIR"
+    clone_lvim
+  fi
+}
+
 function check_system_deps() {
   if ! command -v git &>/dev/null; then
     print_missing_dep_msg "git"
@@ -301,7 +311,7 @@ function backup_old_config() {
 function clone_lvim() {
   msg "Cloning LunarVim configuration"
   if ! git clone --branch "$LV_BRANCH" \
-    --depth 1 "https://github.com/${LV_REMOTE}" "$LUNARVIM_RUNTIME_DIR/lvim"; then
+    --depth 1 "https://github.com/${LV_REMOTE}" "$LUNARVIM_BASE_DIR"; then
     echo "Failed to clone repository. Installation failed."
     exit 1
   fi
@@ -311,13 +321,13 @@ function link_local_lvim() {
   echo "Linking local LunarVim repo"
 
   # Detect whether it's a symlink or a folder
-  if [ -d "$LUNARVIM_RUNTIME_DIR/lvim" ]; then
+  if [ -d "$LUNARVIM_BASE_DIR" ]; then
     echo "Removing old installation files"
-    rm -rf "$LUNARVIM_RUNTIME_DIR/lvim"
+    rm -rf "$LUNARVIM_BASE_DIR"
   fi
 
-  echo "   - $BASEDIR -> $LUNARVIM_RUNTIME_DIR/lvim"
-  ln -s -f "$BASEDIR" "$LUNARVIM_RUNTIME_DIR/lvim"
+  echo "   - $BASEDIR -> $LUNARVIM_BASE_DIR"
+  ln -s -f "$BASEDIR" "$LUNARVIM_BASE_DIR"
 }
 
 function setup_shim() {
@@ -356,7 +366,7 @@ function setup_lvim() {
 
   setup_shim
 
-  cp "$LUNARVIM_RUNTIME_DIR/lvim/utils/installer/config.example.lua" "$LUNARVIM_CONFIG_DIR/config.lua"
+  cp "$LUNARVIM_BASE_DIR/utils/installer/config.example.lua" "$LUNARVIM_CONFIG_DIR/config.lua"
 
   echo "Preparing Packer setup"
 
@@ -367,10 +377,6 @@ function setup_lvim() {
   echo "Packer setup complete"
 }
 
-function update_lvim() {
-  "$INSTALL_PREFIX/bin/lvim" --headless +'LvimUpdate' +q
-}
-
 function print_logo() {
   cat <<'EOF'