Follow symlink, ensure destination directory exists

This commit is contained in:
southerntofu 2020-04-24 14:53:38 -04:00
parent 17bfae349c
commit 3c2abfe485
1 changed files with 15 additions and 7 deletions

22
zola
View File

@ -34,8 +34,12 @@ build_to () {
exit 2 exit 2
fi fi
[ ! -d $DEST ] && mkdir $DEST if [ ! -d $DEST ]; then
echo "Creating missing directory"
mkdir $DEST || echo "FAILED." && exit 3
fi
cp -R public/* $DEST/ cp -R public/* $DEST/
[[ $? != 0 ]] && echo "Failed to copy project to $DEST" && exit 4
rm -R public rm -R public
} }
@ -47,9 +51,10 @@ if [ -f $GITBUILDCONF/$1.baseurl ]; then
base_url="$(url_template $1 $GITBUILDCONF/$1.baseurl)" base_url="$(url_template $1 $GITBUILDCONF/$1.baseurl)"
fi fi
if [ -f $GITBUILDCONF/$1.basedir ]; then # Follow the symlink to make sure it's a directory
if [ -L $GITBUILDCONF/$1.basedir ]; then
dest="$(readlink -e $GITBUILDCONF/$1.basedir)"
SINGLE=1 SINGLE=1
dest="$(cat $GITBUILDCONF/$1.basedir)"
fi fi
if [[ $SINGLE = 1 ]]; then if [[ $SINGLE = 1 ]]; then
@ -64,7 +69,7 @@ if [[ $SINGLE = 1 ]]; then
fi fi
base_url="https://$(cat $GITBUILDCONF/hostname)/~$USER/$1" base_url="https://$(cat $GITBUILDCONF/hostname)/~$USER/$1"
fi fi
[ -z $dest ] && dest=$HOME/public_html/$1 [ -z $dest ] && echo "Project has specific base_url but no basedir. Building to ~/public_html/$1" && dest=$HOME/public_html/$1
# BUILD # BUILD
build_to $dest -u $base_url build_to $dest -u $base_url
exit $? exit $?
@ -96,10 +101,13 @@ fi
FAILED=0 FAILED=0
for t in $GITBUILDCONF/*.target.baseurl; do for t in $GITBUILDCONF/*.target.baseurl; do
t_name="$(basename $t .target.baseurl)" t_name="$(basename $t .target.baseurl)"
dest=$GITBUILDCONF/$t_name.target.basedir
echo "[$1] Found target $t_name" echo "[$1] Found target $t_name"
# Check if basedir is symbolic link (hopefully to a real dir)
if [ ! -h $dest ]; then dest=$GITBUILDCONF/$t_name.target.basedir
# Follow symlink
[ -L $dest ] && dest="$(readlink -e $dest)"
if [ ! -d $dest ]; then
echo "ERROR: no $dest. Skipping $1:$t_name" echo "ERROR: no $dest. Skipping $1:$t_name"
continue continue
fi fi