#!/bin/bash PARAM="$1" ACK_FILE=/etc/lliurex-analytics/status # MAIN PURPOSE FOR THIS SCRIPT IS WRITE THE FILE # IF ISN'T POSSIBLE IT DOESN'T MAKE SENSE CONTINUE RIGHTS_TO_ACK="" if [ -w "${ACK_FILE}" ]; then RIGHTS_TO_ACK="yes" else # UNPRIVILEGED USERS CAN'T APPROVE OR FILE DOESN'T EXIST exit 0 fi # CHECK BASIC DEPENDENCIES WHICH="$(which which)" if [ -z "${WHICH}" ]; then exit 0 fi DPKG="$(${WHICH} dpkg)" GREP="$(${WHICH} egrep)" if [ -z "${DPKG}" -o -z "${GREP}" ]; then exit 0 fi # CHECK MAIN DEPENDENCIES AUDIT_INSTALLED="$(${DPKG} -l|${GREP} -o auditd)" PYTHON_DAEMON_INSTALLED="$(${DPKG} -l|${GREP} -o python-daemon)" if [ -z "${AUDIT_INSTALLED}" -o -z "${PYTHON_DAEMON_INSTALLED}" ]; then exit 0 fi # CHECK DEPENDENCIES 4 TESTING N4DCLI="$(${WHICH} n4d-client)" FINDMNT="$(${WHICH} findmnt)" CAT="$(${WHICH} cat)" DEBCONF_COMM="$(${WHICH} debconf-communicate)" LLIUREX_VERSION=$(${WHICH} lliurex-version) if [ -z "${N4DCLI}" -o -z "${FINDMNT}" -o -z "${CAT}" -o -z "${DEBCONF_COMM}" -o -z "${LLIUREX_VERSION}" ]; then exit 0 fi # ACK FILE FUNCTIONS accept_file(){ echo "yes" > ${ACK_FILE} } deny_file(){ echo "no" > ${ACK_FILE} } reset_file(){ echo "" > ${ACK_FILE} } check_file(){ if [ -n "${LOCAL_ACKNOWLEDGE}" ]; then exit 0 fi } # INSTALLATION TYPE DETECTION & ACKNOWLEDGE TYPES RUN_ON_LIVE="$(${FINDMNT} -P -t squashfs|${GREP} -i 'target="/rofs" source="/dev/loop[0-9]?"')" if [ -n "${RUN_ON_LIVE}" ]; then #ON LIVE SYSTEMS STATS ARE DEACTIVATED deny_file exit 0 fi RUN_ON_LTSP="$(echo $LTSP_FATCLIENT)" if [ -n "${RUN_ON_LTSP}" -a "${RUN_ON_LTSP}" = "false" ]; then #ON THIN CLIENTS THE SERVER SEND THE STATISTICS exit 0 fi RUN_AS_CLIENT=$(${LLIUREX_VERSION} |${GREP} -i -o client|uniq) RUN_AS_SERVER=$(${LLIUREX_VERSION} |${GREP} -i -o server|uniq) RUN_AS_DESKTOP="" if [ -z "${RUN_AS_CLIENT}" -a -z "${RUN_AS_SERVER}" ];then RUN_AS_DESKTOP="yes" else #NOT USED INSIDE CONFIRMATOR, THIS LOGIC IS INTO COLLECTOR AND WILL BE ACCEPTED NOT NEED WRITE THE LOCAL FILE SERVER_OVERRIDE="$(${N4DCLI} -h server -c VariablesManager -m get_variable -a 'STATS_ENABLED'|${GREP} '1')" if [ -n "${SERVER_OVERRIDE}" ]; then exit 0 fi fi LOCAL_ACKNOWLEDGE="$(${CAT} ${ACK_FILE}|${GREP} -E -i -o 'yes|no')" # IF ALREADY ACCEPTED OR DENIED AND IS NOT FORCED EXECUTION AFTER CHECK SERVER OVERRIDE WE CAN EXIT AT THIS POINT if [ -n "${LOCAL_ACKNOWLEDGE}" -a "${PARAM}" != "-f" ]; then exit 0 fi DEBCONF_ACKNOWLEDGE="$(echo get lliurex-statistics/acknowledge|${DEBCONF_COMM} 2>/dev/null |${GREP} -E -i -o 'true|false')" # DIALOG FUNCTION show_dialog(){ # Script messages l10n # Detects which language is set RET="" _langrc=0 echo $LANGUAGE | grep -q "^ca_ES" || _langrc=1 # All message strings in both languages VA_CONFIRM="Desitgeu acceptar la monitorització d'estadístiques?" ES_CONFIRM="¿Desea aceptar la monitoritzación de estadísticas?" # Valencian is selected by default CONFIRM="$VA_CONFIRM" # But they could change if Spanish is detected if [ $_langrc -eq 1 ] ; then CONFIRM="$ES_CONFIRM" fi zenity --question --text "$CONFIRM" if [ $? -eq 0 ]; then RET="yes" fi } # AT THIS POINT: # - FILE IS PRESENT & IT'S WRITEABLE # - THIS IS NOT A LIVE SYSTEM # - THIS IS NOT A LTSP THIN CLIENT # - SERVER IS NOT FORCING THE ACKNOWLEDGE OF COLLECT STATISTICS # TRY TO WRITE ACK FILE NOW # ACCEPTATION PRIORITY: 1 SERVER ACK, 2 DEBCONF ACK, 3 LOCAL ACK # DEBCONF ACK (HIGH PRIORITY OVER LOCAL FILE) : POSSIBLE VALUES ARE: TRUE, FALSE, ASK (LOCAL ANSWER) (DEFAULT IF UNATTENDED INSTALL) if [ -n "${DEBCONF_ACKNOWLEDGE}" ]; then if [ "${DEBCONF_ACKNOWLEDGE}" = "true" ]; then accept_file exit 0 fi if [ "${DEBCONF_ACKNOWLEDGE}" = "false" ]; then deny_file exit 0 fi fi # LOCAL ACK # ALL OTHER EXECUTIONS #if [ -n ${RUN_AS_DESKTOP} -o -n ${RUN_AS_SERVER} -o -n ${RUN_AS_CLIENT} ]; then #IF ALREADY SET THE ANSWER (yes|no) check_file AVOID ASKING ANOTHER TIME check_file show_dialog if [ -n "${RET}" ]; then accept_file else deny_file fi exit 0 #fi