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