installsh.in 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394
  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. function set-title() {
  6. if [[ -z "$ORIG" ]]; then
  7. ORIG=$PS1
  8. fi
  9. TITLE="\[\e]2;$*\a\]"
  10. PS1=${ORIG}${TITLE}
  11. }
  12. set-title 【可视柜台应用程序安装脚本】
  13. clear
  14. installType=@INSTALLSCRIPT_TYPE@
  15. echo "[RVCTermianal] === Install Start === "
  16. echo 安装脚本模式: $installType
  17. curr_timestamp=`date "+%Y%m%d-%H%M%S.%3N"`
  18. lightdm_file=/etc/lightdm/lightdm.conf
  19. rvc_pkg_rvc=${MY_PATH}/rvc
  20. rvc_install_path_root="/opt"
  21. rvc_install_path_rvc_dir=${rvc_install_path_root}/rvc
  22. rvc_install_path_Run_dir=${rvc_install_path_root}/Run
  23. rvc_install_path_hardware_dir=${rvc_install_path_Run_dir}/hardwarecfg
  24. rvc_install_path_versions_dir=${rvc_install_path_Run_dir}/version
  25. res=0
  26. #设置开机自动登录用户(有做冗余判断)
  27. setup_autologin()
  28. {
  29. given_user=$1
  30. given_sudoers_file=$2
  31. if [ ! -f "$given_sudoers_file" ]; then
  32. echo "[Seat:*]" > $given_sudoers_file
  33. # echo "autologin-guest=false" >> $given_sudoers_file
  34. echo "autologin-user=$given_user" >> $given_sudoers_file
  35. echo "autologin-user-timeout=0" >> $given_sudoers_file
  36. fi
  37. if [ "$(grep -c "^\\s*autologin-user=${given_user}" $given_sudoers_file)" -gt 0 ]; then
  38. echo "autologin-user is already setted in ^lightdm.conf^"
  39. else
  40. echo "setting autologin-user in ^$given_sudoers_file^"
  41. #sed -i.bak -E "s|^#(autologin-user=).*|\\1$given_user|;s|^#(autologin-user-timeout=).*|\\0|" $given_sudoers_file
  42. sed -i "s/^\s*#\s*autologin-user=/autologin-user=/g;s/autologin-user=.*$/autologin-user=$given_user/g" $given_sudoers_file
  43. #sed -i "s/^#autologin-user=$/autologin-user=${given_user}/" $given_sudoers_file
  44. #sed -i "s/^#autologin-user-timeout=$/autologin-user-timeout=0/" $given_sudoers_file
  45. sed -i "s/^\s*#\s*autologin-user-timeout=/autologin-user-timeout=/g;s/autologin-user-timeout=.*$/autologin-user-timeout=0/g" $given_sudoers_file
  46. fi
  47. }
  48. #设置免密使用root权限(有做冗余判断)
  49. sudo_priviledge()
  50. {
  51. given_user=$1
  52. given_sudoers_file=$2
  53. if [ -e ${given_sudoers_file}.tmp -o "$(pidof visudo)" ]; then
  54. echo "[ERROR]: ${given_sudoers_file} is working now, wait a little and then try again later"
  55. return 2
  56. fi
  57. ret=0
  58. echo "[INFO]: to process editing sudoers file..."
  59. cp ${given_sudoers_file} ${given_sudoers_file}.tmp
  60. chmod 0640 ${given_sudoers_file}.tmp
  61. cat ${given_sudoers_file}.tmp | grep 'includedir /etc/sudoers.d' > /dev/null
  62. if [ $? = 0 ]; then
  63. echo "[INFO]: '#includedir /etc/sudoers.d' already exists in /etc/sudoers file"
  64. else
  65. echo "#includedir /etc/sudoers.d" >> ${given_sudoers_file}.tmp
  66. ret=1
  67. fi
  68. if [ "`cat /etc/sudoers | grep ${given_user} | grep ALL=\(ALL\)`" != "" ]; then
  69. echo "[WARN]: sudoers file has been loaded up all(all) config"
  70. else
  71. new_entry="${given_user} ALL=(ALL) ALL"
  72. echo "${new_entry}" >> ${given_sudoers_file}.tmp
  73. ret=1
  74. fi
  75. if [ "`cat /etc/sudoers|grep ${given_user}|grep Run`" != "" ]; then
  76. echo "[WARN]: sudoers file has been loaded up rvc config"
  77. else
  78. new_entry="${given_user} ALL=(ALL) NOPASSWD: /opt/Run/version/*, NOPASSWD: /bin/sh, NOPASSWD: /bin/bash"
  79. echo "${new_entry}" >> ${given_sudoers_file}.tmp
  80. ret=1
  81. fi
  82. chmod 0440 ${given_sudoers_file}.tmp
  83. if visudo -c -f ${given_sudoers_file}.tmp ; then
  84. echo check syntax correct on ${given_sudoers_file}.tmp
  85. else
  86. echo "[ERROR]: syntax check failed on file ${given_sudoers_file}"
  87. rm ${given_sudoers_file}.tmp
  88. #if [ -f "${given_sudoers_file}.backup" ]; then
  89. #fi
  90. return 3
  91. fi
  92. if [ $ret -eq 1 ]; then
  93. echo "[SUCCESS]: config file has been change !!"
  94. cp ${given_sudoers_file} ${given_sudoers_file}.backup
  95. mv ${given_sudoers_file}.tmp ${given_sudoers_file}
  96. ret=0
  97. else
  98. echo "[WARN]: config file not change"
  99. rm ${given_sudoers_file}.tmp
  100. ret=0
  101. fi
  102. return $ret
  103. }
  104. # check root priviledge
  105. if [ $(id -u) != 0 ]; then
  106. #红底白字
  107. echo -e "\033[41;37m [ERROR] === 该安装脚本需要以ROOT权限启动,请在命令行窗口添加sudo指令执行 'sudo bash $0',如果无法执行相关指令,请先确认系统已开启开发者模式 === \033[0m"
  108. echo "10 秒后退出"
  109. for i in $(seq 1 10);do echo $i 秒......; sleep 1s; done
  110. exit 0
  111. fi
  112. #获取当前登录的用户名称,这里可以考虑用另外一种优化的方法
  113. rvc_user=$USER
  114. if [ -z "$rvc_user" -o "$rvc_user" = "root" ]; then
  115. users=$(cat /etc/passwd | awk -F: '$3>=500' | cut -f 1 -d :)
  116. echo "user list: $users"
  117. cnt=0
  118. for var in $(echo ${users} | awk '{split($0,arr,",");for(i in arr) print arr[i]}')
  119. do
  120. if [ ${var} != 'nobody' -a ${var} != 'systemd-coredump' -a ${var} != 'liuwt' -a ${var} != 'deepin-anything-server' ]; then
  121. cnt=$((${cnt}+1))
  122. rvc_user=${var}
  123. fi
  124. done
  125. if [ $cnt -ne 1 ]; then
  126. echo "too many users: $cnt"
  127. rvc_user=''
  128. else
  129. echo "aim user: $rvc_user"
  130. fi
  131. fi
  132. #上保险,即另外一种优化的方法
  133. if [ -z "$rvc_user" -o "$rvc_user" = "root" ]; then
  134. name=$(whoami)
  135. exec="bash $ABS_CURRENT_PATH/sub_install_user.sh"
  136. pid=$(pgrep startdde)
  137. . <(xargs -0 bash -c 'printf "export %q\n" "$@"' -- </proc/$pid/environ)
  138. name=$(ps -o uname= -p "${pid}")
  139. echo new fetch name: $name
  140. rvc_user=$name
  141. fi
  142. if [ $installType -eq 4 ]; then
  143. rm /etc/xdg/autostart/spexplorerauto.desktop > /dev/null 2>&1
  144. rm /usr/share/applications/spexplorerauto.desktop > /dev/null 2>&1
  145. rm -rf /opt/rvc > /dev/null 2>&1
  146. rm -rf /opt/Run > /dev/null 2>&1
  147. rm -rf /opt/wlog > /dev/null 2>&1
  148. echo "[INFO]: set menu tool as show mode..."
  149. gsettings set com.deepin.dde.dock hide-mode keep-showing
  150. echo "[INFO]: set menu tool as show mode done!"
  151. papers_dir=/usr/share/wallpapers/deepin
  152. papers_bak_dir=/usr/share/wallpapers/deepin_bak
  153. if [ -d $papers_bak_dir ]; then
  154. rm -rf $papers_dir/* > /dev/null 2>&1
  155. cp $papers_bak_dir/* $papers_dir > /dev/null 2>&1
  156. rm -rf $papers_bak_dir > /dev/null 2>&1
  157. fi
  158. if [ -z "$rvc_user" ]; then
  159. echo -e "\033[41;37m [ERROR]: 无法获取当前用户名称(用户名为空),退出程序 \033[0m"
  160. exit 1
  161. elif [ "$rvc_user" = "root" ]; then
  162. echo -e "\033[41;37m [ERROR]: 无法获取当前用户名称(用户名无效),退出程序 \033[0m"
  163. exit 2
  164. fi
  165. rm /home/$rvc_user/Desktop/spexplorerauto.desktop > /dev/null 2>&1
  166. echo [INFO]恢复桌面组件应用程序的执行权限
  167. sudo chmod +x /usr/bin/dde-desktop
  168. sudo chmod +x /usr/bin/dde-dock
  169. echo -e "\033[42;37m [INFO]: === 所有安装步骤执行成功,正常退出=== \033[0m"
  170. exit 0
  171. fi
  172. echo "to clear the rvc terminal processes..."
  173. killall -9 spshell > /dev/null 2>&1
  174. killall -9 sphost > /dev/null 2>&1
  175. killall -9 guardian > /dev/null 2>&1
  176. killall -9 uosbrowser > /dev/null 2>&1
  177. killall -9 browser > /dev/null 2>&1
  178. killall -s 9 `ps -aux | grep browser | awk '{print $2}'` > /dev/null 2>&1
  179. echo "============== previous installation custom scripts start =============="
  180. user1=$(ps -o user= -p $$ | awk '{print $1}')
  181. echo "user1: $user1"
  182. user2=$(whoami)
  183. echo "user2: $user2"
  184. #user3=$(logname)
  185. #echo "user3: $user3"
  186. # 备份壁纸
  187. papers_dir=/usr/share/wallpapers/deepin
  188. papers_bak_dir=/usr/share/wallpapers/deepin_bak
  189. if [ -f "${papers_dir}/WallPaper1920.png" ]; then
  190. echo "[INFO]: CMB WallPaper has been exist, skip latter copy procedure"
  191. else
  192. if [ ! -d $papers_bak_dir ]; then
  193. mkdir -p ${papers_bak_dir}
  194. cp $papers_dir/* $papers_bak_dir
  195. fi
  196. rm -rf $papers_dir/* > /dev/null 2>&1
  197. cp ${rvc_pkg_rvc}/Resources/WallPaper1280.png ${papers_dir}
  198. cp ${rvc_pkg_rvc}/Resources/WallPaper1920.png ${papers_dir}
  199. fi
  200. echo "============== previous installation custom scripts done =============="
  201. echo "============== during installation custom scripts start =============="
  202. #拷贝终端版本
  203. # fetch the version full path at pkg
  204. version_dir=$(find ${MY_PATH}/Run/version/ -maxdepth 1 -regex ".*[0-9\.]$" -type d)
  205. echo version dir: $version_dir
  206. slen=${#MY_PATH}
  207. rel_version_dir=${version_dir:$slen+1}
  208. echo ${rel_version_dir}
  209. # 如果版本中有root.ini,移除测试的root.ini文件
  210. if [ -f ${MY_PATH}/Run/hardwarecfg/root.ini ]; then
  211. sudo rm ${MY_PATH}/Run/hardwarecfg/root.ini
  212. fi
  213. if [ -d ${MY_PATH}/Run/runinfo ]; then
  214. sudo rm -rf ${MY_PATH}/Run/runinfo
  215. fi
  216. if [ ! -f $rvc_install_path_hardware_dir/root.ini ]; then
  217. #delete /opt/Run
  218. sudo rm -rf ${rvc_install_path_Run_dir} > /dev/null 2>&1
  219. sudo rm -rf ${rvc_install_path_rvc_dir} > /dev/null 2>&1
  220. fi
  221. #copy the Run pkg to run path
  222. echo to copy Run package...
  223. if [ ! -d $rvc_install_path_Run_dir ]; then
  224. sudo mkdir -p ${rvc_install_path_Run_dir}
  225. fi
  226. sudo cp -rvf $MY_PATH/Run ${rvc_install_path_root}
  227. echo copy Run package completely!
  228. #copy the res pkg to rvc path
  229. echo to copy rvc Audio files...
  230. if [ ! -d $rvc_install_path_rvc_dir ]; then
  231. sudo mkdir -p ${rvc_install_path_rvc_dir}
  232. fi
  233. if [ ! -d $rvc_install_path_rvc_dir/adData ]; then
  234. sudo mkdir -p ${rvc_install_path_rvc_dir}/adData
  235. fi
  236. if [ ! -d $rvc_install_path_rvc_dir/Resources ]; then
  237. sudo mkdir -p ${rvc_install_path_rvc_dir}/Resources
  238. fi
  239. sudo cp -rvf $MY_PATH/rvc/adData/Audio ${rvc_install_path_rvc_dir}/adData
  240. echo copy rvc Audio files completely!
  241. #sudo cp -rvf $MY_PATH/rvc/adData/Video ${rvc_install_path_rvc_dir}/adData
  242. #echo copy rvc Video files completely!
  243. echo "[INFO]: Copy application icon to Resource dir..."
  244. cp ${rvc_pkg_rvc}/Resources/logo.png ${rvc_install_path_rvc_dir}/Resources
  245. echo "[INFO]: change the run scripts priviledge..."
  246. echo ${rvc_install_path_rvc_dir}
  247. echo ${rvc_install_path_root}/${rel_version_dir}
  248. sudo chmod 777 ${rvc_install_path_root}
  249. sudo chmod a+rw -R ${rvc_install_path_rvc_dir}
  250. sudo chmod a+rw -R ${rvc_install_path_hardware_dir}
  251. sudo chmod 777 -R ${rvc_install_path_root}/${rel_version_dir}
  252. sudo chmod 777 ${rvc_install_path_versions_dir}/spexplorer.sh
  253. sudo chmod 777 ${rvc_install_path_versions_dir}/sudo_spexplorer.sh
  254. sudo chmod a+rw ${rvc_install_path_versions_dir}/active.txt
  255. sudo chmod a+rw ${rvc_install_path_versions_dir}
  256. sudo chmod a+rw ${rvc_install_path_Run_dir}
  257. echo "[INFO]: change the run scripts priviledge done!"
  258. echo "============== during installation custom scripts done =============="
  259. echo "============== post installation custom scripts start =============="
  260. sudoers_file=/etc/sudoers
  261. if [ -z "$rvc_user" ]; then
  262. echo -e "\033[41;37m [ERROR]: 无法获取当前用户名称(用户名为空),退出程序 \033[0m"
  263. exit 1
  264. elif [ "$rvc_user" = "root" ]; then
  265. echo -e "\033[41;37m [ERROR]: 无法获取当前用户名称(用户名无效),退出程序 \033[0m"
  266. exit 2
  267. fi
  268. echo "[INFO]: Going to add entry into /etc/sudoers file for user: $rvc_user"
  269. if [ ! -d '/etc/sudoers.d' ]; then
  270. mkidr /etc/sudoers.d
  271. chmod 750 /etc/sudoers.d
  272. fi
  273. sudo_priviledge ${rvc_user} ${sudoers_file}
  274. res=$?
  275. if [ $res -eq 0 ]; then
  276. # 清理桌面数据
  277. echo "[INFO]: rm file under desktop directory..."
  278. rm -rf /home/$rvc_user/Desktop/* > /dev/null 2>&1
  279. echo "[INFO]: rm file under desktop directory done!"
  280. echo "[INFO]: setup user $rvc_user auto login.."
  281. setup_autologin ${rvc_user} ${lightdm_file}
  282. #设置桌面图标
  283. echo "[INFO]: Copy application shortkeys to menu tools..."
  284. cp ${rvc_pkg_rvc}/Resources/spexplorerauto.desktop /usr/share/applications
  285. echo "[INFO]: Active application icon autorun after boot..."
  286. cp ${rvc_pkg_rvc}/Resources/spexplorerauto.desktop /etc/xdg/autostart/
  287. echo "[INFO]: Copy application icon to desktop..."
  288. cp ${rvc_pkg_rvc}/Resources/spexplorerauto.desktop /home/$rvc_user/Desktop
  289. if [ $installType -eq 1 ]; then
  290. echo [INFO]去除桌面组件应用程序的执行权限,实现开机黑屏
  291. sudo chmod -x /usr/bin/dde-desktop
  292. sudo chmod -x /usr/bin/dde-dock
  293. fi
  294. else
  295. echo -e "\033[41;37m [ERROR]: 设置SUDO权限失败!! \033[0m"
  296. exit 1
  297. fi
  298. #去掉密钥环,之前出现过这种问题,统信指示移除该文件即可
  299. keyring_file=/home/$rvc_user/.local/share/keyrings/login.keyring
  300. if [ -f "$keyring_file" ]; then
  301. rm $keyring_file
  302. echo "[INFO]: remove keyring file."
  303. fi
  304. # 设置隐藏菜单栏
  305. echo "[INFO]: set menu tool as hidden mode..."
  306. gsettings set com.deepin.dde.dock hide-mode keep-hidden
  307. echo "[INFO]: set menu tool as hidden mode done!"
  308. browserDownURLDEV="http://99.12.23.78/uos/uosbrowser_5.3.52-1.zip"
  309. broswerDownPRD="http://ecsnp01.s3ecs.itcenter.cmbchina.cn:9020/lr18.24-upgrade-pack-prd/uosbrowser_5.3.52-1_22061501_02/origin/uosbrowser_5.3.52-1_22061501.zip?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Date=20240508T120010Z&X-Amz-SignedHeaders=host&X-Amz-Expires=604800&X-Amz-Credential=lr18.24-upgrade-prd%2F20240508%2Fcn-north-1%2Fs3%2Faws4_request&X-Amz-Signature=67950161ab9de5d35b7556a6fe4e8d102b1269cc72c22784f009d36d654d4413"
  310. browserDownURL=${browserDownURLDEV}
  311. if [ $installType -eq 0 ]; then
  312. echo ${browserDownURL}
  313. if [ "`dpkg -l | grep org.deepin.browser | awk '{print $3}'`" == "" ]; then
  314. echo "[WARN]: 未安装最新的UOS浏览器,将自动下载安装UOS浏览器"
  315. echo 下载最新的UOS浏览器...
  316. rm -rf ${MY_PATH}/Tmp > /dev/null 2>&1
  317. mkdir -p ${MY_PATH}/Tmp > /dev/null 2>&1
  318. mkdir -p ${MY_PATH}/Tmp/Extra > /dev/null 2>&1
  319. wget -nv ${browserDownURL} -O ${MY_PATH}/Tmp/UOSBrowser.zip
  320. if [ $? -ne 0 ]; then
  321. echo "[WARN]下载最新的UOS浏览器失败"
  322. else
  323. echo 下载最新的UOS浏览器 完成!
  324. unzip -q ${MY_PATH}/Tmp/UOSBrowser.zip -d ${MY_PATH}/Tmp/Extra
  325. chmod 777 -R ${MY_PATH}/Tmp/Extra
  326. sudo dpkg -i ${MY_PATH}/Tmp/Extra/**/*.deb
  327. fi
  328. rm -rf ${MY_PATH}/Tmp > /dev/null 2>&1
  329. else
  330. echo "[INFO]: 已安装最新的UOS浏览器"
  331. fi
  332. fi
  333. echo "============== post installation custom scripts done =============="
  334. #绿底白字
  335. echo -e "\033[42;37m [INFO]: === 所有安装步骤执行成功,正常退出=== \033[0m"
  336. exit 0