-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup
executable file
·114 lines (93 loc) · 4.04 KB
/
setup
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
#!/usr/bin/env bash
# Setup script for installing my dotfiles. Arguments represent package
# names to install over the base "common" package(s)
# Example usage: ./setup xfce
set -o pipefail
dotfiles="$(dirname "${0/#.\//$PWD/}")"
package_names=("common" "$@")
repos=("$dotfiles")
if ! command -v tput > /dev/null; then
alias tput=:
fi
function fail {
tput setaf 1 >&2
echo "$@" >&2
tput sgr0 >&2
exit 1
}
function info {
tput bold
tput setaf 6
echo "$@"
tput sgr0
}
# Ensure path is good for installing pipsi / gardener
export PATH="$HOME/.local/bin:$PATH"
# The PyPI release of pipsi is super out of date and uses virtualenv rather
# than venv, but master is broken, so for now we use my fork.
command -v pipsi > /dev/null ||
curl https://raw.githubusercontent.com/benburrill/pipsi/master/get-pipsi.py |
python3 - --src "git+https://github.com/benburrill/pipsi.git#egg=pipsi" ||
fail "Couldn't install pipsi"
command -v gardener > /dev/null ||
pipsi install --python=python3 symlink-gardener ||
fail "Couldn't install gardener"
# In case I reorganize things
[ -x "$dotfiles/common/bin/yn" ] ||
fail "Couldn't find yn tool in dotfiles"
if "$dotfiles/common/bin/yn" -n "Install private dotfiles?"; then
command -v keybase > /dev/null ||
fail "Keybase must be installed for private dotfiles."
private_dotfiles="$(dirname "$dotfiles")/private-dotfiles"
[ -d "$private_dotfiles" ] ||
git clone keybase://private/benburrill/private-dotfiles "$private_dotfiles" ||
fail "Couldn't install private dotfiles, maybe keybase is not set up properly?"
repos+=("$private_dotfiles")
fi
packages=()
package_paths=()
for name in "${package_names[@]}"; do
name="${name%/}"
for repo in "${repos[@]}"; do
garden_name="$(basename "$repo")/$name"
if [ -d "$repo/$name" ]; then
packages+=("$garden_name:$repo/$name")
package_paths+=("$repo/$name")
fi
# This is separate from the directory check so setup scripts can
# run even if they don't come with an actual garden package.
if [ -x "$repo/$name.setup" ]; then
info "Setting up package $garden_name..."
# TODO: I think it would be nice if setup scripts could set
# dependencies. IDK the best way to do this, maybe they
# could output "dep: blah" or something. Maybe I could use
# process substitution to pass a file descriptor. Maybe I
# could export a bash function (actually I don't think that
# would work -- probably wouldn't be able to update global
# variables. Could source the setup scripts, but I don't
# really want to TBH). But in any case, I probably want to
# make the contents of this loop into a function and add
# dependencies as needed to the packages list. Also, since
# it would be annoying to have to update the package_names
# array, that should probably be created on the fly in the
# loop rather than stored as a variable to make sure it
# doesn't get misused. But also, there's the possibility of
# duplicate packages, which we'll need to be wary of. So
# I'll probably want to create a package_names array, just
# it might be different from the inputted package names.
"$repo/$name.setup" || fail "$garden_name.setup failed"
fi
done
done
info "Installing ${#packages[@]} packages..."
gardener -g "$HOME" prepare &> /dev/null ||
"$dotfiles/common/bin/yn" -n "Reset existing garden?" &&
gardener -g "$HOME" prepare --verbose --reset ||
fail "Couldn't prepare garden"
gardener -g "$HOME" plant --verbose --weeds=compost "${packages[@]}" ||
fail "Couldn't plant packages"
info "Generating $dotfiles/requires.list..."
find "${package_paths[@]}" -type f -print0 |
xargs -0 perl -nle '/~requires (.*)$/ && print $1' |
sort | uniq > "$dotfiles/requires.list" ||
fail "Couldn't generate list of requirements"