-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcustom_startup_script_v4.sh
More file actions
105 lines (79 loc) · 4.46 KB
/
Copy pathcustom_startup_script_v4.sh
File metadata and controls
105 lines (79 loc) · 4.46 KB
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
#!/bin/bash
# create my timestamp for naming the log file
timestamp=$(date +"%Y-%m-%d_%T")
# set the log output directory
logDir=/Users/scott/Logs/custom_startup_script/v4/
# format the timestamp by replacing ":" from the filename (otherwise macOS will moan like a bitch)
ts=${timestamp//[:]/-}
# set value for output log
logFile=$logDir$ts.txt
printf "%s\tCommence logging of custom startup script\n" "$(/usr/local/bin/gdate +"%T.%4N")" > $logFile
# Since there is an issue with Transmission starting up before the required
# disks have been mounted, this script will run at startup, check if
# Transmission is running, terminate the process if it is, and loop over the
# mounted volumes until /Volumes/iMacHD is mounted. Once iMacHD is mounted, launch Transmission
# Transmission
#####################################################################################################################
# Reference site:
# https://stackoverflow.com/questions/1821886/check-if-mac-process-is-running-using-bash-by-process-name
printf "%s\tCheck for existing Transmission service\n" "$(/usr/local/bin/gdate +"%T.%4N")" >> $logFile
PROCESS=Transmission
number=$(ps aux | grep -v grep | grep -ci Transmission)
if [ $number -gt 0 ]
then
printf "%s\tTransmission is running. Kill it!\n" "$(/usr/local/bin/gdate +"%T.%4N")" >> $logFile
/usr/bin/killall $PROCESS
printf "%s\tTransmission killed\n" "$(/usr/local/bin/gdate +"%T.%4N")" >> $logFile
sleep 2
else
printf "%s\tTransmission process not found\n" "$(/usr/local/bin/gdate +"%T.%4N")" >> $logFile
fi
# while loop to check mounted volumes
while ! [[ $(mount | awk '$3 == "/Volumes/iMacHD" {print $3}') != "" ]];
do
printf "%s\tiMacHD disk not mounted yet. Wait for 2 seconds\n" "$(/usr/local/bin/gdate +"%T.%4N")" >> $logFile
sleep 2
done
printf "%s\tiMacHD disk successfully mounted. Continue\n" "$(/usr/local/bin/gdate +"%T.%4N")" >> $logFile
# now we can launch Transmission, Radarr and Sonarr
printf "%s\tStarting Transmission\n" "$(/usr/local/bin/gdate +"%T.%4N")" >> $logFile
/usr/bin/open -a Transmission
status=$?
printf "%s\tRequest to start Transmission returned: %s\n" "$(/usr/local/bin/gdate +"%T.%4N")" $status >> $logFile
#####################################################################################################################
# Sonarr
#####################################################################################################################
printf "%s\tWaiting 1 second before starting Sonarr service\n" "$(/usr/local/bin/gdate +"%T.%4N")" >> $logFile
sleep 1s
printf "%s\tStarting Sonarr\n" "$(/usr/local/bin/gdate +"%T.%4N")" >> $logFile
/usr/bin/open -a Sonarr
status=$?
printf "%s\tRequest to start Sonarr returned: %s\n" "$(/usr/local/bin/gdate +"%T.%4N")" $status >> $logFile
# Sonarr
#####################################################################################################################
# Radarr
#####################################################################################################################
printf "%s\tWaiting 1 second before starting Radarr service\n" "$(/usr/local/bin/gdate +"%T.%4N")" >> $logFile
sleep 1s
printf "%s\tStarting Radarr\n" "$(/usr/local/bin/gdate +"%T.%4N")" >> $logFile
/usr/bin/open -a Radarr
status=$?
printf "%s\tRequest to start Radarr returned: %s\n" "$(/usr/local/bin/gdate +"%T.%4N")" $status >> $logFile
# Radarr
#####################################################################################################################
# Sony speaker
#####################################################################################################################
# Finally, connect the Sony bluetooth speaker if headphones not plugged in
printf "%s\tFinally, let\'s connect the Sony Bluetooth speaker\n" "$(/usr/local/bin/gdate +"%T.%4N")" >> $logFile
audio_output=$(system_profiler SPAudioDataType | grep "Output Source:" | awk '{print $3}')
if [ $audio_output != "Headphones" ]
then
/usr/local/bin/blueutil --connect "SRS-BT100"
status=$?
printf "%s\tBluetooth connection attempt returned: %s\n" "$(/usr/local/bin/gdate +"%T.%4N")" $status >> $logFile
else
printf "%s\tHeadphones are plugged in, so not connecting to bluetooth.\n" "$(/usr/local/bin/gdate +"%T.%4N")" >> $logFile
fi
#####################################################################################################################
printf "%s\tStartup complete. Exiting!\n" "$(/usr/local/bin/gdate +"%T.%4N")" >> $logFile
exit 0