-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathinstall_dependency.sh
executable file
·70 lines (51 loc) · 1.7 KB
/
install_dependency.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
#!/bin/bash
# shellcheck disable=2154,2181
alfred_workflow_cache=${alfred_workflow_cache:-"."}
APP="${1}"
PKG="${2}"
EXE="${3}"
BREW=""
PORT=""
# Try installing with a package manager
install () {
log "Could not find ${APP}"
dialog='Could not find '"${APP}"'. Try installing with '"${1}"'?'
title="${alfred_workflow_name}"
buttons='{ "Cancel", "Install" }'
2>&- osascript -e 'display dialog "'"${dialog}"'" with icon stop with title "'"${title}"'" buttons '"${buttons}"' default button "Cancel"' > /dev/null
if [ $? == 0 ]; then
echo -n "install"
osascript -e 'display notification "Installing '"${APP}"'"'
osascript -e 'tell application "Terminal" to activate'
osascript -e 'tell application "Terminal" to do script "exec '"${2}"'"'
fi
}
# Create local symlink
mklink () {
for D in /usr/bin /usr/local/bin /opt/{homebrew,local}/bin /usr/local/Cellar/"${PKG}"/*/bin /opt/homebrew/Cellar/"${PKG}"/*/bin /run/current-system/sw/bin; do
if [ -x "${D}/${EXE}" ]; then
log "ln -sf ${D}/${EXE} ${alfred_workflow_cache}"
ln -sf "${D}/${EXE}" "${alfred_workflow_cache}"
break
fi
# Look for brew and port too
[ -x "${D}"/brew ] && BREW="${D}"/brew
[ -x "${D}"/port ] && PORT="${D}"/port
done
}
##################################################
# Main
# Check symlink
[ -x "${alfred_workflow_cache}/${EXE}" ] && exit
# Make symlink
mklink
# Check again
[ -x "${alfred_workflow_cache}/${EXE}" ] && exit
# Offer to install
if [ "${BREW}" != "" ]; then
install "Homebrew" "${BREW} install ${PKG}"
elif [ "${PORT}" != "" ]; then
install "MacPorts" "sudo ${PORT} -N install ${PKG}"
fi
# Once more, with feeling
[ -x "${alfred_workflow_cache}/${EXE}" ] || echo -n "cancel"