forked from nmandery/dotfiles
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall.sh
executable file
·60 lines (49 loc) · 1.56 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
#!/bin/bash
set -e
SCRIPT_DIR=$(dirname $0)
pushd "$SCRIPT_DIR" >/dev/null
SCRIPT_DIR=$(pwd)
for SFILE in $(ls -1 "./" | grep '^_'); do
TARGET_FILE=$(echo "$SFILE" | sed 's/^_/./g')
TARGET_FULL="$HOME/$TARGET_FILE"
echo "$SFILE"
if [ -L "$TARGET_FULL" ]; then
rm "$TARGET_FULL"
fi
if [ -e "$TARGET_FULL" ]; then
echo "$HOME/$TARGET_FILE exits. creating a backup"
mv "$HOME/$TARGET_FILE" "$HOME/$TARGET_FILE.backup"
fi
ln -s "$PWD/$SFILE" "$TARGET_FULL"
done
# add own bashrc to the existing ~/.bashrc + delete existing
# bashrc_nmandery inclusion
[ -f ~/.bashrc ] || touch ~/.bashrc
sed -i '/dotfiles nmandery start/,/dotfiles nmandery end/d' ~/.bashrc
cat >>~/.bashrc <<EOF
# dotfiles nmandery start
[ -f ~/.bashrc_nmandery ] && . ~/.bashrc_nmandery
# dotfiles nmandery end
EOF
# add own zshrc to the existing ~/.zshrc + delete existing
# zshrc_nmandery inclusion
[ -f ~/.zshrc ] || touch ~/.zshrc
sed -i '/dotfiles nmandery start/,/dotfiles nmandery end/d' ~/.zshrc
cat >>~/.zshrc <<EOF
# dotfiles nmandery start
[ -f ~/.zshrc_nmandery ] && . ~/.zshrc_nmandery
# dotfiles nmandery end
EOF
# add binaries
BINDIR=~/bin
[ -d "$BINDIR" ] || mkdir "$BINDIR"
for BINFILE in $(find "$SCRIPT_DIR/bin" -executable -type f); do
BINBASENAME=$(basename "$BINFILE")
if [ ! -f "$BINDIR/$BINBASENAME" ]; then
echo "linking executable $BINBASENAME to $BINDIR."
ln -s "$BINFILE" "$BINDIR/$BINBASENAME"
else
echo "executable $BINBASENAME is already linked to $BINDIR. skipping."
fi
done
popd >/dev/null