-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall
executable file
·160 lines (140 loc) · 3.95 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
#!/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
}
pipm() {
python3 -m pip "$@"
}
pip_install() {
pipm install --user "$@"
}
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-fork'
UPSTREAM_URL='https://github.com/karlicoss/HPI'
FORK_URL="https://github.com/hpi/${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}" || return $?
git remote add upstream "${UPSTREAM_URL}"
else
echo "Path already exists, skipping clone..."
fi
cd "${FORK_TARGET}" || return $?
pip_install -e '.[optional,testing]'
# cd back to here, to pip install this
cd "${BASE_DIR}" || return $?
pip_install -e '.'
# TODO: ensure easy-install.path is ordered right?
}
# install dependencies (with pip) for this module
# this works by traversing the AST/looking for
# a 'REQUIRES' global variable in the
# corresponding file
hpi_module() {
hpi module install --user "$@"
}
module_dependencies() {
# no my.github.gdpr because I install deps manually
#(setup_ghexport) || return $?
hpi_module my.activitywatch
hpi_module my.airtable
hpi_module my.google_api
hpi_module my.eightsleep
hpi_module my.levelshealth
hpi_module my.lunchmoney
hpi_module my.rescuetime
hpi_module my.taskwarrior
hpi_module my.todoist
hpi_module my.trello
hpi_module my.typeform
hpi_module my.withings
# other requirements needed in general/not specifically for a module
pip_install -U -r ./requirements.txt
}
setup_data_dir() {
local DATA_PREFIX="${HOME}/data"
local -a directories
directories=(
'activitywatch'
'airtable'
'eightsleep'
'levelshealth'
'lunchmoney'
'rescuetime'
'taskwarrior'
'todoist'
'trello'
'typeform'
'withings'
)
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
set +e
}
install_dependencies() {
# install arctee, needed for jobs
pip_install 'git+https://github.com/karlicoss/arctee'
pip_install 'git+https://github.com/seanbreckenridge/reorder_editable'
}
main() {
required_commands || return $?
wait-for-internet
setup_data_dir || return $?
install_dependencies || return $?
(setup_fork) || return $?
module_dependencies || return $?
#verify_personal_python_packages || return $?
}
main "$@" || exit $?