Skip to content

Commit d26cc7e

Browse files
authored
- Check if user contains an email in case it is optimal - Check if v-add-web-domain runs successfully if not exit
1 parent 5a4cb6c commit d26cc7e

File tree

1 file changed

+29
-10
lines changed

1 file changed

+29
-10
lines changed

bin/v-import-cpanel

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,12 @@
1212
# - Importing certificates fails at the moment. Due to format changes of CPanel side
1313
# - It doesn't update DKIM
1414

15-
# shellcheck source=/etc/hestiacp/hestia.conf
16-
source /etc/hestiacp/hestia.conf
1715
# shellcheck source=/usr/local/hestia/func/main.sh
1816
source $HESTIA/func/main.sh
17+
# shellcheck source=/etc/hestiacp/hestia.conf
18+
source /etc/hestiacp/hestia.conf
19+
# load config file
20+
source_conf "$HESTIA/conf/hestia.conf"
1921

2022
if [ $# -lt 1 ]; then
2123
echo "usage: bash $0 cpanel-backup.tar.gz"
@@ -107,7 +109,15 @@ fi
107109
# Create a new user
108110
tmp_passwd=$(generate_password)
109111
email=$(cat ./cp/$new_user | grep CONTACTEMAIL= | cut -f2 -d'=')
112+
if [ -z "$email" ]; then
113+
# Hestia does not like email to be set to an empty string
114+
email="info@"$(hostname)
115+
fi
110116
$BIN/v-add-user "$new_user" "$tmp_passwd" "$email" "$hestia_package"
117+
if [ "$?" -ne 0 ]; then
118+
echo "Unable to create user"
119+
exit 1
120+
fi
111121
# Restore user password
112122
update_user_value "$new_user" 'MD5' "$(cat shadow)"
113123
$BIN/v-rebuild-user "$new_user"
@@ -174,12 +184,11 @@ echo "Converting addons domains, subdomains and some other fun"
174184
cp sds hst_sds
175185
cp sds2 hst_sds2
176186
sed -i 's/_/./g' hst_sds
177-
cat addons | while read ddon_domain addon_sub
178-
do
179-
echo "Converting default subdomain: $addon_sub in domain: $addon_domain"
180-
sed -i -e "s/$addon_sub/$addon_domain/g" hst_sds
181-
sed -i -e "s/$addon_sub/$addon_domain/g" hst_sds2
182-
mv userdata/$addon_sub userdata/${addon_domain}
187+
cat addons | while read ddon_domain addon_sub; do
188+
echo "Converting default subdomain: $addon_sub in domain: $addon_domain"
189+
sed -i -e "s/$addon_sub/$addon_domain/g" hst_sds
190+
sed -i -e "s/$addon_sub/$addon_domain/g" hst_sds2
191+
mv userdata/$addon_sub userdata/${addon_domain}
183192
done
184193
sed -i 's/public_html/public@html/g; s/_/./g; s/public@html/public_html/g; s/=/ /g' hst_sds2
185194

@@ -190,7 +199,11 @@ function get_domain_path() {
190199
while read cp_domain path; do
191200
echo "Import $cp_domain"
192201
if [ -e userdata/$cp_domain ]; then
202+
echo $cp_domain
193203
$BIN/v-add-domain "$new_user" "$cp_domain"
204+
if [ $? -ne 0 ]; then
205+
check_result "1" "Unable to create domain it allready exists"
206+
fi
194207
rm -f /home/$new_user/web/$cp_domain/public_html/index.html
195208
rm -f /home/$new_user/web/$cp_domain/public_html/robots.txt
196209
sync_count=0
@@ -206,7 +219,13 @@ function get_domain_path() {
206219
}
207220
get_domain_path < hst_sds2
208221

209-
/usr/local/hestia/bin/v-add-domain $new_user $main_domain1
222+
echo $main_domain1
223+
$BIN/v-add-domain $new_user $main_domain1
224+
225+
if [ $? -ne 0 ]; then
226+
check_result "1" "Unable to create domain it allready exists"
227+
fi
228+
210229
# need it for restore main domain
211230
if [ ! -e exclude_path ]; then
212231
touch exclude_path
@@ -238,7 +257,7 @@ for folder in *; do
238257
echo "Domain: $folder"
239258
cd $folder
240259
for mail_account in *; do
241-
echo "Import mail account: $mail_account@#$folder"
260+
echo "Import mail account: $mail_account@$folder"
242261
# Doesn't really matter but we don't know the unhashed one
243262
tmp_pass=$(generate_password)
244263
$BIN/v-add-mail-account $new_user $folder $mail_account $tmp_pass

0 commit comments

Comments
 (0)