source: lliurex-statistics/trunk/fuentes/lliurex-statistics.install/usr/bin/confirmator @ 3270

Last change on this file since 3270 was 3270, checked in by mabarracus, 3 years ago

Fix bug into confirmator

  • Property svn:executable set to *
File size: 4.1 KB
Line 
1#!/bin/bash
2PARAM="$1"
3ACK_FILE=/etc/lliurex-analytics/status
4
5# MAIN PURPOSE FOR THIS SCRIPT IS WRITE THE FILE
6# IF ISN'T POSSIBLE IT DOESN'T MAKE SENSE CONTINUE
7RIGHTS_TO_ACK=""
8if [ -w "${ACK_FILE}" ]; then
9    RIGHTS_TO_ACK="yes"
10else
11    # UNPRIVILEGED USERS CAN'T APPROVE OR FILE DOESN'T EXIST
12    exit 0
13fi
14
15# CHECK BASIC DEPENDENCIES
16WHICH="$(which which)"
17if [ -z "${WHICH}" ]; then
18    exit 0
19fi     
20DPKG="$(${WHICH} dpkg)"
21GREP="$(${WHICH} egrep)"
22
23if [ -z "${DPKG}" -o -z "${GREP}" ]; then 
24    exit 0
25fi
26# CHECK MAIN DEPENDENCIES
27AUDIT_INSTALLED="$(${DPKG} -l|${GREP} -o auditd)"
28PYTHON_DAEMON_INSTALLED="$(${DPKG} -l|${GREP} -o python-daemon)"
29
30if [ -z "${AUDIT_INSTALLED}" -o -z "${PYTHON_DAEMON_INSTALLED}" ]; then 
31    exit 0
32fi
33
34# CHECK DEPENDENCIES 4 TESTING
35N4DCLI="$(${WHICH} n4d-client)"
36FINDMNT="$(${WHICH} findmnt)"
37CAT="$(${WHICH} cat)"
38DEBCONF_COMM="$(${WHICH} debconf-communicate)"
39LLIUREX_VERSION=$(${WHICH} lliurex-version)
40
41if [ -z "${N4DCLI}" -o -z "${FINDMNT}" -o -z "${CAT}" -o -z "${DEBCONF_COMM}" -o -z "${LLIUREX_VERSION}" ]; then 
42    exit 0
43fi
44
45
46# ACK FILE FUNCTIONS
47accept_file(){
48    echo "yes" > ${ACK_FILE}
49}
50deny_file(){
51    echo "no" > ${ACK_FILE}
52}
53reset_file(){
54    echo "" > ${ACK_FILE}
55}
56check_file(){
57    if [ -n "${LOCAL_ACKNOWLEDGE}" ]; then
58        exit 0
59    fi
60}
61
62# INSTALLATION TYPE DETECTION & ACKNOWLEDGE TYPES
63RUN_ON_LIVE="$(${FINDMNT} -P -t squashfs|${GREP} -i 'target="/rofs" source="/dev/loop[0-9]?"')"
64
65if [ -n "${RUN_ON_LIVE}" ]; then
66    #ON LIVE SYSTEMS STATS ARE DEACTIVATED
67    deny_file
68    exit 0
69fi
70
71RUN_ON_LTSP="$(echo $LTSP_FATCLIENT)"
72if [ -n "${RUN_ON_LTSP}" -a "${RUN_ON_LTSP}" = "false" ]; then
73    #ON THIN CLIENTS THE SERVER SEND THE STATISTICS
74    exit 0
75fi
76
77RUN_AS_CLIENT=$(${LLIUREX_VERSION} |${GREP} -i -o client|uniq)
78RUN_AS_SERVER=$(${LLIUREX_VERSION} |${GREP} -i -o server|uniq)
79RUN_AS_DESKTOP=""
80if [ -z "${RUN_AS_CLIENT}" -a -z "${RUN_AS_SERVER}" ];then
81    RUN_AS_DESKTOP="yes"
82else
83    #NOT USED INSIDE CONFIRMATOR, THIS LOGIC IS INTO COLLECTOR AND WILL BE ACCEPTED NOT NEED WRITE THE LOCAL FILE
84    SERVER_OVERRIDE="$(${N4DCLI} -h server -c VariablesManager -m get_variable -a 'STATS_ENABLED'|${GREP} '1')"
85    if [ -n "${SERVER_OVERRIDE}" ]; then
86        exit 0
87    fi
88fi
89
90LOCAL_ACKNOWLEDGE="$(${CAT} ${ACK_FILE}|${GREP} -E -i -o 'yes|no')"
91# IF ALREADY ACCEPTED OR DENIED AND IS NOT FORCED EXECUTION AFTER CHECK SERVER OVERRIDE WE CAN EXIT AT THIS POINT
92if [ -n "${LOCAL_ACKNOWLEDGE}" -a "${PARAM}" != "-f" ]; then
93    exit 0
94fi
95
96DEBCONF_ACKNOWLEDGE="$(echo get lliurex-statistics/acknowledge|${DEBCONF_COMM} 2>/dev/null |${GREP} -E -i -o 'true|false')"
97
98
99# DIALOG FUNCTION
100
101show_dialog(){
102# Script messages l10n
103# Detects which language is set
104RET=""
105_langrc=0
106echo $LANGUAGE | grep -q "^ca_ES" || _langrc=1
107
108# All message strings in both languages
109VA_CONFIRM="Desitgeu acceptar la monitorització d'estadístiques?"
110ES_CONFIRM="¿Desea aceptar la monitoritzación de estadísticas?"
111
112# Valencian is selected by default
113CONFIRM="$VA_CONFIRM"
114
115# But they could change if Spanish is detected
116if [ $_langrc -eq 1 ] ; then
117        CONFIRM="$ES_CONFIRM"
118fi
119
120zenity --question --text "$CONFIRM"
121
122if [ $? -eq 0 ]; then
123    RET="yes"
124fi
125}
126# AT THIS POINT:
127# - FILE IS PRESENT & IT'S WRITEABLE
128# - THIS IS NOT A LIVE SYSTEM
129# - THIS IS NOT A LTSP THIN CLIENT
130# - SERVER IS NOT FORCING THE ACKNOWLEDGE OF COLLECT STATISTICS
131
132# TRY TO WRITE ACK FILE NOW
133# ACCEPTATION PRIORITY: 1 SERVER ACK, 2 DEBCONF ACK, 3 LOCAL ACK
134
135# DEBCONF ACK (HIGH PRIORITY OVER LOCAL FILE) : POSSIBLE VALUES ARE: TRUE, FALSE, ASK (LOCAL ANSWER) (DEFAULT IF UNATTENDED INSTALL)
136if [ -n "${DEBCONF_ACKNOWLEDGE}" ]; then
137    if [ "${DEBCONF_ACKNOWLEDGE}" = "true" ]; then
138        accept_file
139        exit 0
140    fi
141    if [ "${DEBCONF_ACKNOWLEDGE}" = "false" ]; then
142        deny_file
143        exit 0
144    fi
145fi
146
147# LOCAL ACK
148# ALL OTHER EXECUTIONS
149#if [ -n ${RUN_AS_DESKTOP} -o -n ${RUN_AS_SERVER} -o -n ${RUN_AS_CLIENT} ]; then
150
151#IF ALREADY SET THE ANSWER (yes|no) check_file AVOID ASKING ANOTHER TIME
152check_file
153show_dialog
154if [ -n "${RET}" ]; then
155    accept_file
156else
157    deny_file
158fi
159exit 0
160
161#fi
162
Note: See TracBrowser for help on using the repository browser.