-
Notifications
You must be signed in to change notification settings - Fork 1
/
_helpers.sh
80 lines (70 loc) · 1.8 KB
/
_helpers.sh
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
#!/bin/sh
command_exists() {
local cmd="$1"
command -v "${cmd}" >/dev/null 2>&1
}
install_homebrew() {
local homebrew_installer_url="https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh"
command_exists "curl"
curl_exists=$?
if [[ $curl_exists -ne 0 ]]; then
if [[ -n "$(command -v "apt")" ]]; then
sudo apt install curl
else
echo >&2 "curl isn't available. What's up?"
exit 2
fi
fi
bash -c "$(curl -fsSL ${homebrew_installer_url})"
}
install_packages() {
local listfile="$1"
local cmd_template="$2"
oldifs="${IFS}"
IFS=$'\n'
failed=()
for package in `cat ${listfile}`; do
local clean_package=$(echo ${package} | sed -e 's/\//\\\//g')
local cmd=$(echo "${cmd_template}" | sed -e "s/\%PACKAGE\%/${clean_package}/g")
eval $cmd
if [[ $? -ne 0 ]]; then
failed+=("$package")
fi
done
IFS="${oldifs}"
if [[ ${#failed[@]} -gt 0 ]]; then
echo "These packages failed to install:"
printf "\t%s\n" "${failed[@]}"
echo "You can to rerun this script until this message disappears."
echo "Inspect the transcript to find more exact errors."
fi
}
# from_dir must be an absolute path!
link_all_files_in_dir() {
from_dir="$1"
to_dir="$2"
rm="$3"
prepend="$4"
case "$(uname -s)" in
Darwin) LN_OPTIONS="sFf" ;;
Linux) LN_OPTIONS="sf" ;;
# TODO: determine safe defaults for OSes I never use
*) LN_OPTIONS="sf" ;;
esac
for f in $(ls "${from_dir}"); do
TARGET="${from_dir}/${f}"
LINK="${to_dir}/${prepend}${f}"
if [[ ! -z $rm ]]; then
echo "Removing ${LINK}"
rm -f "${LINK}"
fi
echo "Linking ${LINK} to ${TARGET}"
ln -sFf "${TARGET}" "${LINK}"
done
}
banner_text() {
local text="${@}"
printf "\033#3%s\n" "${text}"
printf "\033#4%s\n" "${text}"
printf "\033#5"
}