#!/bin/bash FILE_OF_RULES="/etc/lliurex-moving-profiles.conf" test_permissions() { USER_ID="$(id -u)" if [ ${USER_ID} -ne 0 ]; then echo " [ Moving Profiles Rules ] : You need root privileges" exit 1 fi } show_usage() { echo " [ Moving Profiles Rules ] " echo " USAGE : Simple script to manage moving profiles" echo " moving-profiles-rules add [rule]" echo "" echo " Rules available: " echo " * local" exit 0 } add_rule() { echo "[ Moving Profiles Rules ] Adding :"${1} RULE="${1}" case ${RULE} in local) rc=0 grep -q "^local" ${FILE_OF_RULES} || rc=1 if [ ${rc} -eq 1 ] ; then echo "[ Moving Profiles Rules ]: Not exists..adding" sed -i '/\[include\]/a local=.local' ${FILE_OF_RULES} else echo "[ Moving Profiles Rules ]: Rule already exists" fi ;; *) echo " [ Moving Profiles Rules ] : Unknown RULE" ;; esac } # # Main test_permissions if [ $# -lt 2 ]; then show_usage fi ACTION="${1}" case ${ACTION} in add) shift RULE="${1}" add_rule ${RULE} exit 0 ;; *) echo " [ Moving Profiles Rules ] : Unknow action" ;; esac exit 0