#!/bin/bash MY_PATH="`dirname \"$0\"`" # relative # echo "1"$MY_PATH MY_PATH="`( cd \"$MY_PATH\" && pwd )`" # absolutized and normalized installType=@INSTALLSCRIPT_TYPE@ echo 安装脚本模式: $installType curr_timestamp=`date "+%Y%m%d-%H%M%S.%3N"` lightdm_file=/etc/lightdm/lightdm.conf rvc_pkg_rvc=${MY_PATH}/rvc 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 res=0 #设置开机自动登录用户(有做冗余判断) setup_autologin() { given_user=$1 given_sudoers_file=$2 ret=0 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 "[WARN] autologin-user is already setted in ^lightdm.conf^" else echo "[INFO] 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 return $ret } #设置免密使用root权限(有做冗余判断) 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 #pkexec chmod 0440 /etc/sudoers 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 /opt/Run/version/v2`" != "" ]; then echo "[WARN]: sudoers file has been loaded up rvc config" else new_entry="${given_user} ALL=(ALL) NOPASSWD: ALL, NOPASSWD: /opt/Run/version/v2" echo "[INFO] update sudoers file with all no need password" 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}.tmp else echo "[ERROR] syntax check failed on file ${given_sudoers_file}" rm ${given_sudoers_file}.tmp #if [ -f "${given_sudoers_file}.backup" ]; then #fi return 3 fi if [ $ret -eq 1 ]; then echo "[SUCCESS]: config file has been change !!" cp ${given_sudoers_file} ${given_sudoers_file}.backup 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 } # check root priviledge if [ $(id -u) != 0 ]; then #红底白字 echo -e "\033[41;37m [ERROR] === 该安装脚本需要以ROOT权限启动,请在命令行窗口添加sudo指令执行 'sudo bash $0',如果无法执行相关指令,请先确认系统已开启开发者模式 === \033[0m" timoutsecs=10 for i in $(seq ${timoutsecs} -1 1) do echo [INFO] ${i}s 后退出当前执行脚本 sleep 1 done exit 1 fi #避免遗漏,要求先安装浏览器再执行安装 if [ "`dpkg -l | grep org.deepin.browser | awk '{print $3}'`" == "" ]; then echo -e "\033[41;37m [ERROR] 未安装指定的浏览器,请至下载站点下载并安装UOS浏览器后再执行此安装脚本! \033[0m" exit 1 fi echo "[INFO] 清理可视柜台相关进程……" chromium_pid=$(ps -aux | grep mod_chromium | grep sphost | awk 'NR==1{print $2}') echo "[DEBUG] chromium_pid=$chromium_pid" timoutsecs4chromium=5 if [ "${chromium_pid}" != "" ]; then echo "[INFO] has mod_chromium pid to SIGTERM it and wait" sudo kill -s 15 ${chromium_pid} for i in $(seq ${timoutsecs4chromium} -1 1) do echo "[DEBUG] wait chrmoium process exit" sleep 1 chromium_pid=$(ps -aux | grep mod_chromium | grep sphost | awk 'NR==1{print $2}') if [ "${chromium_pid}" == "" ]; then echo "[INFO] chrmoium process has been exit" break fi done fi killall -9 spshell > /dev/null 2>&1 killall -9 sphost > /dev/null 2>&1 killall -9 guardian > /dev/null 2>&1 killall -9 uosbrowser > /dev/null 2>&1 killall -9 browser > /dev/null 2>&1 killall -s 9 `ps -aux | grep browser | awk '{print $2}'` > /dev/null 2>&1 echo "[INFO] 清理可视柜台相关进程OK!" #获取当前登录的用户名称,这里可以考虑用另外一种优化的方法 echo [INFO] 获取当前登录的用户名 rvc_user=$USER if [ -z "$rvc_user" -o "$rvc_user" = "root" ]; then users=$(cat /etc/passwd | awk -F: '$3>=500' | cut -f 1 -d :) echo "[DEBUG] 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 "[WARN] too many users: $cnt" rvc_user='' else echo "[DEBUG] aim user: $rvc_user" fi fi #上保险,即另外一种优化的方法 if [ -z "$rvc_user" -o "$rvc_user" = "root" ]; then name=$(whoami) pid=$(pgrep startdde) . <(xargs -0 bash -c 'printf "export %q\n" "$@"' -- /dev/null 2>&1 sudo chmod 777 -R ${rvc_install_path_root}/${rel_version_dir} sudo chmod 777 ${rvc_install_path_versions_dir}/spexplorer.sh > /dev/null 2>&1 sudo chmod a+rw ${rvc_install_path_versions_dir}/active.txt sudo chmod a+rw ${rvc_install_path_versions_dir} sudo chmod a+rw ${rvc_install_path_Run_dir} echo [INFO] 赋予应用相关文件执行权限OK! echo 【2/3】拷贝系统桌面壁纸,用于后续安装 papers_dir=/usr/share/wallpapers/deepin papers_bak_dir=/usr/share/wallpapers/deepin_bak WallpaperPath=${rvc_install_path_rvc_dir}/Resources/WallPaper1920.png if [ -f "${papers_dir}/WallPaper1920.png" ]; then echo [DEBUG] 指定壁纸已存在系统目录 WallpaperPath=${papers_dir}/WallPaper1920.png rm ${papers_dir}/WallPaper1280.png > /dev/null 2>&1 else if [ ! -f "${rvc_install_path_rvc_dir}/Resources/WallPaper1920.png" ]; then echo -e "\033[41;37m [ERROR] 壁纸资源文件不存在,请检查安装包的合法性和完整性!! \033[0m" exit 1 fi if [ ! -d $papers_bak_dir ]; then mkdir -p ${papers_bak_dir} cp $papers_dir/* $papers_bak_dir fi rm -rf $papers_dir/* > /dev/null 2>&1 cp "${rvc_install_path_rvc_dir}/Resources/WallPaper1920.png" ${papers_dir} WallpaperPath=${papers_dir}/WallPaper1920.png fi echo [DEBUG] WallpaperPath=$WallpaperPath echo [WARN] 清理桌面文件内容 rm -rf /home/$rvc_user/Desktop/* > /dev/null 2>&1 echo [INFO] 清理桌面文件内容OK! echo 【3/3】拷贝系统桌面壁纸OK! echo 【3/4】设置可视柜台应用程序开机自启动 echo [INFO] 设置用户免密使用ROOT权限 sudoers_file=/etc/sudoers 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] 设置用户免密使用ROOT权限OK! else echo -e "\033[41;37m [ERROR] 设置用户免密使用ROOT权限失败!! \033[0m" exit 1 fi echo [INFO] 设置用户自动登录 setup_autologin ${rvc_user} ${lightdm_file} res=$? if [ $res -eq 0 ]; then echo [INFO] 设置用户自动登录OK! else echo -e "\033[41;37m [ERROR] 设置用户自动登录失败!! \033[0m" exit 1 fi echo [INFO] 设置应用自启动和桌面图标 if [ ! -f "${rvc_install_path_rvc_dir}/Resources/spexplorerauto.desktop" ]; then echo -e "\033[41;37m [ERROR] 自启动快捷键资源文件不存在,请检查安装包的合法性和完整性!! \033[0m" exit 1 fi if [ ! -f "/opt/Run/version/spexplorer.sh" ]; then echo -e "\033[41;37m [ERROR] 应用启动脚本文件不存在,请检查安装包的合法性和完整性!! \033[0m" exit 1 fi echo [DEBUG] Copy application shortkeys to menu tools... cp "${rvc_install_path_rvc_dir}/Resources/spexplorerauto.desktop" /usr/share/applications echo [DEBUG] Active application icon autorun after boot... cp "${rvc_install_path_rvc_dir}/Resources/spexplorerauto.desktop" /etc/xdg/autostart/ echo [DEBUG] Copy application icon to desktop... cp "${rvc_install_path_rvc_dir}/Resources/spexplorerauto.desktop" /home/$rvc_user/Desktop echo 【4/4】设置可视柜台应用程序开机自启动OK! #去掉密钥环,之前出现过这种问题,统信指示移除该文件即可 keyring_file=/home/$rvc_user/.local/share/keyrings/login.keyring if [ -f "$keyring_file" ]; then rm $keyring_file echo "[INFO] remove keyring file." fi keyring_file=/home/$rvc_user/.local/share/deepin-keyrings-wb/login.keyring if [ -f "$keyring_file" ]; then rm $keyring_file echo "[INFO] remove keyring file." fi #执行完删除自身 rm -f $0 exit 0