sid_upgrade 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. #!/bin/sh
  2. #set -x
  3. clear
  4. ###
  5. #
  6. # Author: Stéphane HUC
  7. # mail: devs@stephane-huc.net
  8. #
  9. # License: GNU/GPL 3
  10. #
  11. # GitLab: https://framasoft.git/hucste/tools/
  12. #
  13. # Date: 2016/05/08
  14. #
  15. ###
  16. ###
  17. # Purpose: Upgrade Sid Debian; ./sid_upgrade
  18. ###
  19. mssg_info_reboot_sys="### The computer will be restart in few seconds ! ###"
  20. mssg_info_start_X="### Restart X: "
  21. mssg_info_stop_X="### Stop X:"
  22. mssg_ko_rights_admin="Need to get rights admins!"
  23. mssg_ko_start_X="A problem to start X is appear..."
  24. mssg_ko_stop_X="A problem to stop X is appear!"
  25. mssg_menu_reboot_sys="=> Do you want to reboot your system? "
  26. mssg_menu_start_X="=> Do you want to start X session? "
  27. mssg_menu_stop_X="=> Do you want to stop X session? "
  28. mssg_menu_upg_sys="=> Do you want to upgrade your system? "
  29. mssg_ok_start_X="X start correctly!"
  30. mssg_ok_stop_X="Server X stoped!"
  31. ### DO NOT TOUCH THOSES VARIABLES!
  32. apt="$(which apt)"
  33. [ -z "${apt}" ] && apt="$(which apt-get)"
  34. ###############################################################################
  35. ####
  36. ##
  37. # FUNCTIONS
  38. ##
  39. ###
  40. ###############################################################################
  41. confirm () {
  42. mssg="$(printf "%s" "$1" "$2")"
  43. read -r -p "${mssg} [y|n] " response
  44. case "$response" in
  45. y|Y|o|O|1)
  46. true
  47. ;;
  48. *)
  49. false
  50. ;;
  51. esac
  52. }
  53. display_mssg() {
  54. local statut="$1" info="$2" var="$3"
  55. case "${statut}" in
  56. "KO") printf "[ \033[0;31m%s\033[0;m ]\t%s\n" "${statut}" "${info}" ;;
  57. "OK") printf "[ \033[0;32m%s\033[0;m ]\t%s\n" "${statut}" "${info}" ;;
  58. *)
  59. if [ -n "${var}" ]; then
  60. printf "%s %s\n" "${info}" "${var}"
  61. else
  62. printf "%s\n" "${info}"
  63. fi
  64. ;;
  65. esac
  66. unset statut info var
  67. }
  68. start_session() {
  69. display_mssg "" "${mssg_info_start_X}"
  70. if init 5; then
  71. display_mssg "OK" "${mssg_ok_start_X}"
  72. else
  73. display_mssg "KO" "${mssg_ko_start_X}"
  74. stop
  75. fi
  76. }
  77. stop() {
  78. display_mssg "KO" "${mssg_ko_script}"
  79. exit 1;
  80. }
  81. stop_session() {
  82. display_mssg "" "${mssg_info_stop_X}"
  83. if init 3; then
  84. display_mssg "OK" "${mssg_ok_stop_X}"
  85. else
  86. display_mssg "KO" "${mssg_ko_stop_X}"
  87. stop
  88. fi
  89. }
  90. sys_clean() { apt-get clean; }
  91. sys_reboot() {
  92. display_mssg "" "${mssg_info_reboot_sys}"
  93. sleep 1
  94. shutdown -r now;
  95. }
  96. sys_upd() { $apt update; }
  97. sys_upg() {
  98. $apt full-upgrade
  99. [ $? -ne 0 ] && apt-get dist-upgrade
  100. #[ $? -eq 0 ] && sys_clean
  101. }
  102. verify_uid() {
  103. if [ $(id -u) -ne 0 ]; then
  104. display_mssg "KO" "${mssg_ko_rights_admin}"
  105. exit 1
  106. fi
  107. }
  108. verify_uid
  109. confirm "${mssg_menu_stop_X}" && stop_session || exit
  110. sleep 1
  111. sys_upd
  112. sleep 1
  113. confirm "${mssg_menu_upg_sys}" && sys_upg
  114. sleep 1
  115. confirm "${mssg_menu_start_X}" && start_session
  116. sleep 1
  117. confirm "${mssg_menu_reboot_sys}" && sys_reboot