install.sh 13 KB

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