This repository has been archived on 2020-04-08. You can view files and clone it, but cannot push or open issues or pull requests.
install-scripts/dev-setup/hugo.sh

57 lines
1.5 KiB
Bash
Executable File

#!/bin/sh
set -e
_cmd_su="su --login $_user -c"
_site_path="/home/$_user/$_hugo_site_name"
_theme_path="$_site_path/themes/$_hugo_theme_name"
_serve_script_path="$_site_path/hugo-serve.sh"
_build_script_path="$_site_path/hugo-build.sh"
if ! command -v hugo ; then
if command -v apt-get ; then
wget https://github.com/gohugoio/hugo/releases/download/v"$_hugo_version"/hugo_extended_"$_hugo_version"_"$_hugo_distro"bit.deb -O /tmp/hugo.deb
apt-get install /tmp/hugo.deb
else
echo 'hugo.sh: Error - no installation method available for `hugo` executable'
exit 1;
fi
fi
if command -v yarn ; then
$_cmd_su 'yarn global add postcss-cli autoprefixer'
else
echo 'hugo.sh: Error - `yarn` executable not found'
exit 1
fi
$_cmd_su "cd ~ && hugo new site $_hugo_site_name"
if [ -z "$_hugo_theme_git_url" ] ; then
exit
fi
$_cmd_su "git clone $_hugo_theme_git_url $_theme_path"
$_cmd_su " rm -Rf $_theme_path/.git"
$_cmd_su "cd $_theme_path && git init"
$_cmd_su "cd $_theme_path && yarn install"
echo "theme = \"$_hugo_theme_name\"" >> $_site_path/config.toml
echo "#!/bin/sh" > "$_serve_script_path"
echo 'echo "sudo required to bind to port 80"' >> "$_serve_script_path"
echo "sudo hugo server -D --bind=0.0.0.0 --baseURL=http://$_url -p80" >> "$_serve_script_path"
chown "$_user": "$_serve_script_path"
chmod +x "$_serve_script_path"
cat << EOF > "$_build_script_path"
#!/bin/sh
touch ./public
rm -R ./public
hugo -v
EOF
chown "$_user": "$_build_script_path"
chmod +x "$_build_script_path"