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

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

Fix confirmator logic & typo errors

  • Property svn:executable set to *
File size: 3.9 KB
Line 
1#!/bin/bash
2
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)
78RUN_AS_SERVER=$(${LLIUREX_VERSION} |${GREP} -i -o server)
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
92DEBCONF_ACKNOWLEDGE="$(echo get lliurex-statistics/acknowledge|${DEBCONF_COMM} 2>/dev/null |${GREP} -E -i -o 'true|false')"
93
94
95# DIALOG FUNCTION
96
97show_dialog(){
98# Script messages l10n
99# Detects which language is set
100RET=""
101_langrc=0
102echo $LANGUAGE | grep -q "^ca_ES" || _langrc=1
103
104# All message strings in both languages
105VA_CONFIRM="Desitgeu acceptar la monitorització d'estadístiques?"
106ES_CONFIRM="¿Desea aceptar la monitoritzación de estadísticas?"
107
108# Valencian is selected by default
109CONFIRM="$VA_CONFIRM"
110
111# But they could change if Spanish is detected
112if [ $_langrc -eq 1 ] ; then
113        CONFIRM="$ES_CONFIRM"
114fi
115
116zenity --question --text "$CONFIRM"
117
118if [ $? -eq 0 ]; then
119    RET="yes"
120fi
121}
122# AT THIS POINT:
123# - FILE IS PRESENT & IT'S WRITEABLE
124# - THIS IS NOT A LIVE SYSTEM
125# - THIS IS NOT A LTSP THIN CLIENT
126# - SERVER IS NOT FORCING THE ACKNOWLEDGE OF COLLECT STATISTICS
127
128# TRY TO WRITE ACK FILE NOW
129# ACCEPTATION PRIORITY: 1 SERVER ACK, 2 DEBCONF ACK, 3 LOCAL ACK
130
131# DEBCONF ACK (HIGH PRIORITY OVER LOCAL FILE) : POSSIBLE VALUES ARE: TRUE, FALSE, ASK (LOCAL ANSWER) (DEFAULT IF UNATTENDED INSTALL)
132if [ -n "${DEBCONF_ACKNOWLEDGE}" ]; then
133    if [ "${DEBCONF_ACKNOWLEDGE}" = "true" ]; then
134        accept_file
135        exit 0
136    fi
137    if [ "${DEBCONF_ACKNOWLEDGE}" = "false" ]; then
138        deny_file
139        exit 0
140    fi
141fi
142
143# LOCAL ACK
144# ALL OTHER EXECUTIONS
145#if [ -n ${RUN_AS_DESKTOP} -o -n ${RUN_AS_SERVER} -o -n ${RUN_AS_CLIENT} ]; then
146
147#IF ALREADY SET THE ANSWER (yes|no) check_file AVOID ASKING ANOTHER TIME
148check_file
149show_dialog
150if [ -n "${RET}" ]; then
151    accept_file
152else
153    deny_file
154fi
155exit 0
156
157#fi
158
Note: See TracBrowser for help on using the repository browser.