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
fi
[ ! -d $DEST ] && mkdir $DEST
if [ ! -d $DEST ]; then
echo "Creating missing directory"
mkdir $DEST || echo "FAILED." && exit 3
fi
cp -R public/* $DEST/
[[ $? != 0 ]] && echo "Failed to copy project to $DEST" && exit 4
rm -R public
}
@ -47,9 +51,10 @@ if [ -f $GITBUILDCONF/$1.baseurl ]; then
base_url="$(url_template $1 $GITBUILDCONF/$1.baseurl)"
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
dest="$(cat $GITBUILDCONF/$1.basedir)"
fi
if [[ $SINGLE = 1 ]]; then
@ -64,7 +69,7 @@ if [[ $SINGLE = 1 ]]; then
fi
base_url="https://$(cat $GITBUILDCONF/hostname)/~$USER/$1"
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_to $dest -u $base_url
exit $?
@ -96,10 +101,13 @@ fi
FAILED=0
for t in $GITBUILDCONF/*.target.baseurl; do
t_name="$(basename $t .target.baseurl)"
dest=$GITBUILDCONF/$t_name.target.basedir
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"
continue
fi