#!/bin/sh echo "============== post installation custom scripts start: $*==============" curr_timestamp=`date "+%Y%m%d-%H%M%S.%3N"` lightdm_file=/etc/lightdm/lightdm.conf rvc_install_path_root="/opt" rvc_install_path_rvc_dir=${rvc_install_path_root}/rvc rvc_install_path_Run_dir=${rvc_install_path_root}/Run rvc_install_path_hardware_dir=${rvc_install_path_Run_dir}/hardwarecfg rvc_install_path_versions_dir=${rvc_install_path_Run_dir}/version setup_autologin() { given_user=$1 given_sudoers_file=$2 if [ ! -f "$given_sudoers_file" ]; then echo "[Seat:*]" > $given_sudoers_file # echo "autologin-guest=false" >> $given_sudoers_file echo "autologin-user=$given_user" >> $given_sudoers_file echo "autologin-user-timeout=0" >> $given_sudoers_file fi if [ "$(grep -c "^\\s*autologin-user=${given_user}" $given_sudoers_file)" -gt 0 ]; then echo "autologin-user is already setted in ^lightdm.conf^" else echo "setting autologin-user in ^$given_sudoers_file^" #sed -i.bak -E "s|^#(autologin-user=).*|\\1$given_user|;s|^#(autologin-user-timeout=).*|\\0|" $given_sudoers_file sed -i "s/^\s*#\s*autologin-user=/autologin-user=/g;s/autologin-user=.*$/autologin-user=$given_user/g" $given_sudoers_file #sed -i "s/^#autologin-user=$/autologin-user=${given_user}/" $given_sudoers_file #sed -i "s/^#autologin-user-timeout=$/autologin-user-timeout=0/" $given_sudoers_file sed -i "s/^\s*#\s*autologin-user-timeout=/autologin-user-timeout=/g;s/autologin-user-timeout=.*$/autologin-user-timeout=0/g" $given_sudoers_file fi } 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} ret=0 else echo "[WARN]: config file not change" rm ${given_sudoers_file}.tmp ret=0 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' -a ${var} != 'liuwt' -a ${var} != 'deepin-anything-server' ]; 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]: rm file under desktop directory..." rm -rf /home/$rvc_user/Desktop/* > /dev/null 2>&1 echo "[INFO]: rm file under desktop directory done!" echo "[INFO]: setup user $rvc_user auto login.." setup_autologin ${rvc_user} ${lightdm_file} echo "[INFO]: Copy application icon to menu tools..." cp /opt/rvc/Resources/spexplorerauto.desktop /usr/share/applications echo "[INFO]: Active application icon autorun after boot..." cp /opt/rvc/Resources/spexplorerauto.desktop /etc/xdg/autostart/ echo "[INFO]: Copy application icon to desktop..." cp /opt/rvc/Resources/spexplorerauto.desktop /home/$rvc_user/Desktop fi echo "[INFO]: change the run scripts priviledge..." chmod 777 ${rvc_install_path_root} chmod 777 -R ${rvc_install_path_Run_dir} chmod 777 -R ${rvc_install_path_rvc_dir} chmod 777 -R ${rvc_install_path_hardware_dir} chmod 777 ${rvc_install_path_versions_dir}/spexplorer.sh > /dev/null 2>&1 chmod 777 ${rvc_install_path_versions_dir}/sudo_spexplorer.sh > /dev/null 2>&1 chmod a+rw ${rvc_install_path_versions_dir}/active.txt echo "[INFO]: change the run scripts priviledge done!" keyring_file=/home/$rvc_user/.local/share/keyrings/login.keyring if [ -f "$keyring_file" ]; then rm $keyring_file echo "[INFO]: remove keyring file." fi echo "[INFO]: set menu tool as hidden mode..." gsettings set com.deepin.dde.dock hide-mode keep-hidden echo "[INFO]: set menu tool as hidden mode done!" fi exit $res