-
Notifications
You must be signed in to change notification settings - Fork 0
/
install.sh
executable file
·119 lines (102 loc) · 3.16 KB
/
install.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
#!/usr/bin/env bash
NO_CLOBBER=false
FORCE_CLOBBER=false
# Parse command line args
POSITIONAL=()
while [[ $# -gt 0 ]]
do
key="$1"
case $key in
-n|--no-clobber)
# Don't copy over anything
NO_CLOBBER=true
shift # past argument
;;
-f|--force)
# Clobber everything
FORCE_CLOBBER=true
shift # past argument
;;
*) # unknown option
POSITIONAL+=("$1") # save it in an array for later
shift # past argument
;;
esac
done
set -- "${POSITIONAL[@]}" # restore positional parameters
# Unofficial Strict mode
set -euo pipefail
IFS=$'\n\t'
SCRIPTPATH="$( cd "$(dirname "$0")" ; pwd -P )"
OLD_DOTFILES_DIR="$HOME/.local/opt/yf-old"
# shellcheck source=install/general_functions.sh
source "$SCRIPTPATH/install/general_functions.sh"
strip_home () {
echo -En "$@" | sed "s:^$HOME/*::"
}
move_to_old () {
if [ -e "$1" ] ; then
mkdir -p "$(dirname "$OLD_DOTFILES_DIR"/"$(strip_home "$1")")"
mv "$1" "$OLD_DOTFILES_DIR/$(strip_home "$1")"
fi
}
# First argument: file in this directory
# Second argument: destination relative to $HOME
linkFile ()
{
first="$1"
second="$HOME/$2"
if [ -e "$second" ] ; then
userInput="n"
if ! $NO_CLOBBER && ! $FORCE_CLOBBER ; then
echo "$second already exists; replace it? (Y/n):"
read -r userInput
fi
if [ ! "$userInput" = "n" ] || $FORCE_CLOBBER ; then
move_to_old "$second"
ln -sf "$first" "$second"
fi
else
ln -sf "$first" "$second"
fi
}
mkdir -p "$HOME/.local/opt"
mkdir -p "$HOME/.local/usr"
mkdir -p "$HOME/.local/bin"
try_install git
if exists git ; then
# Install scripts if not installed
yf_scripts_dir="$HOME/.local/opt/yf-scripts"
if [ ! -d "$yf_scripts_dir" ] ; then
git clone https://github.com/YourFin/Scripts.git "$yf_scripts_dir"
fi
# Install spacemacs if not installed
if [ ! -d "$HOME/.emacs.d" ] ; then
if ([ -e "$HOME/.emacs" ] || $FORCE_CLOBBER) && ! $NO_CLOBBER ; then
move_to_old "$HOME/.emacs"
fi
if ([ -e "$HOME/.emacs.d" ] || $FORCE_CLOBBER) && ! $NO_CLOBBER ; then
move_to_old "$HOME/.emacs.d"
fi
if ([ -e "$HOME/.spacemacs.d" ] || $FORCE_CLOBBER) && ! $NO_CLOBBER ; then
move_to_old "$HOME/.spacemacs.d"
fi
echo 'Installing doom...'
git clone https://github.com/hlissner/doom-emacs.git ~/.emacs.d
fi
fi
# Copy over files in .config
mkdir -p "$HOME/.config"
for file in "$SCRIPTPATH/config"/*; do
linkFile "$file" ".config/${file#"$SCRIPTPATH/config"}"
done
# Copy over files in desktop-files
DESKTOP_FILES_DIR=".local/share/applications"
mkdir -p "$HOME/$DESKTOP_FILES_DIR"
for file in "$SCRIPTPATH/desktop-files"/*; do
linkFile "$file" "$DESKTOP_FILES_DIR/${file#"$SCRIPTPATH/desktop-files"}"
done
for file in $(ls -a | grep -e '^\.[a-zA-Z0-9]' | grep -v git) ; do # all files not starting with git
linkFile "$SCRIPTPATH/$file" "$file"
done
linkFile "$SCRIPTPATH/.gitconfig" .gitconfig # As it is explicitly ignored otherwise