source: lliurex-zero-installers/trunk/fuentes/lliurex-zero-installer-analytics.zmds/lliurex-zero-installer-analytics.zmd @ 3415

Last change on this file since 3415 was 3415, checked in by mabarracus, 4 years ago

New lliurex-statistics controller for classroom

File size: 3.1 KB
Line 
1#!/bin/bash
2# Examples:
3# xgettext -o - -L Shell --keyword --keyword=GETTEXT lliurex-zero-installer-analytics.zmd
4# xgettext -o file.pot -L Shell --keyword --keyword=GETTEXT lliurex-zero-installer-analytics.zmd
5# LANG=es_ES.UTF-8 gettext -d lliurex-zero-installer-analytics -s "Enabled"
6# msginit -i file.pot -l es_ES.UTF-8
7# msgfmt -v es_ES.po -o es_ES.mo
8# cp es_ES.mo /usr/share/locale/es_ES/LC_MESSAGES/lliurex-zero-installer-analytics.mo
9#
10#
11# LANGUAGE SECTION
12set -x
13export TEXTDOMAIN="lliurex-zero-installer-analytics"
14
15GETTEXT="gettext -d $TEXTDOMAIN -s "
16
17# DETECTION SECTION
18
19ASK_QUESTION1="yes"
20ASK_QUESTION2="yes"
21
22#Subset detection from confirmator
23RUN_ON_LTSP="$(echo $LTSP_FATCLIENT)"
24if [ -n "${RUN_ON_LTSP}" ]; then
25    ASK_QUESTION1="no"
26    ASK_QUESTION2="no"
27fi
28
29#RUN_AS_CLIENT=$(${LLIUREX_VERSION} |${GREP} -i -o client|uniq)
30RUN_AS_SERVER=$(lliurex-version |egrep -i -o server|uniq)
31#RUN_AS_DESKTOP=""
32#if [ -z "${RUN_AS_CLIENT}" -a -z "${RUN_AS_SERVER}" ];then
33#    RUN_AS_DESKTOP="yes"
34#fi
35
36if [ -n "${RUN_AS_SERVER}" ];then
37    ASK_QUESTION1="yes"
38    ASK_QUESTION2="yes"
39else 
40#CLIENTS OR DESKTOPS
41    ASK_QUESTION1="yes"
42    ASK_QUESTION2="no"
43fi
44
45Q1=$($GETTEXT "Lliurex-statistics is %s in this system. Do you want change this state?\n")
46echo Q1 $Q1
47VALUE_ME="$(cat /etc/lliurex-analytics/status|grep -i -o yes|uniq)"
48if [ -n "$VALUE_ME" ];then
49    STATUS_ME=$($GETTEXT "enabled")
50else
51    STATUS_ME=$($GETTEXT "disabled")
52fi
53
54QUESTION1=$(printf "$Q1" "$STATUS_ME")
55echo QUESTION1 $QUESTION1
56if [ "$ASK_QUESTION2" = "yes" ];then
57    Q2=$($GETTEXT "Classroom clients have %s status for the reporting agent. Do you want to change reporting agent status?\n")
58    echo Q2 $Q2
59
60    # Example: n4d-client -u netadmin -p lliurex -c NetinstallManager -m [ get_force_classroom_stats | set_force_classroom_stats -a [ 1 | 0 ] ]
61    CURRENT_VALUE="$(n4d-client -u netadmin -p lliurex -c VariablesManager -m get_variable -a 'STATS_ENABLED')"
62
63    STATUS_CLASS=""
64    if [ "x${CURRENT_VALUE}" = "x1" ]; then
65    #Enabled
66        STATUS_CLASS=$($GETTEXT "enabled")
67    else
68        if [ "x${CURRENT_VALUE}" = "x0" ]; then
69        #Disabled
70            STATUS_CLASS=$($GETTEXT "disabled")
71        else
72        #Unknown
73            STATUS_CLASS=$($GETTEXT "unknown")
74        fi
75    fi
76    QUESTION2=$(printf "$Q2" "$STATUS_CLASS")
77    echo QUESTION2 $QUESTION2
78fi
79
80
81# RUN QUESTIONS SECCTION
82
83zenity --question --text="$QUESTION1"  --ok-label=$($GETTEXT "Allow") --cancel-label=$($GETTEXT "Disallow") > /dev/null 2>&1
84if [ $? -eq 0 ]; then
85    #Enable local stats
86    echo yes > /etc/lliurex-analytics/status
87else
88    #Disable local stats
89    echo no > /etc/lliurex-analytics/status
90fi
91
92
93if [ "$ASK_QUESTION2" = "yes" ]; then
94    zenity --question --text="$QUESTION2"  --ok-label=$($GETTEXT "Allow") --cancel-label=$($GETTEXT "Disallow") > /dev/null 2>&1
95    if [ $? -eq 0 ]; then
96        #Enable classroom stats
97        RES="$(n4d-client -u netadmin -p lliurex -c VariablesManager -m set_variable -a 'STATS_ENABLED' 1)"
98    else
99        #Disable classroom stats
100        RES="$(n4d-client -u netadmin -p lliurex -c VariablesManager -m set_variable -a 'STATS_ENABLED' 0)"
101    fi
102fi
103
104exit 0
Note: See TracBrowser for help on using the repository browser.