original.sh 13 KB

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