mirror of
https://github.com/myvesta/vesta
synced 2025-08-19 21:04:07 -07:00
Create v-move-folder-and-make-symlink
This commit is contained in:
parent
d0f5d1a355
commit
cab6df399a
1 changed files with 85 additions and 0 deletions
85
bin/v-move-folder-and-make-symlink
Normal file
85
bin/v-move-folder-and-make-symlink
Normal file
|
@ -0,0 +1,85 @@
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# info:
|
||||||
|
# This script will move a folder to the new destination and make a symlink from the old path to the new destination
|
||||||
|
|
||||||
|
# options: FROMFOLDER TOFOLDER
|
||||||
|
|
||||||
|
#----------------------------------------------------------#
|
||||||
|
# Variable&Function #
|
||||||
|
#----------------------------------------------------------#
|
||||||
|
|
||||||
|
whoami=$(whoami)
|
||||||
|
if [ "$whoami" != "root" ] && [ "$whoami" != "admin" ] ; then
|
||||||
|
echo "You must be root or admin to execute this script";
|
||||||
|
exit 1;
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Argument definition
|
||||||
|
FROMFOLDER=$1
|
||||||
|
TOFOLDER=$2
|
||||||
|
|
||||||
|
# Includes
|
||||||
|
source $VESTA/func/main.sh
|
||||||
|
|
||||||
|
#----------------------------------------------------------#
|
||||||
|
# Verifications #
|
||||||
|
#----------------------------------------------------------#
|
||||||
|
|
||||||
|
# Trimming the ending slash, just in case
|
||||||
|
FROMFOLDER=$(echo "$FROMFOLDER" | sed 's:/*$::')
|
||||||
|
TOFOLDER=$(echo "$TOFOLDER" | sed 's:/*$::')
|
||||||
|
|
||||||
|
if [ ! -d "$FROMFOLDER" ]; then
|
||||||
|
echo "Folder $FROMFOLDER does not exists, aborting"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
USER=$(stat -c '%U' "$FROMFOLDER")
|
||||||
|
GROUP=$(stat -c '%G' "$FROMFOLDER")
|
||||||
|
PARENTFOLDER=$(dirname "$TOFOLDER")
|
||||||
|
|
||||||
|
if [ ! -d "$PARENTFOLDER" ]; then
|
||||||
|
PUSER=$(stat -c '%U' "$PARENTFOLDER")
|
||||||
|
PGROUP=$(stat -c '%G' "$PARENTFOLDER")
|
||||||
|
echo "= Creating parent folder..."
|
||||||
|
mkdir -p $PARENTFOLDER
|
||||||
|
chown $PUSER:$PGROUP $PARENTFOLDER
|
||||||
|
fi
|
||||||
|
|
||||||
|
#----------------------------------------------------------#
|
||||||
|
# Action #
|
||||||
|
#----------------------------------------------------------#
|
||||||
|
|
||||||
|
rsync -a "$FROMFOLDER/" "$TOFOLDER/"
|
||||||
|
# with slashes on the end of the path of both folders
|
||||||
|
if [ "$?" -ne 0 ]; then
|
||||||
|
echo "Error happened, aborting"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ "$FROMFOLDER" = "/home/$USER" ] && [ -d "$FROMFOLDER/conf" ]; then
|
||||||
|
# if we are moving myVesta home folder, we must remove immutable attribute from conf/ files
|
||||||
|
chattr -R -i "$FROMFOLDER/conf/" > /dev/null 2>&1
|
||||||
|
# with slashes on the end of the path of the folder
|
||||||
|
fi
|
||||||
|
|
||||||
|
rm -rf "$FROMFOLDER"
|
||||||
|
# without slash on the end of the path of the folder
|
||||||
|
|
||||||
|
ln -s "$TOFOLDER" "$FROMFOLDER"
|
||||||
|
# without slashes on the end of the path of both folders
|
||||||
|
|
||||||
|
chown -h $USER:$GROUP $FROMFOLDER
|
||||||
|
# without slash on the end of the path of the folder
|
||||||
|
|
||||||
|
#----------------------------------------------------------#
|
||||||
|
# Log and print result #
|
||||||
|
#----------------------------------------------------------#
|
||||||
|
|
||||||
|
echo "Done, folder $FROMFOLDER moved to $TOFOLDER and symlinked"
|
||||||
|
|
||||||
|
# Logging
|
||||||
|
log_event "$OK" "$ARGUMENTS"
|
||||||
|
|
||||||
|
exit
|
Loading…
Add table
Add a link
Reference in a new issue