-
Notifications
You must be signed in to change notification settings - Fork 5
/
_install_cmds.sh
executable file
·156 lines (136 loc) · 3.64 KB
/
_install_cmds.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
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
#!/bin/bash
DIR=$(dirname ${BASH_SOURCE[0]})
source $DIR/_installed.sh
kexts_dest=/Library/Extensions
tools_dest=/usr/local/bin
apps_dest=/Applications
if [[ ! -d $tools_dest ]]; then sudo mkdir $tools_dest; fi
function findKext() {
# $1: Kext
# $2: Directory
find "${@:2}" -name "$1" -not -path \*/PlugIns/* -not -path \*/Debug/*
}
function findTool() {
# $1: Tool
# $2: Directory
find "${@:2}" -name "$1" -type f -perm -u+x -not -path \*.kext/* -not -path \*.app/* -not -path \*/Debug/*
}
function findApp() {
# $1: App
# $2: Directory
find "${@:2}" -name "$1"
}
function checkExceptions() {
# $1: Item (kext, tool, app, etc)
# $2: Exceptions string
itemName=$(basename "$1")
if [[ -z "$2" || $(echo "$itemName" | grep -vE "$2") ]]; then
# Passed through exceptions
return 0
else
# Did not pass through exceptions
return 1
fi
}
function installKext() {
# $1: Kext to install
# $2: Destination (default: /Library/Extensions)
if [[ -d "$2" ]]; then local kexts_dest="$2"; fi
kextName=$(basename $1)
echo Installing $kextName to $kexts_dest
sudo rm -Rf $kexts_dest/$kextName
sudo cp -Rf $1 $kexts_dest
addInstalledItem "Kexts" "$kextName"
}
function installKextsInDirectory() {
# $1: Directory
# $2: Destination (optional)
# $3: Exceptions string (optional)
if [[ -d "$2" ]]; then
local kexts_dest="$2"
if [[ -n "$3" ]]; then
local exceptions="$3"
fi
elif [[ -n "$2" ]]; then
local exceptions="$2"
fi
for kext in $(findKext "*.kext" "$1"); do
checkExceptions "$kext" "$exceptions"
if [[ $? -eq 0 ]]; then
installKext "$kext" "$kexts_dest"
fi
done
}
function installTool() {
# $1: Tool to install
# $2: Destination (default: /usr/local/bin)
if [[ -d "$2" ]]; then local tools_dest="$2"; fi
fileName=$(basename $1)
echo Installing $fileName to $tools_dest
sudo rm -f $(which $fileName)
sudo cp -f $1 $tools_dest
addInstalledItem "Tools" "$fileName"
}
function installToolsInDirectory() {
# $1: Directory
# $2: Destination (optional)
# $3: Exceptions string (optional)
if [[ -d "$2" ]]; then
local tools_dest="$2"
if [[ -n "$3" ]]; then
local exceptions="$3"
fi
elif [[ -n "$2" ]]; then
local exceptions="$2"
fi
for tool in $(findTool "*" "$1"); do
checkExceptions "$tool" "$exceptions"
if [[ $? -eq 0 ]]; then
installTool "$tool" "$tools_dest"
fi
done
}
function installApp() {
# $1: App to install
# $2: Destination (default: /Applications)
if [[ -d "$2" ]]; then local apps_dest="$2"; fi
appName=$(basename $1)
echo Installing $appName to $apps_dest
sudo rm -Rf $apps_dest/$appName
cp -Rf $1 $apps_dest
addInstalledItem "Apps" "$appName"
}
function installAppsInDirectory() {
# $1: Directory
# $2: Destination (optional)
# $3: Exceptions string (optional)
if [[ -d "$2" ]]; then
local tools_dest="$2"
if [[ -n "$3" ]]; then
local exceptions="$3"
fi
elif [[ -n "$2" ]]; then
local exceptions="$2"
fi
for app in $(findApp "*.app" "$1"); do
checkExceptions "$app" "$exceptions"
if [[ $? -eq 0 ]]; then
installApp "$app" "$apps_dest"
fi
done
}
function removeKext() {
# $1: Kext name
sudo rm -Rf "$kexts_dest/$1"
removeInstalledItem "Kexts" "$1"
}
function removeApp() {
# $1: App name
sudo rm -Rf "$apps_dest/$1"
removeInstalledItem "Apps" "$1"
}
function removeTool() {
# $1: Tool name
sudo rm -Rf "$tools_dest/$1"
removeInstalledItem "Tools" "$1"
}