v-add-sys-theme 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. #!/bin/bash
  2. # info: install theme from local source or GitHub.
  3. # options: THEME [MODE] [ACTIVE]
  4. # labels: hestia
  5. #
  6. # example: v-add-sys-theme myTheme local
  7. #
  8. # The function for installing a custom theme or downloading one
  9. # from the HestiaCP theme repository.
  10. # For more info see https://docs.hestiacp.com/customize_hestia.html
  11. #----------------------------------------------------------#
  12. # Variable&Function #
  13. #----------------------------------------------------------#
  14. # Argument definition
  15. theme=$1
  16. mode=$2
  17. active=$3
  18. # Includes
  19. source $HESTIA/func/main.sh
  20. source $HESTIA/conf/hestia.conf
  21. # Define themes repository URL format
  22. HESTIA_THEMES_REPO="$HESTIA_GIT_REPO/$RELEASE_BRANCH/install/deb/themes"
  23. #----------------------------------------------------------#
  24. # Action #
  25. #----------------------------------------------------------#
  26. # Fallback to downloading from GitHub if no mode specified
  27. if [ -z "$mode" ]; then
  28. mode="git"
  29. fi
  30. # Initialize local directory if it does not exist
  31. if [ ! -d "$HESTIA_THEMES_CUSTOM" ]; then
  32. mkdir -p $HESTIA_THEMES_CUSTOM
  33. fi
  34. # Abort if no theme name specified
  35. if [ -z "$theme" ]; then
  36. echo "ERROR: No theme name specified."
  37. echo "Usage: v-add-sys-theme theme [GIT | LOCAL] [ACTIVE]"
  38. echo " theme: name of the theme to install."
  39. echo " active: Set downloaded theme as active (optional)"
  40. exit 1
  41. fi
  42. # Check if theme name already exists as system theme
  43. if [ -e $HESTIA_THEMES/$theme.css ]; then
  44. echo "ERROR: System theme with the same name already exists: $theme."
  45. exit 1
  46. fi
  47. # Prompt to replace existing theme if detected
  48. if [ -e $HESTIA_THEMES_CUSTOM/$theme.css ]; then
  49. echo "WARNING: Theme file $theme.css already exists."
  50. read -p "Would you like to replace it? [Y/N] " replace_theme
  51. if [ "$replace_theme" = "N" ] || [ "$replace_theme" = "n" ]; then
  52. exit 1
  53. fi
  54. fi
  55. # Install theme from GitHub repository
  56. if [ "$mode" = "git" ]; then
  57. # Check if it's a valid file first
  58. theme_check=$(curl -s --head -w %{http_code} $HESTIA_THEMES_REPO/$theme.css -o /dev/null)
  59. if [ $theme_check -ne "200" ]; then
  60. echo "Error: invalid theme name specified."
  61. exit 1
  62. fi
  63. # Download the theme file from Git
  64. echo "Downloading and installing theme: $theme..."
  65. wget $HESTIA_THEMES_REPO/$theme.css -O $HESTIA_THEMES_CUSTOM/$theme.css > /dev/null 2>&1
  66. fi
  67. if [ "$mode" = "local" ]; then
  68. read -p "Please enter the full path to the CSS file to import: " theme_path
  69. cp -f $theme_path $HESTIA_THEMES_CUSTOM/
  70. fi
  71. # Set active theme
  72. $BIN/v-change-sys-theme $theme
  73. #----------------------------------------------------------#
  74. # Hestia #
  75. #----------------------------------------------------------#
  76. exit