-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathinstall.sh
executable file
·56 lines (51 loc) · 1.89 KB
/
install.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
#!/bin/bash
readonly APPLICATION_DIR_ABSOLUTE_PATH="$(pwd -P $(dirname $0))"
readonly GITHUB_NOTIF_APP=github_notif
readonly CONFIGURE_APP=configure.sh
readonly INVOCATION_INTERVAL_IN_SECONDS=60
. $APPLICATION_DIR_ABSOLUTE_PATH/constants.sh
. $APPLICATION_DIR_ABSOLUTE_PATH/lib/prompter.sh
. $APPLICATION_DIR_ABSOLUTE_PATH/lib/config_accessor.sh
function get_plist_body() {
cat <<- EOF
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>org.github-notif.get.list</string>
<key>ProgramArguments</key>
<array>
<string>$APPLICATION_DIR_ABSOLUTE_PATH/$GITHUB_NOTIF_APP</string>
</array>
<key>StartInterval</key>
<integer>$INVOCATION_INTERVAL_IN_SECONDS</integer>
<key>StandardOutPath</key>
<string>$LOGFILE_PATH</string>
<key>StandardErrorPath</key>
<string>$LOGFILE_PATH</string>
</dict>
</plist>
EOF
}
function main() {
brew install emojify
mkdir -p $(dirname $LOGFILE_PATH)
touch $LOGFILE_PATH
echo "$(get_plist_body)" > org.github-notif.get.plist
mkdir -p $LAUNCH_AGENTS_DIR
cp org.github-notif.get.plist $LAUNCH_AGENTS_DIR &&
rm org.github-notif.get.plist
launchctl unload $LAUNCH_AGENTS_DIR/org.github-notif.get.plist > /dev/null # unload the old service when it was loaded before. Ignore the error message if service is not insatlled
launchctl load -w $LAUNCH_AGENTS_DIR/org.github-notif.get.plist
local github_url=https://github.com
if ! config_exists $github_url; then
local command="$APPLICATION_DIR_ABSOLUTE_PATH/$CONFIGURE_APP add $github_url"
prompt_for_action "$command" "Do you want to setup $github_url notifications now"
if [[ $? -ne 0 ]]; then
echo "You can add an instance later with '$command' command"
fi
fi
echo "The service is now installed for your account."
}
main