Skip to content

Commit 755d528

Browse files
author
Kristan Kenney
committed
Add backend script to rename user packages
1 parent 2524c15 commit 755d528

File tree

1 file changed

+67
-0
lines changed

1 file changed

+67
-0
lines changed

bin/v-rename-package

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
#!/bin/bash
2+
# info: change package name
3+
# options: OLD_NAME NEW_NAME
4+
#
5+
# The function changes the name of an existing package.
6+
7+
8+
#----------------------------------------------------------#
9+
# Variable&Function #
10+
#----------------------------------------------------------#
11+
12+
# Argument definition
13+
old_name=$1
14+
new_name=$2
15+
16+
# Includes
17+
source $HESTIA/func/main.sh
18+
source $HESTIA/func/domain.sh
19+
source $HESTIA/conf/hestia.conf
20+
21+
22+
#----------------------------------------------------------#
23+
# Verifications #
24+
#----------------------------------------------------------#
25+
26+
# Ensure that package names have been passed to the script.
27+
if [ -z "$old_name" ]; then
28+
echo "ERROR: Current package name not specified."
29+
fi
30+
if [ -z "$new_name" ]; then
31+
echo "ERROR: New package name not specified."
32+
fi
33+
34+
# Perform verification if read-only mode is enabled
35+
check_hestia_demo_mode
36+
37+
38+
#----------------------------------------------------------#
39+
# Action #
40+
#----------------------------------------------------------#
41+
42+
if [ -e $HESTIA/data/packages/$old_name.pkg ]; then
43+
mv $HESTIA/data/packages/$old_name.pkg $HESTIA/data/packages/$new_name.pkg
44+
echo "Successfully renamed $old_name to $new_name."
45+
46+
# Update package for existing users
47+
for user in `ls $HESTIA/data/users/`; do
48+
OLD_PACKAGE=$(v-get-user-value $user PACKAGE)
49+
if [ "$old_name" = "$OLD_PACKAGE" ]; then
50+
echo "Updating package for user: $user..."
51+
v-change-user-package $user $new_name
52+
fi
53+
done
54+
else
55+
echo "ERROR: Specified package not found."
56+
fi
57+
58+
59+
#----------------------------------------------------------#
60+
# Hestia #
61+
#----------------------------------------------------------#
62+
63+
# Logging
64+
log_history "renamed package $old_name to $new_name"
65+
log_event "$OK" "$ARGUMENTS"
66+
67+
exit

0 commit comments

Comments
 (0)