-
Notifications
You must be signed in to change notification settings - Fork 0
/
install
executable file
·84 lines (76 loc) · 2.44 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
#!/usr/bin/env bash
#
# A script for bootstrapping my dotfiles installation.
# On early stages.
#
# Bashisms: arrays.
PROG=$(basename $0)
exists() {
command -v "$1" >/dev/null 2>/dev/null;
}
usage() {
printf >&2 "%s: %s\n" "$PROG" "installs dotfiles" # terrible description
printf >&2 "Usage: %s\n" "$PROG <ACTION> <DEST>"
printf >&2 "Where\n"
printf >&2 " ACTION : the action to be done.\n"
printf >&2 " | https: clone to DEST via HTTPS\n"
printf >&2 " | https-shallow: clone to DEST via HTTPS with --depth 1\n"
printf >&2 " | ssh: clone to DEST via SSH\n"
printf >&2 " | https-to-ssh: clone to (already existing, but https-based) DEST via SSH (thus converting it to SSH)\n"
printf >&2 " DEST : the path where the dotfiles will be installed."
exit 1
}
[ $# != 2 ] && usage
case "$1" in
https|https-shallow) DOTFILES_URL="https://github.com/YohananDiamond/dotfiles" ;;
ssh|https-to-ssh) DOTFILES_URL="[email protected]:yohanandiamond/dotfiles" ;;
*)
printf >&2 "Invalid ACTION: %s\n" "$1"
printf >&2 "\n"
usage
;;
esac
if [ "$1" != https-to-ssh ] && [ -e "$2" ]; then
printf >&2 "DEST %s already exists. Please delete it or choose another path.\n" "$2"
exit 1
fi
# TODO: get the similar thing from LARBS or something and put it here instead
for dependency in git python3; do
if ! exists "$dependency"; then
printf >&2 "Could not find %s in PATH - attempting to install it...\n" "$dependency"
if exists pacman; then
sudo pacman -Syy "$dependency"
elif exists apt; then
sudo apt install "$dependency"
elif exists apt-get; then
sudo apt-get install "$dependency"
else
printf >&2 "Could not find your package manager. Please install said dependency manually.\n"
exit 1
fi
fi
done
case "$1" in
https-to-ssh)
if [ ! -d "$2" ]; then
printf >&2 "%s is not a directory.\n" "$2"
exit 1
fi
temp=$(mktemp) \
&& rm -f "$temp" \
&& mv "$2" "$temp" || exit 1
if git clone "$DOTFILES_URL" "$2"; then
rm -rf "$temp"
else
mv "$temp" "$2"
fi
;;
*)
[ "$1" = https-shallow ] && shallow=(--depth 1) || shallow=()
git clone "${shallow[@]}" "$DOTFILES_URL" "$2" \
&& mkdir -p ~/.local/share/dots \
&& echo "$(realpath -m "$2")" > ~/.local/share/dots/dotpath \
&& echo "gruvbox-dark-medium" > ~/.local/share/dots/theme \
&& DOTFILES="$2" "$2/scripts/sysm"
;;
esac