forked from holman/dotfiles
-
Notifications
You must be signed in to change notification settings - Fork 1
/
install
executable file
·117 lines (102 loc) · 3.37 KB
/
install
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
#!/usr/bin/env bash
# Change working directory to script directory
cd "$(dirname "$0")"
if [ "$(pwd)" != "$HOME/.dotfiles" ] ; then
echo "Cowardly refusing to proceed as the install script is not running from $HOME/.dotfiles."
exit 1
fi
declare -A targets
if [ "$1" != "--uninstall" ] ; then
# Install packages, if needed
if command -v pacman &> /dev/null ; then
# Arch/Manjaro
packages="sudo git zsh curl xz ripgrep tmux broot helix wl-clipboard xsel fzf eza"
if ! pacman -Q $packages &>/dev/null; then
sudo pacman -S --needed $packages
fi
elif command -v apt &> /dev/null ; then
# Debian/Ubuntu
packages="git curl xz-utils ripgrep zsh wl-clipboard xsel tmux fuse fzf eza"
if dpkg-query -Wf'${db:Status-abbrev}\n' $packages 2>&1 | grep -vq "^ii" ; then
sudo apt install $packages
fi
if [ ! -e "xbin/broot" ] ; then
wget -nv "https://dystroy.org/broot/download/x86_64-unknown-linux-musl/broot" -O "xbin/broot" && chmod a+x "xbin/broot"
fi
if [ ! -e "xbin/hx" ] ; then
wget "https://github.com/zydou/helix/releases/download/v24.03/helix-v24.03-x86_64-unknown-linux-gnu.tar.xz" -O - | tar xvJ --directory=xbin --strip-components=1
chmod a+x bin/hx
fi
elif command -v nix-env &> /dev/null ; then
for pkg in tmux broot fzf ripgrep xz helix zsh curl xsel python3 eza ; do
if ! (nix-env -q $pkg >/dev/null 2>&1 || command -v $pkg >/dev/null 2>&1); then
nix-env -iA -f '<nixpkgs>' $pkg
fi
done
elif command -v dnf &> /dev/null ; then
for package in git zsh curl xz ripgrep tmux helix xsel fzf eza ; do
if ! dnf list installed "$package" &>/dev/null; then
sudo dnf install -y "$package"
fi
done
else
# Bluefin? OSX?
for a in git zsh curl xz ripgrep:rg tmux broot helix:hx xsel fzf ; do
cmd="${a##*:}"
pkg="${a%%:*}"
command -v "$cmd" > /dev/null || echo "$pkg"
done | HOMEBREW_NO_ENV_HINTS=1 xargs -r brew install
fi
# Set the ssh-git URL for this repo, to allow pushing changes
git remote set-url --push origin [email protected]:vanviegen/dotfiles.git
# Create symlinks
linkables=(*/**.symlink)
skip_all=false
overwrite_all=false
backup_all=false
for linkable in "${linkables[@]}"; do
overwrite=false
backup=false
target=".$(basename "${linkable%.symlink}" | sed 's/__/\//g')"
target="$HOME/$target"
targets["$target"]=true
linkable="$(realpath "$(pwd)/$linkable")"
if [ -e "$target" ] || [ -L "$target" ]; then
if [ -L "$target" ] && [ "$(readlink "$target")" = "$linkable" ]; then
continue
fi
if ! "$skip_all" && ! "$overwrite_all" && ! "$backup_all"; then
read -p "File already exists: $target, what do you want to do? [s]kip, [S]kip all, [o]verwrite, [O]verwrite all, [b]ackup, [B]ackup all >> " choice
case "$choice" in
o) overwrite=true;;
b) backup=true;;
O) overwrite_all=true;;
B) backup_all=true;;
S) skip_all=true;;
s) continue;;
esac
fi
if "$overwrite" || "$overwrite_all"; then
rm -rf "$target"
fi
if "$backup" || "$backup_all"; then
mv "$target" "$target.backup"
fi
else
mkdir -p "$(dirname "$target")"
fi
echo "linking $target"
ln -s "$linkable" "$target"
done
chmod -R a+rX .
chmod a+x,o-r ..
fi
for file in "$HOME/".* "$HOME/".*/**; do
if [ -L "$file" ]; then
link="$(readlink "$file")"
if [[ "$link" == "$(pwd)/"* ]] && [ ! "${targets[$file]}" ]; then
echo "unlinking $file"
rm "$file"
fi
fi
done