#!/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" $_cmd_su "cd $_site_path && git init" $_cmd_su "echo '/themes/' >> $_site_path/.gitignore" $_cmd_su "echo 'node_modules/' >> $_site_path/.gitignore" $_cmd_su "cd $_site_path && git add . && git commit -m 'initial commit'" 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" if [ -n "$_hugo_theme_git_url" ] ; then $_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 $_cmd_su "echo 'node_modules/' >> $_theme_path/.gitignore" $_cmd_su "cd $_theme_path && git add . && git commit -m 'initial commit'" else _theme_path='No theme installed' fi echo "" echo "#################################################################################################" echo "" tee $_site_path/README.txt << EOF Site directory: $_site_path Theme directory: $_theme_path BOTH directories have been initialised as git repositories. Build script: $_build_script_path Server script: $_serve_script_path Server URL: http://$_url EOF echo "" echo "#################################################################################################" echo "" chown "$_user": "$_site_path/README.txt"