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:
parent
0f9b879afb
commit
6159700714
@ -1,75 +0,0 @@
|
||||
## Enable color support of ls and also add handy aliases
|
||||
# Some colors
|
||||
alias ls='ls --color=auto'
|
||||
alias grep='grep --color=auto'
|
||||
|
||||
# Some utils aliases
|
||||
alias ll='ls -l'
|
||||
alias la='ls -A'
|
||||
alias rmrf='rm -rf'
|
||||
alias gcl='git clone'
|
||||
|
||||
# Aliases for executing ~/.script scripts
|
||||
alias gitan='sh ~/.script/gitan.sh'
|
||||
alias clean='sh ~/.script/clean.sh'
|
||||
|
||||
## Some export
|
||||
# colored GCC warnings and errors
|
||||
export GCC_COLORS='error=01;31:warning=01;35:note=01;36:caret=01;32:locus=01:quote=01'
|
||||
|
||||
# Set history size to unlimited
|
||||
export HISTSIZE=-1
|
||||
export HISTFILESIZE=-1
|
||||
|
||||
# For header vim
|
||||
#export VIUSER=xuser
|
||||
#export VIMAIL=xuser@xdomain.tld
|
||||
|
||||
## Activate and custom bash completion
|
||||
#bind 'TAB:menu-complete'
|
||||
#bind 'set show-all-if-ambiguous on'
|
||||
|
||||
## Setting prompt style
|
||||
# Get current branch in git repo
|
||||
function parse_git_branch() {
|
||||
BRANCH=`git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/\1/'`
|
||||
if [ ! "${BRANCH}" == "" ]
|
||||
then
|
||||
STAT=`parse_git_dirty`
|
||||
echo " [${BRANCH}${STAT}]"
|
||||
else
|
||||
echo ""
|
||||
fi
|
||||
}
|
||||
|
||||
# get current status of git repo
|
||||
function parse_git_dirty {
|
||||
status=`git status 2>&1 | tee`
|
||||
dirty=`echo -n "${status}" 2> /dev/null | grep "modified:" &> /dev/null; echo "$?"`
|
||||
untracked=`echo -n "${status}" 2> /dev/null | grep "Untracked files" &> /dev/null; echo "$?"`
|
||||
ahead=`echo -n "${status}" 2> /dev/null | grep "Your branch is ahead of" &> /dev/null; echo "$?"`
|
||||
newfile=`echo -n "${status}" 2> /dev/null | grep "new file:" &> /dev/null; echo "$?"`
|
||||
renamed=`echo -n "${status}" 2> /dev/null | grep "renamed:" &> /dev/null; echo "$?"`
|
||||
deleted=`echo -n "${status}" 2> /dev/null | grep "deleted:" &> /dev/null; echo "$?"`
|
||||
bits=''
|
||||
if [ "${renamed}" == "0" ] || [ "${newfile}" == "0" ] || [ "${untracked}" == "0" ] || [ "${dirty}" == "0" ]; then
|
||||
bits="+${bits}"
|
||||
fi
|
||||
if [ "${ahead}" == "0" ]; then
|
||||
bits="*${bits}"
|
||||
fi
|
||||
if [ "${deleted}" == "0" ]; then
|
||||
bits="-${bits}"
|
||||
fi
|
||||
if [ ! "${bits}" == "" ]
|
||||
then
|
||||
echo " ${bits}"
|
||||
else
|
||||
echo ""
|
||||
fi
|
||||
}
|
||||
|
||||
IP_LOC=`ip -4 -o addr show | grep "eth0" | cut -f7 -d' ' | cut -f1 -d'/'`
|
||||
IP_PUB=`wget -q -O - checkip.dyndns.org|sed -e 's/.*Current IP Address: //' -e 's/<.*$//'`
|
||||
|
||||
export PS1='` if [ $? = 0 ]; then echo "\[\033[01;32m\]✔"; else echo "\[\033[01;31m\]✘"; fi` \[\033[36m\]\u\[\033[00m\]@\[\033[01;36m\]$IP_LOC\[\033[32m\] \w\[\033[34m\]$(parse_git_branch " %s") \[\033[0m\]>\[\033[00m\] '
|
||||
84
install.sh
Normal file → Executable file
84
install.sh
Normal file → Executable file
@ -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 =)"
|
||||
|
||||
Loading…
Reference in New Issue
Block a user