postinst 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. #!/bin/sh
  2. echo "============== post installation custom scripts start: $*=============="
  3. curr_timestamp=`date "+%Y%m%d-%H%M%S.%3N"`
  4. lightdm_file=/etc/lightdm/lightdm.conf
  5. rvc_install_path_root="/opt"
  6. rvc_install_path_rvc_dir=${rvc_install_path_root}/rvc
  7. rvc_install_path_Run_dir=${rvc_install_path_root}/Run
  8. rvc_install_path_hardware_dir=${rvc_install_path_Run_dir}/hardwarecfg
  9. rvc_install_path_versions_dir=${rvc_install_path_Run_dir}/version
  10. setup_autologin()
  11. {
  12. given_user=$1
  13. given_sudoers_file=$2
  14. if [ ! -f "$given_sudoers_file" ]; then
  15. echo "[Seat:*]" > $given_sudoers_file
  16. # echo "autologin-guest=false" >> $given_sudoers_file
  17. echo "autologin-user=$given_user" >> $given_sudoers_file
  18. echo "autologin-user-timeout=0" >> $given_sudoers_file
  19. fi
  20. if [ "$(grep -c "^\\s*autologin-user=${given_user}" $given_sudoers_file)" -gt 0 ]; then
  21. echo "autologin-user is already setted in ^lightdm.conf^"
  22. else
  23. echo "setting autologin-user in ^$given_sudoers_file^"
  24. #sed -i.bak -E "s|^#(autologin-user=).*|\\1$given_user|;s|^#(autologin-user-timeout=).*|\\0|" $given_sudoers_file
  25. sed -i "s/^\s*#\s*autologin-user=/autologin-user=/g;s/autologin-user=.*$/autologin-user=$given_user/g" $given_sudoers_file
  26. #sed -i "s/^#autologin-user=$/autologin-user=${given_user}/" $given_sudoers_file
  27. #sed -i "s/^#autologin-user-timeout=$/autologin-user-timeout=0/" $given_sudoers_file
  28. sed -i "s/^\s*#\s*autologin-user-timeout=/autologin-user-timeout=/g;s/autologin-user-timeout=.*$/autologin-user-timeout=0/g" $given_sudoers_file
  29. fi
  30. }
  31. sudo_priviledge() {
  32. given_user=$1
  33. given_sudoers_file=$2
  34. if [ -e ${given_sudoers_file}.tmp -o "$(pidof visudo)" ]; then
  35. echo "[ERROR]: ${given_sudoers_file} is working now, wait a little and then try again later"
  36. return 2
  37. fi
  38. ret=0
  39. echo "[INFO]: to process editing sudoers file..."
  40. cp ${given_sudoers_file} ${given_sudoers_file}.tmp
  41. chmod 0640 ${given_sudoers_file}.tmp
  42. cat ${given_sudoers_file}.tmp | grep 'includedir /etc/sudoers.d' > /dev/null
  43. if [ $? = 0 ]; then
  44. echo "[INFO]: '#includedir /etc/sudoers.d' already exists in /etc/sudoers file"
  45. else
  46. echo "#includedir /etc/sudoers.d" >> ${given_sudoers_file}.tmp
  47. ret=1
  48. fi
  49. if [ "`cat /etc/sudoers|grep ${given_user}|grep ALL=(ALL)`" != "" ]; then
  50. echo "[WARN]: sudoers file has been loaded up all(all) config"
  51. else
  52. new_entry="${given_user} ALL=(ALL) ALL"
  53. echo "${new_entry}" >> ${given_sudoers_file}.tmp
  54. ret=1
  55. fi
  56. if [ "`cat /etc/sudoers|grep ${given_user}|grep Run`" != "" ]; then
  57. echo "[WARN]: sudoers file has been loaded up rvc config"
  58. else
  59. new_entry="${given_user} ALL=(ALL) NOPASSWD: /opt/Run/version/*, NOPASSWD: /bin/sh, NOPASSWD: /bin/bash"
  60. echo "${new_entry}" >> ${given_sudoers_file}.tmp
  61. ret=1
  62. fi
  63. chmod 0440 ${given_sudoers_file}.tmp
  64. if visudo -c -f ${given_sudoers_file}.tmp ; then
  65. echo check syntax correct on ${given_sudoers_file}
  66. else
  67. echo "[ERROR]: syntax check failed on file ${given_sudoers_file}"
  68. rm ${given_sudoers_file}.tmp
  69. return 3
  70. fi
  71. if [ $ret -eq 1 ]; then
  72. echo "[SUCCESS]: config file has been change !!"
  73. cp ${given_sudoers_file} ${given_sudoers_file}.backup.${curr_timestamp}
  74. mv ${given_sudoers_file}.tmp ${given_sudoers_file}
  75. ret=0
  76. else
  77. echo "[WARN]: config file not change"
  78. rm ${given_sudoers_file}.tmp
  79. ret=0
  80. fi
  81. return $ret
  82. }
  83. res=0
  84. if [ "$1" = "configure" ]; then
  85. rvc_user=$USER
  86. sudoers_file=/etc/sudoers
  87. if [ -z "$rvc_user" -o "$rvc_user" = "root" ]; then
  88. users=$(cat /etc/passwd | awk -F: '$3>=500' | cut -f 1 -d :)
  89. echo "user list: $users"
  90. cnt=0
  91. for var in $(echo ${users} | awk '{split($0,arr,",");for(i in arr) print arr[i]}')
  92. do
  93. if [ ${var} != 'nobody' -a ${var} != 'systemd-coredump' -a ${var} != 'liuwt' -a ${var} != 'deepin-anything-server' ]; then
  94. cnt=$((${cnt}+1))
  95. rvc_user=${var}
  96. fi
  97. done
  98. if [ $cnt -ne 1 ]; then
  99. echo "too many users: $cnt"
  100. rvc_user=''
  101. else
  102. echo "aim user: $rvc_user"
  103. fi
  104. fi
  105. if [ -z "$rvc_user" ]; then
  106. echo "[ERROR]: username is empty, please use cmd 'dpkg -i {.deb file} to install'"
  107. exit 1
  108. elif [ "$rvc_user" = "root" ]; then
  109. echo "[ERROR]: username is invalid, please use cmd 'dpkg -i {.deb file} to install'"
  110. exit 2
  111. fi
  112. echo "[INFO]: Going to add entry into /etc/sudoers file for user: $rvc_user"
  113. if [ ! -d '/etc/sudoers.d' ]; then
  114. mkidr /etc/sudoers.d
  115. chmod 750 /etc/sudoers.d
  116. fi
  117. sudo_priviledge ${rvc_user} ${sudoers_file}
  118. res=$?
  119. if [ $res -eq 0 ]; then
  120. echo "[INFO]: rm file under desktop directory..."
  121. rm -rf /home/$rvc_user/Desktop/* > /dev/null 2>&1
  122. echo "[INFO]: rm file under desktop directory done!"
  123. echo "[INFO]: setup user $rvc_user auto login.."
  124. setup_autologin ${rvc_user} ${lightdm_file}
  125. echo "[INFO]: Copy application icon to menu tools..."
  126. cp /opt/rvc/Resources/spexplorerauto.desktop /usr/share/applications
  127. echo "[INFO]: Active application icon autorun after boot..."
  128. cp /opt/rvc/Resources/spexplorerauto.desktop /etc/xdg/autostart/
  129. echo "[INFO]: Copy application icon to desktop..."
  130. cp /opt/rvc/Resources/spexplorerauto.desktop /home/$rvc_user/Desktop
  131. fi
  132. echo "[INFO]: change the run scripts priviledge..."
  133. chmod 777 ${rvc_install_path_root}
  134. chmod 777 -R ${rvc_install_path_Run_dir}
  135. chmod 777 -R ${rvc_install_path_rvc_dir}
  136. chmod 777 -R ${rvc_install_path_hardware_dir}
  137. chmod 777 ${rvc_install_path_versions_dir}/spexplorer.sh > /dev/null 2>&1
  138. chmod 777 ${rvc_install_path_versions_dir}/sudo_spexplorer.sh > /dev/null 2>&1
  139. chmod a+rw ${rvc_install_path_versions_dir}/active.txt
  140. echo "[INFO]: change the run scripts priviledge done!"
  141. keyring_file=/home/$rvc_user/.local/share/keyrings/login.keyring
  142. if [ -f "$keyring_file" ]; then
  143. rm $keyring_file
  144. echo "[INFO]: remove keyring file."
  145. fi
  146. echo "[INFO]: set menu tool as hidden mode..."
  147. gsettings set com.deepin.dde.dock hide-mode keep-hidden
  148. echo "[INFO]: set menu tool as hidden mode done!"
  149. fi
  150. exit $res