source: branches/gsoc11-statistics/base/submitstats.sh @ 139042

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

Added submitstats.sh

This script calls port stats submit only if a user is participating.
This script should not be called directly - It will be run by launchd

It takes one argument - the path to the MacPorts configuration file
It checks that configuration file for the value of 'stats_participate'
It runs 'port stats submit' only if 'stats_participate' is set to 'yes'

File size: 991 bytes
Line 
1#!/bin/sh
2
3# This script calls port stats submit only if a user is participating.
4# This script should not be called directly - It will be run by launchd
5
6# It takes one argument - the path to the MacPorts configuration file
7# It checks that configuration file for the value of 'stats_participate'
8# It runs 'port stats submit' only if 'stats_participate' is set to 'yes'
9
10configfile=$1
11
12die () {
13    echo >&2 "$@"
14    exit 1
15}
16
17# Make sure the config file exists
18if [ ! -f "$configfile" ]; then
19        die "$CONFIG does not exist"
20fi
21
22# Read configfile and see if stats_participate is set to yes
23is_participating() {
24        # An example line is "stats_participate yes"
25        line=$(grep "stats_participate" $configfile)
26        participating=$(awk '{print $2}' <<< $line)
27        if [ "$participating" == "yes" ]; then
28                return 0 # Return true - user is participating
29        else 
30                return 1 # Return false
31        fi
32}
33
34# Run the command if the user is participating
35if is_participating ; then
36        port stats submit > /dev/null
37fi
38
Note: See TracBrowser for help on using the repository browser.