Skip to content

Commit

Permalink
site_link: Support for custom path and public dir
Browse files Browse the repository at this point in the history
  • Loading branch information
lukasbestle committed May 31, 2020
1 parent e9bd0ac commit 723dba4
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions bin/site_link
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,20 @@
########################################################################
# Creates a link for the webserver pointing a domain to a site.
#
# Usage: site_link <site> <domain>
# Usage: site_link <site> <domain> [<path>]
#
# <site> Name of the site (directory in ~/web/sites/)
# <domain> FQDN of the domain (like "example.com")
# <path> Optional destination path for the link
# If not given, the destination will be the "current"
# directory of the site. If the current site directory
# has a "public" directory on the top level, it will
# be the destination of the domain link.
########################################################################

site="$1"
domain="$2"
path="$3"

if [[ -z "$domain" ]]; then
# Print help
Expand All @@ -38,9 +44,18 @@ if [[ -e "$HOME/web/$domain" ]]; then
exit 1
fi

# Determine the link destination if not given
if [[ -z "$path" ]]; then
if [[ -d "$HOME/web/sites/$site/current/public" ]]; then
path="current/public"
else
path="current"
fi
fi

# Create link
echo -e "\033[1mCreating link from site \033[34m$site\033[0;1m to domain \033[34m$domain\033[0;1m...\033[0m"
if ! ln -s "sites/$site/current" "$HOME/web/$domain"; then
echo -e "\033[1mCreating link from site \033[34m$site\033[0;1m (path \033[34m$path\033[0;1m) to domain \033[34m$domain\033[0;1m...\033[0m"
if ! ln -s "sites/$site/$path" "$HOME/web/$domain"; then
echo -e " => \033[31mCould not create link at \033[34m$HOME/web/$domain\033[31m.\033[0m" >&2
exit 1
fi
Expand Down

0 comments on commit 723dba4

Please sign in to comment.