refactor(install): auto-detect OS, drop target arg, harden script
Rework install.sh:
- detect OS via uname (Darwin -> bashrc-osx, else bashrc-linux);
remove the {server|linux|arm|osx} argument and bashrc-server
- fix broken /tmp/config paths that made server+osx install no bashrc
- switch #!/bin/sh -> bash, add set -euo pipefail, quote expansions
- clone nerdtree into bundle (was a no-op cp of a dir), drop the
redundant molokai clone (already tracked in vim/colors)
- guard apt-get behind command -v so macOS skips it
- make re-runnable; drop the no-op trailing 'source ~/.bashrc'
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.7
parent
0f9b879afb
commit
6159700714
Regular → Executable
+46
-38
@@ -1,47 +1,55 @@
|
||||
#!/bin/sh
|
||||
#!/usr/bin/env bash
|
||||
# install.sh — deploy the vim + bash dotfiles. OS is auto-detected.
|
||||
# Usage: ./install.sh
|
||||
set -euo pipefail
|
||||
|
||||
if [ -z $1 ]; then
|
||||
echo "Usage: $0 {server|linux|arm|osx}"
|
||||
exit 1
|
||||
# Resolve the repo root so the script works from any working directory.
|
||||
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
|
||||
|
||||
# System packages: Debian/Ubuntu only. Skipped where apt-get is absent (e.g. macOS).
|
||||
if command -v apt-get >/dev/null 2>&1; then
|
||||
sudo apt-get update
|
||||
sudo apt-get upgrade -y
|
||||
sudo apt-get install -y vim git gcc make pkg-config unzip dkms git-lfs
|
||||
else
|
||||
echo "apt-get not found — skipping system packages (install vim/git manually)."
|
||||
fi
|
||||
|
||||
sudo apt-get update && sudo apt-get upgrade -y && sudo apt-get install -y vim git gcc make pkg-config unzip dkms git-lfs
|
||||
# Back up any existing config before overwriting (re-runnable).
|
||||
echo "Backing up existing config to ~/Oldconfig"
|
||||
rm -rf "$HOME/Oldconfig"
|
||||
mkdir -p "$HOME/Oldconfig"
|
||||
for cfg in .vim .Sublivim .vimrc .bashrc; do
|
||||
if [ -e "$HOME/$cfg" ]; then
|
||||
mv "$HOME/$cfg" "$HOME/Oldconfig/"
|
||||
fi
|
||||
done
|
||||
|
||||
echo "Save older config in ~/Oldconfig ( with '.' like \".vimrc\" )"
|
||||
rm -rf $HOME/Oldconfig 2>&-
|
||||
mkdir -p $HOME/Oldconfig
|
||||
mv $HOME/.vim $HOME/Oldconfig 2>&-
|
||||
mv $HOME/.Sublivim $HOME/Oldconfig 2>&-
|
||||
mv $HOME/.vimrc $HOME/Oldconfig 2>&-
|
||||
mv $HOME/.bashrc $HOME/Oldconfig 2>&-
|
||||
# Recreate the vim directory layout.
|
||||
echo "Creating vim directory structure"
|
||||
mkdir -p "$HOME"/.vim/{autoload,colors,syntax,plugin,spell,config,bundle}
|
||||
|
||||
echo "Create new vim architecture"
|
||||
mkdir -p $HOME/.vim/autoload $HOME/.vim/colors $HOME/.vim/syntax $HOME/.vim/plugin $HOME/.vim/spell $HOME/.vim/config $HOME/.vim/bundle
|
||||
# Fetch external vim plugins (rm first so re-runs do not fail on existing clones).
|
||||
echo "Cloning vim plugins"
|
||||
rm -rf "$HOME/.vim/bundle/syntastic"
|
||||
git clone --quiet https://github.com/vim-syntastic/syntastic "$HOME/.vim/bundle/syntastic"
|
||||
rm -rf "$HOME/.vim/bundle/nerdtree"
|
||||
git clone --quiet https://github.com/preservim/nerdtree "$HOME/.vim/bundle/nerdtree"
|
||||
|
||||
echo "Cloning some git repositories"
|
||||
#git clone --quiet https://github.com/tpope/vim-pathogen $HOME/.vim/pathogen
|
||||
git clone --quiet https://github.com/vim-syntastic/syntastic $HOME/.vim/bundle/syntastic
|
||||
git clone --quiet https://github.com/tomasr/molokai /tmp/molokai
|
||||
git clone --quiet https://github.com/preservim/nerdtree /tmp/nerdtree
|
||||
# Deploy tracked vim files: vimrc, pathogen loader, molokai colorscheme.
|
||||
echo "Deploying vim config"
|
||||
cp -rupv "$SCRIPT_DIR"/vim/* "$HOME/.vim/"
|
||||
ln -sf "$HOME/.vim/vimrc" "$HOME/.vimrc"
|
||||
|
||||
echo "Building new vim"
|
||||
cp -rupv ./vim/* $HOME/.vim
|
||||
#ln -s $HOME/.vim/pathogen/autoload/pathogen.vim $HOME/.vim/autoload/pathogen.vim
|
||||
cp /tmp/molokai/colors/molokai.vim $HOME/.vim/colors
|
||||
cp /tmp/nerdtree $HOME/.vim/bundle/
|
||||
ln -s $HOME/.vim/vimrc $HOME/.vimrc
|
||||
|
||||
if [ "$1" == "server" ]; then
|
||||
cp /tmp/config/bash/bashrc-server $HOME/.bashrc
|
||||
elif [ "$1" == "linux" -o "$1" == "arm" ]; then
|
||||
cp bash/bashrc-linux $HOME/.bashrc
|
||||
elif [ "$1" == "osx" ]; then
|
||||
cp /tmp/config/bash/bashrc-osx $HOME/.bashrc
|
||||
# Deploy the bashrc matching the detected OS.
|
||||
# macOS uses bashrc-osx (falling back to bashrc-linux if absent); everything else uses bashrc-linux.
|
||||
if [ "$(uname -s)" = "Darwin" ] && [ -f "$SCRIPT_DIR/bash/bashrc-osx" ]; then
|
||||
bashrc="bash/bashrc-osx"
|
||||
else
|
||||
bashrc="bash/bashrc-linux"
|
||||
fi
|
||||
echo "Deploying $bashrc"
|
||||
cp "$SCRIPT_DIR/$bashrc" "$HOME/.bashrc"
|
||||
|
||||
echo "Deleting temporary files"
|
||||
rm -rf /tmp/molokai
|
||||
|
||||
source $HOME/.bashrc
|
||||
echo "Ïf you are running zsh, please change for bash =)"
|
||||
echo "Enjoy !"
|
||||
echo "Done. Restart your shell or run: source ~/.bashrc"
|
||||
echo "If you use zsh, switch to bash to enjoy these settings =)"
|
||||
|
||||
Reference in New Issue
Block a user