source: branches/gsoc11-statistics/base/setupstats.sh @ 136298

Last change on this file since 136298 was 79659, checked in by derek@…, 9 years ago

Renamed install_launchd.sh to setupstats.sh
Modified Makefile.in accordingly

  • Property svn:executable set to *
File size: 2.1 KB
Line 
1#!/bin/sh
2
3#
4
5# Where the generated plist should be written
6PLIST=/Library/LaunchAgents/org.macports.stats.plist
7
8die () {
9    echo >&2 "$@"
10    exit 1
11}
12
13# Make sure exactly 2 arguments are provided
14[ "$#" -eq 2 ] || die "exactly two arguments required"
15
16# $1 must be the path to the script launchd will execute
17SCRIPT=$1
18
19# $2 is the path to the MacPorts configuration file
20CONFIG=$2
21
22# Make sure the script argument is executable
23if [ ! -x "$SCRIPT" ]; then
24        die "$SCRIPT is not a valid executable"
25fi
26
27# Make sure the config file exists
28if [ ! -f "$CONFIG" ]; then
29        die "$CONFIG does not exist"
30fi
31
32# Determine the day and time that launchd should run the script
33setup_times() {
34    # Get hardware uuid - Hardware UUID: UUID
35    huuid=`system_profiler SPHardwareDataType | grep "Hardware UUID"`
36   
37    # Strip out Hardware UUID:   
38    huuid=`echo $huuid | awk '/Hardware UUID/ {print $3;}'`
39   
40    # Strip out '-' characters
41    huuid=`echo $huuid | tr -d -`
42   
43    # Weekday is hardware uuid mod 7
44    weekday=`echo $huuid % 7 | bc`
45   
46    # Use current hours and minute
47    hour=`date '+%H'`
48    minute=`date '+%M'`
49}
50
51# Generate the launchd plist that executes 'port stats submit'
52# Outputs to the file $plist
53generate_plist() {
54    setup_times
55        cat <<-EOF > $PLIST
56                <?xml version="1.0" encoding="UTF-8"?>
57        <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
58        <plist version="1.0">
59         <dict>
60          <key>Label</key>
61          <string>org.macports.stats</string>
62          <key>ProgramArguments</key>
63          <array>
64             <string>$SCRIPT</string>
65             <string>$CONFIG</string>
66          </array>
67          <key>StartCalendarInterval</key>
68          <dict>
69            <key>Weekday</key>
70            <integer>$weekday</integer>
71            <key>Hour</key>
72            <integer>$hour</integer>
73            <key>Minute</key>
74            <integer>$minute</integer>
75          </dict>
76         </dict>
77        </plist>
78        EOF
79}
80
81# Install the plist using launchctl
82install_plist() {
83        launchctl load -w -F $PLIST
84}
85
86# Generate and install the plist
87generate_plist
88install_plist
89
90
Note: See TracBrowser for help on using the repository browser.