install.sh 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. #! /usr/bin/env bash
  2. THEME='poly-dark'
  3. LANG='English'
  4. # Change to temporary directory
  5. cd $(mktemp -d)
  6. # Pre-authorise sudo
  7. sudo echo
  8. # Select language, optional
  9. declare -A LANGS=(
  10. [Chinese]=zh_CN
  11. [English]=EN
  12. [French]=FR
  13. [German]=DE
  14. [Italian]=IT
  15. [Norwegian]=NO
  16. [Portuguese]=PT
  17. [Russian]=RU
  18. [Spanish]=ES
  19. [Ukrainian]=UA
  20. )
  21. LANG_NAMES=($(echo ${!LANGS[*]} | tr ' ' '\n' | sort -n))
  22. PS3='Please select language #: '
  23. select l in "${LANG_NAMES[@]}"
  24. do
  25. if [[ -v LANGS[$l] ]]
  26. then
  27. LANG=$l
  28. break
  29. else
  30. echo 'No such language, try again'
  31. fi
  32. done < /dev/tty
  33. # Detect distro and set GRUB location and update method
  34. GRUB_DIR='grub'
  35. UPDATE_GRUB=''
  36. if [ -e /etc/os-release ]; then
  37. source /etc/os-release
  38. if [[ "$ID" =~ (debian|ubuntu|solus) || \
  39. "$ID_LIKE" =~ (debian|ubuntu) ]]; then
  40. UPDATE_GRUB='update-grub'
  41. elif [[ "$ID" =~ (arch|gentoo) || \
  42. "$ID_LIKE" =~ (archlinux|gentoo) ]]; then
  43. UPDATE_GRUB='grub-mkconfig -o /boot/grub/grub.cfg'
  44. elif [[ "$ID" =~ (centos|fedora|opensuse) || \
  45. "$ID_LIKE" =~ (fedora|rhel|suse) ]]; then
  46. GRUB_DIR='grub2'
  47. UPDATE_GRUB='grub2-mkconfig -o /boot/grub2/grub.cfg'
  48. fi
  49. fi
  50. echo 'Fetching theme archive'
  51. wget -O ${THEME}.zip https://github.com/shvchk/${THEME}/archive/master.zip
  52. echo 'Unpacking theme'
  53. unzip ${THEME}.zip
  54. if [[ "$LANG" != "English" ]]
  55. then
  56. echo "Changing language to ${LANG}"
  57. sed -i -r -e '/^\s+# EN$/{n;s/^(\s*)/\1# /}' \
  58. -e '/^\s+# '"${LANGS[$LANG]}"'$/{n;s/^(\s*)#\s*/\1/}' ${THEME}-master/theme.txt
  59. fi
  60. echo 'Creating GRUB themes directory'
  61. sudo mkdir -p /boot/${GRUB_DIR}/themes/${THEME}
  62. echo 'Copying theme to GRUB themes directory'
  63. sudo cp -r ${THEME}-master/* /boot/${GRUB_DIR}/themes/${THEME}
  64. echo 'Removing other themes from GRUB config'
  65. sudo sed -i '/^GRUB_THEME=/d' /etc/default/grub
  66. echo 'Making sure GRUB uses graphical output'
  67. sudo sed -i 's/^\(GRUB_TERMINAL\w*=.*\)/#\1/' /etc/default/grub
  68. echo 'Removing empty lines at the end of GRUB config' # optional
  69. sudo sed -i -e :a -e '/^\n*$/{$d;N;};/\n$/ba' /etc/default/grub
  70. echo 'Adding new line to GRUB config just in case' # optional
  71. echo | sudo tee -a /etc/default/grub
  72. echo 'Adding theme to GRUB config'
  73. echo "GRUB_THEME=/boot/${GRUB_DIR}/themes/${THEME}/theme.txt" | sudo tee -a /etc/default/grub
  74. echo 'Removing theme installation files'
  75. rm -rf ${THEME}.zip ${THEME}-master
  76. echo 'Updating GRUB'
  77. if [[ $UPDATE_GRUB ]]; then
  78. eval sudo "$UPDATE_GRUB"
  79. else
  80. cat << ' EOF'
  81. --------------------------------------------------------------------------------
  82. Cannot detect your distro, you will need to run `grub-mkconfig` (as root) manually.
  83. Common ways:
  84. - Debian, Ubuntu, Solus and derivatives: `update-grub` or `grub-mkconfig -o /boot/grub/grub.cfg`
  85. - RHEL, CentOS, Fedora, SUSE and derivatives: `grub2-mkconfig -o /boot/grub2/grub.cfg`
  86. - Arch, Gentoo and derivatives: `grub-mkconfig -o /boot/grub/grub.cfg`
  87. --------------------------------------------------------------------------------
  88. EOF
  89. fi