-
Notifications
You must be signed in to change notification settings - Fork 6
/
install
executable file
·181 lines (163 loc) · 4.84 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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
#!/usr/bin/env bash
set -u
# script to setup HPI
# - installs karlicoss/HPI as an editable namespace package,
# - installs this repo
# - installs additional python packages for modules
# - checks for any required external commands
# - sets up directory structure in ~/data
# cd to this directory
BASE_DIR="$(realpath "$(dirname "${BASH_SOURCE[0]}")")" || exit $?
readonly BASE_DIR
cd "${BASE_DIR}" || exit 1
# function to verify an external command is installed
havecmd() {
local BINARY ERRMSG script_name
script_name='HPI'
# error if first argument isn't provided
BINARY="${1:?Must provide command to check}"
# the commend exists, exit with 0 (success!)
if command -v "${BINARY}" >/dev/null 2>&1; then
return 0
else
# construct error message
ERRMSG="'${script_name}' requires '${BINARY}', could not find that on your \$PATH"
if [[ -n "$2" ]]; then
ERRMSG="$ERRMSG. $2"
fi
printf '%s\n' "$ERRMSG" 1>&2
return 1
fi
}
clone_if_not_exists() {
if [[ ! -d "$2" ]]; then
git clone "$1" "$2" || return $?
fi
}
setup_fork() {
local FORK_ABBREV FORK_URL UPSTREAM_URL FORK_TARGET
echo 'Setting up upstream fork...'
# the name of my fork close to karlicoss/HPI, since HPI is this repo
FORK_ABBREV='HPI-to-master'
UPSTREAM_URL='https://github.com/karlicoss/HPI'
FORK_URL="https://github.com/seanbreckenridge/${FORK_ABBREV}"
FORK_TARGET="$(realpath "../${FORK_ABBREV}")"
# clone my fork one level up from here if it doesnt exist
if [[ ! -e "${FORK_TARGET}" ]]; then
git clone "${FORK_URL}" "${FORK_TARGET}"
cd "${FORK_TARGET}"
git remote add upstream "${UPSTREAM_URL}"
else
echo "Path already exists, skipping clone..."
fi
cd "${FORK_TARGET}"
python3 -m pip install -e '.[optional,testing]'
# cd back to here, to pip install this
cd "${BASE_DIR}" || return $?
python3 -m pip install -e '.'
# TODO: ensure easy-install.path is ordered right?
}
setup_ghexport() {
local URL TARGET
# temporary (hopefully?) patch to use httpx instead of requirements
echo 'Setting up ghexport...'
URL='https://github.com/seanbreckenridge/ghexport'
TARGET="${REPOS:?Repos environment variable is not set}/ghexport"
python3 -m pip install httpx
clone_if_not_exists "$URL" "$TARGET"
cd "$TARGET" || return $?
git submodule update --init
python3 -m pip install --user .
}
module_dependencies() {
(setup_ghexport) || return $?
hpi module install --user my.reddit
hpi module install --user my.pdfs
hpi module install --user my.window_watcher
hpi module install --user my.discord
hpi module install --user my.body
hpi module install --user my.google
hpi module install --user my.time.tz.via_location
hpi module install --user my.coding.commits
hpi module install --user my.todotxt
hpi module install --user my.reddit
hpi module install --user my.location.ip
hpi module install --user my.location.gpslogger
hpi module install --user my.chess
hpi module install --user my.mpv
hpi module install --user my.league
hpi module install --user my.trakt
# other requirements needed in general/not specifically for a module
python3 -m pip install --user -r ./requirements.txt
}
verify_personal_python_packages() {
# some python packages I install manually as they're
# pretty personal/require extensive configuration
# here, just try and import them -- that shouldn't fail
# https://github.com/seanbreckenridge/mint
# https://github.com/seanbreckenridge/albums
python3 -c "import nextalbums, budget"
}
setup_data_dir() {
local DATA_PREFIX="${HOME}/data"
local -a directories
directories=(
'tupletally'
'doctor'
'github/gdpr'
'github/ghexport'
'zsh_history'
'bash_history'
'rexport'
'pushshift'
'todotxt'
'newsboat'
'firefox'
'mpv'
'blizzard'
'facebook_gdpr'
'ipython'
'old_forums'
'ttt'
'window_watcher'
'google_takeout'
'spotify'
'apple'
'discord'
'league_of_legends'
'chessdotcom'
'trakt'
'albums'
)
echo 'Setting up directories in ~/data'
for dir in "${directories[@]}"; do
ddir="${DATA_PREFIX}/${dir}"
if [[ ! -d "${ddir}" ]]; then
mkdir -p "${ddir}"
fi
done
}
required_commands() {
echo 'Checking if required commands are installed...'
set -e
havecmd curl
havecmd git
havecmd bgproc "For background tasks; install from https://github.com/seanbreckenridge/bgproc"
havecmd evry "To handle background tasks; install from https://github.com/seanbreckenridge/evry"
havecmd wait-for-internet "To verify I have internet; install from https://github.com/seanbreckenridge/wait-for-internet"
havecmd python3
havecmd fd 'For my.coding.commits'
havecmd mispipe 'part of the moreutils package'
set +e
# install arctee, needed for jobs
python3 -m pip install --user 'git+https://github.com/karlicoss/arctee'
}
main() {
required_commands || return $?
wait-for-internet
setup_data_dir || return $?
(setup_fork) || return $?
module_dependencies || return $?
verify_personal_python_packages || return $?
}
main "$@" || exit $?