123 lines
3.7 KiB
Bash
123 lines
3.7 KiB
Bash
#!/usr/bin/env bash
|
|
#
|
|
# download and setup zsh, oh-my-zsh and various zsh plugins
|
|
#
|
|
# author: david@socialnerds.org
|
|
# license: MIT
|
|
# git: https://socialg.it/david/scripts.git
|
|
# version 0.1
|
|
|
|
# **** vars ****
|
|
command="$0"
|
|
root="$HOME/.dotfiles"
|
|
plugins="$root/zsh"
|
|
timestamp=$(date +"%Y%m%d%H%M")
|
|
repo="https://socialg.it/david/dotfiles.git"
|
|
dependencies="awk tee ls git wget curl rm mv sleep date"
|
|
debug=1
|
|
|
|
# **** functions ****
|
|
message() {
|
|
if [ $1 == "e" ]; then
|
|
level="\033[31m✗\033[0m"
|
|
elif [ $1 == "i" ]; then
|
|
level="\033[32m✓\033[0m"
|
|
elif [ $1 == "w" ]; then
|
|
level="\033[33m!\033[0m"
|
|
elif [ $1 == "d" ]; then
|
|
if [ $debug -eq 1 ]; then
|
|
level="\033[2md\033[0m"
|
|
else
|
|
return 0
|
|
fi
|
|
else
|
|
message e "Unknown message level[$1]."
|
|
return 1
|
|
fi
|
|
echo -e [$level] ${@:2}
|
|
sleep 0.1
|
|
}
|
|
|
|
failsafe() {
|
|
if [ $1 -ne 0 ]; then
|
|
message e "Installer died horribly!"
|
|
if [ $2 ]; then
|
|
message d "Dumping last output to stdout."
|
|
echo ${@:2}
|
|
fi
|
|
exit 1
|
|
fi
|
|
}
|
|
|
|
cleanup() {
|
|
# Get rid of preexisting data at destination
|
|
destination=$1
|
|
if [ -a "$destination.old" ]; then
|
|
message e "A previous backup exists. Move elsewhere or delete first[$destination.old]."
|
|
exit 1
|
|
else
|
|
if [ -h $destination ]; then
|
|
link=$(ls -la $destination | awk '{print $9" "$10" "$11}')
|
|
# It should be safe to just remove symbolic links because no data is actually deleted.
|
|
message d "Symbolic link exists, attempting to remove it[$link]."
|
|
output=$(rm $destination 2>&1); failsafe $? $output
|
|
message i "Removed symbolic link[$link]."
|
|
elif [ -a $destination ]; then
|
|
# Rename data to $destination.old
|
|
message d "Data exists at install destination, attempting to create a backup[$destination.old]."
|
|
output="", output=$(mv $destination $destination.old 2>&1); failsafe $? $output
|
|
message i "Created a backup of a preexisting data[$destination.old]."
|
|
fi
|
|
fi
|
|
}
|
|
|
|
|
|
# **** start of script ****
|
|
|
|
message d "Warming up installer."
|
|
#message d "Initiating preflight checks."
|
|
|
|
|
|
# check dependencies, fail with a list of missing
|
|
|
|
# can i write to ~ and ~/.oh-my-zsh
|
|
|
|
# remove everything in 5 seconds: ~/.dotfiles ~/.dotfiles.old ~/.myzsh ~/.oh-my-zsh ~/.zshrc
|
|
message w "your old configs will be deleted in 5 seconds [terminate deletion with Ctrl-C]"
|
|
sleep 5
|
|
rm -rf $HOME/.dotfiles
|
|
rm -rf $HOME/.dotfiles.old
|
|
rm -rf $HOME/.myzsh
|
|
rm -rf $HOME/.oh-my-zsh
|
|
rm $HOME/.zshrc
|
|
rm $HOME/.zshrc.pre-oh-my-zsh
|
|
|
|
# invoke oh-my-zh installer
|
|
curl -fsSL https://raw.github.com/robbyrussell/oh-my-zsh/master/tools/install.sh | bash
|
|
message i "oh-my-zsh installed"
|
|
|
|
# set $ZSH_THEME="" in .zshrc
|
|
cat $HOME/.zshrc | sed "s/^ZSH_THEME=\"robbyrussell\"/ZSH_THEME=\"\"/g" > $HOME/.zshrc
|
|
message i "oh-my-zsh theme deactivated"
|
|
|
|
# clone plugins
|
|
cd $HOME/.oh-my-zsh/custom/plugins/ > /dev/null
|
|
git clone https://github.com/sindresorhus/pure.git pure
|
|
git clone https://github.com/mafredri/zsh-async.git async
|
|
git clone https://socialg.it/david/zsh-david.git zsh-david
|
|
git clone https://github.com/zsh-users/zsh-syntax-highlighting.git zsh-syntax-highlighting
|
|
git clone https://github.com/skx/sysadmin-util.git sysadmin-util
|
|
git clone https://github.com/TamCore/autoupdate-oh-my-zsh-plugins.git autoupdate
|
|
git clone https://github.com/zsh-users/zsh-autosuggestions.git zsh-autosuggestions
|
|
cd - > /dev/null
|
|
message i "all plugins cloned"
|
|
|
|
# set $plugins in .zshrc
|
|
plugins="git zsh-autosuggestions autoupdate sysadmin-util zsh-syntax-highlighting zsh-david async pure"
|
|
cat $HOME/.zshrc | sed "/plugins=(/,/)/d; s/source \$ZSH\/oh-my-zsh.sh/plugins=($plugins);; source \$ZSH\/oh-my-zsh.sh/g" | sed $'s/;; /\\\n/g' > $HOME/.zshrc
|
|
message i "activated zsh plugins [$plugins]"
|
|
|
|
message d "Installer finished."
|
|
|
|
# **** end of script ****
|