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

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

Update preseed templates

  • Property svn:executable set to *
File size: 3.8 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)"
39# NOT NEEDED
40#LLIUREX_VERSION=$(${WHICH} lliurex-version)
41
42if [ -z "${N4DCLI}" -o -z "${FINDMNT}" -o -z "${CAT}" -o -z "${DEBCONF_COMM}" ]; then
43    exit 0
44fi
45
46
47# ACK FILE FUNCTIONS
48accept_file(){
49    echo "yes" > ${ACK_FILE}
50}
51deny_file(){
52    echo "no" > ${ACK_FILE}
53}
54reset_file(){
55    echo "" > ${ACK_FILE}
56}
57check_file(){
58    if [ -n "${LOCAL_ACKNOWLEDGE}" ]; then
59        exit 0
60    fi
61}
62
63# INSTALLATION TYPE DETECTION & ACKNOWLEDGE TYPES
64RUN_ON_LIVE="$(${FINDMNT} -P -t squashfs|${GREP} -i 'target="/rofs" source="/dev/loop[0-9]?"')"
65
66if [ -n "${RUN_ON_LIVE}" ]; then
67    #ON LIVE SYSTEMS STATS ARE DEACTIVATED
68    deny_file
69    exit 0
70fi
71
72RUN_ON_LTSP="$(echo $LTSP_FATCLIENT)"
73if [ -n "${RUN_ON_LTSP}" -a "${RUN_ON_LTSP}" = "false" ]; then
74    #ON THIN CLIENTS THE SERVER SEND THE STATISTICS
75    exit 0
76fi
77
78RUN_AS_CLIENT=$(${LLIUREX_VERSION} |${GREP} -i client)
79RUN_AS_SERVER=$(${LLIUREX_VERSION} |${GREP} -i server)
80RUN_AS_DESKTOP=""
81if [ -z ${RUN_AS_CLIENT} -a -z ${RUN_AS_SERVER} ];then
82    RUN_AS_DESKTOP="yes"
83else
84    #NOT USED INSIDE CONFIRMATOR, THIS LOGIC IS INTO COLLECTOR AND WILL BE ACCEPTED NOT NEED WRITE THE LOCAL FILE
85    SERVER_OVERRRIDE="$(${N4DCLI} -h server -c VariablesManager -m get_variable -a 'STATS_ENABLED'|${GREP} '1')"
86    if [ -n "${SERVER_OVERRIDE}" ]; then
87        exit 0
88    fi
89fi
90
91LOCAL_ACKNOWLEDGE="$(${CAT} ${ACK_FILE}|${GREP} -E -i -o 'yes|no')"
92
93DEBCONF_ACKNOWLEDGE="$(echo get lliurex-statistics/acknowledge|${DEBCONF_COMM} 2>/dev/null |${GREP} -E -i -o 'true|false')"
94
95
96# DIALOG FUNCTION
97
98show_dialog(){
99# Script messages l10n
100# Detects which language is set
101RET=""
102_langrc=0
103echo $LANGUAGE | grep -q "^ca_ES" || _langrc=1
104
105# All message strings in both languages
106VA_CONFIRM="Desitgeu acceptar la monitorització d'estadístiques?"
107ES_CONFIRM="¿Desea aceptar la monitoritzación de estadísticas?"
108
109# Valencian is selected by default
110CONFIRM="$VA_CONFIRM"
111
112# But they could change if Spanish is detected
113if [ $_langrc -eq 1 ] ; then
114        CONFIRM="$ES_CONFIRM"
115fi
116
117zenity --question --text "$CONFIRM"
118
119if [ $? -eq 0 ]; then
120    RET="yes"
121fi
122}
123# AT THIS POINT:
124# - FILE IS PRESENT & IT'S WRITEABLE
125# - THIS IS NOT A LIVE SYSTEM
126# - THIS IS NOT A LTSP THIN CLIENT
127# - SERVER IS NOT FORCING THE ACKNOWLEDGE OF COLLECT STATISTICS
128
129# TRY TO WRITE ACK FILE NOW
130# ACCEPTATION PRIORITY: 1 SERVER ACK, 2 DEBCONF ACK, 3 LOCAL ACK
131
132# DEBCONF ACK (HIGH PRIORITY OVER LOCAL FILE) : POSSIBLE VALUES ARE: TRUE, FALSE, ASK (LOCAL ANSWER) (DEFAULT IF UNATTENDED INSTALL)
133if [ -n "${DEBCONF_ACKNOWLEDGE}" ]; then
134    if [ "${DEBCONF_ACKNOWLEDGE}" = "true" ]; then
135        accept_file
136        exit 0
137    fi
138    if [ "${DEBCONF_ACKNOWLEDGE}" = "false" ]; then
139        deny_file
140        exit 0
141    fi
142fi
143
144# LOCAL ACK
145# ALL OTHER EXECUTIONS
146#if [ -n ${RUN_AS_DESKTOP} -o -n ${RUN_AS_SERVER} -o -n ${RUN_AS_CLIENT} ]; then
147
148#IF ALREADY SET THE ANSWER (yes|no) check_file AVOID ASKING ANOTHER TIME
149check_file
150show_dialog
151if [ -n "${RET}" ]; then
152    accept_file
153else
154    deny_file
155fi
156exit 0
157
158#fi
159
Note: See TracBrowser for help on using the repository browser.