installsub.in 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339
  1. #!/bin/bash
  2. MY_PATH="`dirname \"$0\"`" # relative
  3. # echo "1"$MY_PATH
  4. MY_PATH="`( cd \"$MY_PATH\" && pwd )`" # absolutized and normalized
  5. installType=@INSTALLSCRIPT_TYPE@
  6. echo 安装脚本模式: $installType
  7. curr_timestamp=`date "+%Y%m%d-%H%M%S.%3N"`
  8. lightdm_file=/etc/lightdm/lightdm.conf
  9. rvc_pkg_rvc=${MY_PATH}/rvc
  10. rvc_install_path_root="/opt"
  11. rvc_install_path_rvc_dir=${rvc_install_path_root}/rvc
  12. rvc_install_path_Run_dir=${rvc_install_path_root}/Run
  13. rvc_install_path_hardware_dir=${rvc_install_path_Run_dir}/hardwarecfg
  14. rvc_install_path_versions_dir=${rvc_install_path_Run_dir}/version
  15. res=0
  16. #设置开机自动登录用户(有做冗余判断)
  17. setup_autologin()
  18. {
  19. given_user=$1
  20. given_sudoers_file=$2
  21. ret=0
  22. if [ ! -f "$given_sudoers_file" ]; then
  23. echo "[Seat:*]" > $given_sudoers_file
  24. # echo "autologin-guest=false" >> $given_sudoers_file
  25. echo "autologin-user=$given_user" >> $given_sudoers_file
  26. echo "autologin-user-timeout=0" >> $given_sudoers_file
  27. fi
  28. if [ "$(grep -c "^\\s*autologin-user=${given_user}" $given_sudoers_file)" -gt 0 ]; then
  29. echo "[WARN] autologin-user is already setted in ^lightdm.conf^"
  30. else
  31. echo "[INFO] setting autologin-user in ^$given_sudoers_file^"
  32. #sed -i.bak -E "s|^#(autologin-user=).*|\\1$given_user|;s|^#(autologin-user-timeout=).*|\\0|" $given_sudoers_file
  33. sed -i "s/^\s*#\s*autologin-user=/autologin-user=/g;s/autologin-user=.*$/autologin-user=$given_user/g" $given_sudoers_file
  34. #sed -i "s/^#autologin-user=$/autologin-user=${given_user}/" $given_sudoers_file
  35. #sed -i "s/^#autologin-user-timeout=$/autologin-user-timeout=0/" $given_sudoers_file
  36. sed -i "s/^\s*#\s*autologin-user-timeout=/autologin-user-timeout=/g;s/autologin-user-timeout=.*$/autologin-user-timeout=0/g" $given_sudoers_file
  37. fi
  38. return $ret
  39. }
  40. #设置免密使用root权限(有做冗余判断)
  41. sudo_priviledge()
  42. {
  43. given_user=$1
  44. given_sudoers_file=$2
  45. if [ -e ${given_sudoers_file}.tmp -o "$(pidof visudo)" ]; then
  46. echo "[ERROR] ${given_sudoers_file} is working now, wait a little and then try again later"
  47. return 2
  48. fi
  49. #pkexec chmod 0440 /etc/sudoers
  50. ret=0
  51. echo "[INFO] to process editing sudoers file..."
  52. cp ${given_sudoers_file} ${given_sudoers_file}.tmp
  53. chmod 0640 ${given_sudoers_file}.tmp
  54. cat ${given_sudoers_file}.tmp | grep 'includedir /etc/sudoers.d' > /dev/null
  55. if [ $? = 0 ]; then
  56. echo "[INFO] '#includedir /etc/sudoers.d' already exists in /etc/sudoers file"
  57. else
  58. echo "#includedir /etc/sudoers.d" >> ${given_sudoers_file}.tmp
  59. ret=1
  60. fi
  61. if [ "`cat /etc/sudoers | grep ${given_user} | grep ALL=\(ALL\)`" != "" ]; then
  62. echo "[WARN]: sudoers file has been loaded up all(all) config"
  63. else
  64. new_entry="${given_user} ALL=(ALL) ALL"
  65. echo "${new_entry}" >> ${given_sudoers_file}.tmp
  66. ret=1
  67. fi
  68. if [ "`cat /etc/sudoers|grep ${given_user}|grep /opt/Run/version/v2`" != "" ]; then
  69. echo "[WARN]: sudoers file has been loaded up rvc config"
  70. else
  71. new_entry="${given_user} ALL=(ALL) NOPASSWD: ALL, NOPASSWD: /opt/Run/version/v2"
  72. echo "[INFO] update sudoers file with all no need password"
  73. echo "${new_entry}" >> ${given_sudoers_file}.tmp
  74. ret=1
  75. fi
  76. chmod 0440 ${given_sudoers_file}.tmp
  77. if visudo -c -f ${given_sudoers_file}.tmp ; then
  78. echo check syntax correct on ${given_sudoers_file}.tmp
  79. else
  80. echo "[ERROR] syntax check failed on file ${given_sudoers_file}"
  81. rm ${given_sudoers_file}.tmp
  82. #if [ -f "${given_sudoers_file}.backup" ]; then
  83. #fi
  84. return 3
  85. fi
  86. if [ $ret -eq 1 ]; then
  87. echo "[SUCCESS]: config file has been change !!"
  88. cp ${given_sudoers_file} ${given_sudoers_file}.backup
  89. mv ${given_sudoers_file}.tmp ${given_sudoers_file}
  90. ret=0
  91. else
  92. echo "[WARN]: config file not change"
  93. rm ${given_sudoers_file}.tmp
  94. ret=0
  95. fi
  96. return $ret
  97. }
  98. # check root priviledge
  99. if [ $(id -u) != 0 ]; then
  100. #红底白字
  101. echo -e "\033[41;37m [ERROR] === 该安装脚本需要以ROOT权限启动,请在命令行窗口添加sudo指令执行 'sudo bash $0',如果无法执行相关指令,请先确认系统已开启开发者模式 === \033[0m"
  102. timoutsecs=10
  103. for i in $(seq ${timoutsecs} -1 1)
  104. do
  105. echo [INFO] ${i}s 后退出当前执行脚本
  106. sleep 1
  107. done
  108. exit 1
  109. fi
  110. #避免遗漏,要求先安装浏览器再执行安装
  111. if [ "`dpkg -l | grep org.deepin.browser | awk '{print $3}'`" == "" ]; then
  112. echo -e "\033[41;37m [ERROR] 未安装指定的浏览器,请至下载站点下载并安装UOS浏览器后再执行此安装脚本! \033[0m"
  113. exit 1
  114. fi
  115. echo "[INFO] 清理可视柜台相关进程……"
  116. chromium_pid=$(ps -aux | grep mod_chromium | grep sphost | awk 'NR==1{print $2}')
  117. echo "[DEBUG] chromium_pid=$chromium_pid"
  118. timoutsecs4chromium=5
  119. if [ "${chromium_pid}" != "" ]; then
  120. echo "[INFO] has mod_chromium pid to SIGTERM it and wait"
  121. sudo kill -s 15 ${chromium_pid}
  122. for i in $(seq ${timoutsecs4chromium} -1 1)
  123. do
  124. echo "[DEBUG] wait chrmoium process exit"
  125. sleep 1
  126. chromium_pid=$(ps -aux | grep mod_chromium | grep sphost | awk 'NR==1{print $2}')
  127. if [ "${chromium_pid}" == "" ]; then
  128. echo "[INFO] chrmoium process has been exit"
  129. break
  130. fi
  131. done
  132. fi
  133. killall -9 spshell > /dev/null 2>&1
  134. killall -9 sphost > /dev/null 2>&1
  135. killall -9 guardian > /dev/null 2>&1
  136. killall -9 uosbrowser > /dev/null 2>&1
  137. killall -9 browser > /dev/null 2>&1
  138. killall -s 9 `ps -aux | grep browser | awk '{print $2}'` > /dev/null 2>&1
  139. echo "[INFO] 清理可视柜台相关进程OK!"
  140. #获取当前登录的用户名称,这里可以考虑用另外一种优化的方法
  141. echo [INFO] 获取当前登录的用户名
  142. rvc_user=$USER
  143. if [ -z "$rvc_user" -o "$rvc_user" = "root" ]; then
  144. users=$(cat /etc/passwd | awk -F: '$3>=500' | cut -f 1 -d :)
  145. echo "[DEBUG] user list: $users"
  146. cnt=0
  147. for var in $(echo ${users} | awk '{split($0,arr,",");for(i in arr) print arr[i]}')
  148. do
  149. if [ ${var} != 'nobody' -a ${var} != 'systemd-coredump' -a ${var} != 'liuwt' -a ${var} != 'deepin-anything-server' ]; then
  150. cnt=$((${cnt}+1))
  151. rvc_user=${var}
  152. fi
  153. done
  154. if [ $cnt -ne 1 ]; then
  155. echo "[WARN] too many users: $cnt"
  156. rvc_user=''
  157. else
  158. echo "[DEBUG] aim user: $rvc_user"
  159. fi
  160. fi
  161. #上保险,即另外一种优化的方法
  162. if [ -z "$rvc_user" -o "$rvc_user" = "root" ]; then
  163. name=$(whoami)
  164. pid=$(pgrep startdde)
  165. . <(xargs -0 bash -c 'printf "export %q\n" "$@"' -- </proc/$pid/environ)
  166. name=$(ps -o uname= -p "${pid}")
  167. echo "[DEBUG] new fetch name: $name"
  168. rvc_user=$name
  169. fi
  170. if [ -z "$rvc_user" ]; then
  171. echo -e "\033[41;37m [ERROR] 无法获取当前用户名称(用户名为空),退出程序 \033[0m"
  172. exit 1
  173. elif [ "$rvc_user" = "root" ]; then
  174. echo -e "\033[41;37m [ERROR] 无法获取当前用户名称(用户名无效),退出程序 \033[0m"
  175. exit 2
  176. fi
  177. echo [INFO] 获取当前登录的用户名OK! 用户名:$rvc_user
  178. echo 【0/1】拷贝RVC目录...
  179. if [ ! -d "${rvc_pkg_rvc}/Resources" ]; then
  180. echo -e "\033[41;37m [ERROR] Resources文件夹不存在,请检查安装包的合法性和完整性!!\033[0m"
  181. exit 1
  182. fi
  183. if [ ! -d $rvc_install_path_rvc_dir ]; then
  184. sudo mkdir -p ${rvc_install_path_rvc_dir}
  185. fi
  186. if [ ! -d $rvc_install_path_rvc_dir/Resources ]; then
  187. sudo mkdir -p ${rvc_install_path_rvc_dir}/Resources
  188. fi
  189. sudo cp -rf "${rvc_pkg_rvc}/Resources" ${rvc_install_path_rvc_dir}
  190. echo 【1/1】拷贝RVC目录OK!
  191. if [ ! -d "$MY_PATH/Run" ]; then
  192. echo -e "\033[41;37m [ERROR] Run版本文件夹不存在,请检查安装包的合法性和完整性!!\033[0m"
  193. exit 1
  194. fi
  195. if [ ! -d "$MY_PATH/Run/version" ]; then
  196. echo -e "\033[41;37m [ERROR] version文件夹不存在,请检查安装包的合法性和完整性!!\033[0m"
  197. exit 1
  198. fi
  199. if [ ! -d $rvc_install_path_Run_dir ]; then
  200. sudo mkdir -p ${rvc_install_path_Run_dir}
  201. fi
  202. echo 【1/2】拷贝终端版本,文件数量较多,部分终端拷贝时间比较长,请稍加等候......
  203. if [ -d "${MY_PATH}/Run/hardwarecfg" ]; then
  204. if [ ! -d $rvc_install_path_hardware_dir ]; then
  205. sudo mkdir -p ${rvc_install_path_hardware_dir}
  206. fi
  207. sudo cp -rf "$MY_PATH/Run/hardwarecfg" ${rvc_install_path_Run_dir}
  208. fi
  209. if [ ! -d $rvc_install_path_versions_dir ]; then
  210. sudo mkdir -p ${rvc_install_path_versions_dir}
  211. fi
  212. sudo cp -rf "$MY_PATH/Run/version" ${rvc_install_path_Run_dir}
  213. echo 【2/2】拷贝终端版本OK!
  214. echo [INFO] 赋予应用相关文件执行权限
  215. sudo chmod 777 ${rvc_install_path_root}
  216. sudo chmod a+rw -R ${rvc_install_path_rvc_dir}
  217. sudo chmod a+rw -R ${rvc_install_path_hardware_dir} > /dev/null 2>&1
  218. sudo chmod 777 -R ${rvc_install_path_root}/${rel_version_dir}
  219. sudo chmod 777 ${rvc_install_path_versions_dir}/spexplorer.sh > /dev/null 2>&1
  220. sudo chmod a+rw ${rvc_install_path_versions_dir}/active.txt
  221. sudo chmod a+rw ${rvc_install_path_versions_dir}
  222. sudo chmod a+rw ${rvc_install_path_Run_dir}
  223. echo [INFO] 赋予应用相关文件执行权限OK!
  224. echo 【2/3】拷贝系统桌面壁纸,用于后续安装
  225. papers_dir=/usr/share/wallpapers/deepin
  226. papers_bak_dir=/usr/share/wallpapers/deepin_bak
  227. WallpaperPath=${rvc_install_path_rvc_dir}/Resources/WallPaper1920.png
  228. if [ -f "${papers_dir}/WallPaper1920.png" ]; then
  229. echo [DEBUG] 指定壁纸已存在系统目录
  230. WallpaperPath=${papers_dir}/WallPaper1920.png
  231. rm ${papers_dir}/WallPaper1280.png > /dev/null 2>&1
  232. else
  233. if [ ! -f "${rvc_install_path_rvc_dir}/Resources/WallPaper1920.png" ]; then
  234. echo -e "\033[41;37m [ERROR] 壁纸资源文件不存在,请检查安装包的合法性和完整性!! \033[0m"
  235. exit 1
  236. fi
  237. if [ ! -d $papers_bak_dir ]; then
  238. mkdir -p ${papers_bak_dir}
  239. cp $papers_dir/* $papers_bak_dir
  240. fi
  241. rm -rf $papers_dir/* > /dev/null 2>&1
  242. cp "${rvc_install_path_rvc_dir}/Resources/WallPaper1920.png" ${papers_dir}
  243. WallpaperPath=${papers_dir}/WallPaper1920.png
  244. fi
  245. echo [DEBUG] WallpaperPath=$WallpaperPath
  246. echo [WARN] 清理桌面文件内容
  247. rm -rf /home/$rvc_user/Desktop/* > /dev/null 2>&1
  248. echo [INFO] 清理桌面文件内容OK!
  249. echo 【3/3】拷贝系统桌面壁纸OK!
  250. echo 【3/4】设置可视柜台应用程序开机自启动
  251. echo [INFO] 设置用户免密使用ROOT权限
  252. sudoers_file=/etc/sudoers
  253. echo "[INFO] Going to add entry into /etc/sudoers file for user: $rvc_user"
  254. if [ ! -d '/etc/sudoers.d' ]; then
  255. mkidr /etc/sudoers.d
  256. chmod 750 /etc/sudoers.d
  257. fi
  258. sudo_priviledge ${rvc_user} ${sudoers_file}
  259. res=$?
  260. if [ $res -eq 0 ]; then
  261. echo [INFO] 设置用户免密使用ROOT权限OK!
  262. else
  263. echo -e "\033[41;37m [ERROR] 设置用户免密使用ROOT权限失败!! \033[0m"
  264. exit 1
  265. fi
  266. echo [INFO] 设置用户自动登录
  267. setup_autologin ${rvc_user} ${lightdm_file}
  268. res=$?
  269. if [ $res -eq 0 ]; then
  270. echo [INFO] 设置用户自动登录OK!
  271. else
  272. echo -e "\033[41;37m [ERROR] 设置用户自动登录失败!! \033[0m"
  273. exit 1
  274. fi
  275. echo [INFO] 设置应用自启动和桌面图标
  276. if [ ! -f "${rvc_install_path_rvc_dir}/Resources/spexplorerauto.desktop" ]; then
  277. echo -e "\033[41;37m [ERROR] 自启动快捷键资源文件不存在,请检查安装包的合法性和完整性!! \033[0m"
  278. exit 1
  279. fi
  280. if [ ! -f "/opt/Run/version/spexplorer.sh" ]; then
  281. echo -e "\033[41;37m [ERROR] 应用启动脚本文件不存在,请检查安装包的合法性和完整性!! \033[0m"
  282. exit 1
  283. fi
  284. echo [DEBUG] Copy application shortkeys to menu tools...
  285. cp "${rvc_install_path_rvc_dir}/Resources/spexplorerauto.desktop" /usr/share/applications
  286. echo [DEBUG] Active application icon autorun after boot...
  287. cp "${rvc_install_path_rvc_dir}/Resources/spexplorerauto.desktop" /etc/xdg/autostart/
  288. echo [DEBUG] Copy application icon to desktop...
  289. cp "${rvc_install_path_rvc_dir}/Resources/spexplorerauto.desktop" /home/$rvc_user/Desktop
  290. echo 【4/4】设置可视柜台应用程序开机自启动OK!
  291. #去掉密钥环,之前出现过这种问题,统信指示移除该文件即可
  292. keyring_file=/home/$rvc_user/.local/share/keyrings/login.keyring
  293. if [ -f "$keyring_file" ]; then
  294. rm $keyring_file
  295. echo "[INFO] remove keyring file."
  296. fi
  297. keyring_file=/home/$rvc_user/.local/share/deepin-keyrings-wb/login.keyring
  298. if [ -f "$keyring_file" ]; then
  299. rm $keyring_file
  300. echo "[INFO] remove keyring file."
  301. fi
  302. #执行完删除自身
  303. rm -f $0
  304. exit 0