myvesta/bin/v-change-dir-www
2024-12-03 15:50:07 +01:00

72 lines
1.8 KiB
Bash

#!/bin/bash
# info: Change directory to the public_html folder of a domain
# usage: source v-cd-www DOMAIN
#----------------------------------------------------------#
# Variable&Function #
#----------------------------------------------------------#
if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then
echo "This script must be sourced to change the current directory."
echo "Usage: source v-cd-www DOMAIN"
exit 1
fi
whoami=$(whoami)
if [ "$whoami" != "root" ]; then
echo "You must be root to execute this script"
return 1
fi
# Importing system environment
source /etc/profile
PATH=$PATH:/usr/local/vesta/bin && export PATH
SILENT_MODE=1
# Argument definition
domain=$1
user=$(/usr/local/vesta/bin/v-search-domain-owner $domain)
if [ -z "$user" ]; then
echo "Domain $domain doesn't exist"
return 1
fi
USER=$user
# Includes
source /usr/local/vesta/func/main.sh
source /usr/local/vesta/func/domain.sh
#----------------------------------------------------------#
# Verifications #
#----------------------------------------------------------#
check_args '1' "$#" 'DOMAIN'
is_format_valid 'domain'
is_object_valid 'user' 'USER' "$user"
if [ ! -d "/home/$user" ]; then
echo "User $user doesn't exist"
return 1
fi
if [ ! -d "/home/$user/web/$domain/public_html" ]; then
echo "Domain $domain doesn't have a public_html directory"
return 1
fi
#----------------------------------------------------------#
# Action #
#----------------------------------------------------------#
cd "/home/$user/web/$domain/public_html"
#----------------------------------------------------------#
# Vesta #
#----------------------------------------------------------#
return 0