| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121 |
- #!/bin/sh
- echo "============== post installation custom scripts start =============="
- curr_timestamp=`date "+%Y%m%d-%H%M%S.%3N"`
- sudo_priviledge() {
- given_user=$1
- given_sudoers_file=$2
- if [ -e ${given_sudoers_file}.tmp -o "$(pidof visudo)" ]; then
- echo "[ERROR]: ${given_sudoers_file} is working now, wait a little and then try again later"
- return 2
- fi
- ret=0
- echo "[INFO]: to process editing sudoers file..."
-
- cp ${given_sudoers_file} ${given_sudoers_file}.tmp
-
- chmod 0640 ${given_sudoers_file}.tmp
- cat ${given_sudoers_file}.tmp | grep 'includedir /etc/sudoers.d' > /dev/null
- if [ $? = 0 ]; then
- echo "[INFO]: '#includedir /etc/sudoers.d' already exists in /etc/sudoers file"
- else
- echo "#includedir /etc/sudoers.d" >> ${given_sudoers_file}.tmp
- ret=1
- fi
- if [ "`cat /etc/sudoers|grep ${given_user}|grep ALL=(ALL)`" != "" ]; then
- echo "[WARN]: sudoers file has been loaded up all(all) config"
- else
- new_entry="${given_user} ALL=(ALL) ALL"
- echo "${new_entry}" >> ${given_sudoers_file}.tmp
- ret=1
- fi
- if [ "`cat /etc/sudoers|grep ${given_user}|grep Run`" != "" ]; then
- echo "[WARN]: sudoers file has been loaded up rvc config"
- else
- new_entry="${given_user} ALL=(ALL) NOPASSWD: /opt/Run/version/*, NOPASSWD: /bin/sh, NOPASSWD: /bin/bash"
- echo "${new_entry}" >> ${given_sudoers_file}.tmp
- ret=1
- fi
- chmod 0440 ${given_sudoers_file}.tmp
- if visudo -c -f ${given_sudoers_file}.tmp ; then
- echo check syntax correct on ${given_sudoers_file}
- else
- echo "[ERROR]: syntax check failed on file ${given_sudoers_file}"
- rm ${given_sudoers_file}.tmp
- return 3
- fi
- if [ $ret -eq 1 ]; then
- echo "[SUCCESS]: config file has been change !!"
- cp ${given_sudoers_file} ${given_sudoers_file}.backup.${curr_timestamp}
- mv ${given_sudoers_file}.tmp ${given_sudoers_file}
- else
- echo "[WARN]: config file not change"
- rm ${given_sudoers_file}.tmp
- fi
- return $ret
- }
- res=0
- if [ "$1" = "configure" ]; then
- rvc_user=$USER
- sudoers_file=/etc/sudoers
- if [ -z "$rvc_user" -o "$rvc_user" = "root" ]; then
- users=$(cat /etc/passwd | awk -F: '$3>=500' | cut -f 1 -d :)
- echo "user list: $users"
- cnt=0
- for var in $(echo ${users} | awk '{split($0,arr,",");for(i in arr) print arr[i]}')
- do
- if [ ${var} != 'nobody' -a ${var} != 'systemd-coredump' ]; then
- cnt=$((${cnt}+1))
- rvc_user=${var}
- fi
- done
- if [ $cnt -ne 1 ]; then
- echo "too many users: $cnt"
- rvc_user=''
- else
- echo "aim user: $rvc_user"
- fi
- fi
- if [ -z "$rvc_user" ]; then
- echo "[ERROR]: username is empty, please use cmd 'dpkg -i {.deb file} to install'"
- exit 1
- elif [ "$rvc_user" = "root" ]; then
- echo "[ERROR]: username is invalid, please use cmd 'dpkg -i {.deb file} to install'"
- exit 2
- fi
- echo "[INFO]: Going to add entry into /etc/sudoers file for user: $rvc_user"
- if [ ! -d '/etc/sudoers.d' ]; then
- mkidr /etc/sudoers.d
- chmod 750 /etc/sudoers.d
- fi
- sudo_priviledge ${rvc_user} ${sudoers_file}
- res=$?
- if [ $res -eq 0 ]; then
- echo "[INFO]: Copy application icon to menu tools..."
- cp /opt/rvc/Resources/RVCTerminalApp.desktop /usr/share/applications
- echo "[INFO]: Active application icon autorun after boot..."
- cp /opt/rvc/Resources/RVCTerminalApp.desktop /etc/xdg/autostart/
- echo "[INFO]: Copy application icon to desktop..."
- cp /opt/rvc/Resources/RVCTerminalApp.desktop /home/$rvc_user/Desktop
- fi
- fi
- exit $res
|