diff --git a/dietpi/dietpi-software b/dietpi/dietpi-software index d74fe303f0..6e23b5af3e 100755 --- a/dietpi/dietpi-software +++ b/dietpi/dietpi-software @@ -1018,6 +1018,12 @@ Available commands: aSOFTWARE_DOCS[$software_id]='https://dietpi.com/docs/software/social/#wordpress' aSOFTWARE_DEPS[$software_id]='88 89 webserver' #------------------ + software_id=176 + aSOFTWARE_NAME[$software_id]='Hugo' + aSOFTWARE_DESC[$software_id]='A static-site generator for building websites' + aSOFTWARE_CATX[$software_id]=6 + aSOFTWARE_DOCS[$software_id]='https://dietpi.com/docs/software/social/#hugo' + #------------------ software_id=38 aSOFTWARE_NAME[$software_id]='FreshRSS' aSOFTWARE_DESC[$software_id]='self-hosted RSS feed aggregator' @@ -7058,6 +7064,121 @@ _EOF_ /boot/dietpi/func/create_mysql_db wordpress wordpress "$GLOBAL_PW" fi + if To_Install 176 # Hugo + then + local hugo_dir=/mnt/dietpi_userdata/hugo + local hugo_sitename=mysite + + G_AGI hugo + G_EXEC mkdir -p "$hugo_dir" + Create_User -d "$hugo_dir" hugo + + G_EXEC cd "$hugo_dir" + if ! [[ -d "${hugo_dir}/${hugo_sitename}" ]]; then + G_EXEC hugo new site "${hugo_sitename}" -f toml + fi + G_EXEC cd "${hugo_dir}/${hugo_sitename}" + if ! [[ -d themes/paper ]]; then + Download_Install "https://github.com/nanxiaobei/hugo-paper/archive/master.tar.gz" "${hugo_dir}/${hugo_sitename}" + G_EXEC mv "${hugo_dir}/${hugo_sitename}/hugo-paper-main" "${hugo_dir}/${hugo_sitename}/themes/paper" + fi + + cat << _EOF_ > /etc/default/hugo +# Environment variables read by systemd service file /etc/systemd/system/hugo.service +## Toml config path to point to +HUGO_SITEPATH="${hugo_dir}/${hugo_sitename}" +## Domain or address +HUGO_BASEURL="http://$(G_GET_NET ip)" +## Server config +HUGO_PORT="8141" +HUGO_LISTEN="0.0.0.0" +## Inherited by hugo.toml +HUGO_THEME="paper" +_EOF_ + + ## Create a default config with a default theme + cat << _EOF_ > "${hugo_dir}"/"${hugo_sitename}"/hugo.toml +title = "DietPi Initial Blog" +languageCode = 'en-us' + +[markup.goldmark.renderer] + unsafe = true + +_EOF_ + + ## Create a systemd file + cat << '_EOF_' > /etc/systemd/system/hugo.service +[Unit] +Description=Hugo Static Webserver service +Wants=network-online.target +After=network-online.target + +[Service] +EnvironmentFile=/etc/default/hugo +SyslogIdentifier=Hugo +User=hugo +LogsDirectory=hugo +WorkingDirectory=/mnt/dietpi_userdata/hugo/ +ExecStart=/usr/bin/hugo server -s "${HUGO_SITEPATH}" -p "${HUGO_PORT}" -b "${HUGO_BASEURL}" -t "${HUGO_THEME}" --bind "${HUGO_LISTEN}" --buildDrafts --navigateToChanged + +[Install] +WantedBy=multi-user.target + +_EOF_ + + ## Create first post + G_EXEC mkdir -p "${hugo_dir}/${hugo_sitename}/content/posts/" + cat << _EOF_ > "${hugo_dir}/${hugo_sitename}/content/posts/first.md" +--- +title: "First Post" +date: $(date +%Y-%m-%d) +draft: false +--- +# The website is up! + +This is the first post, which was generated by running the command + + cd /mnt/dietpi_userdata/hugo/${hugo_sitename}/ + sudo -u hugo hugo new posts/name-of-post.md + ## Note that the '.md' extension is important + +You can then modify the file with a text or markdown editor, and it will +update in real time. e.g. + + sudo -u hugo nano /mnt/dietpi_userdata/hugo/${hugo_sitename}/content/posts/name-of-post.md + +Please also see the [Quick Start](https://gohugo.io/getting-started/quick-start/) +guide for more configuration tips! + +This also allows you to **push** markdown snippets to your DietPi. e.g. + + rsync random-note.md dietpi@my.website.com:/mnt/dietpi_userdata/hugo/${hugo_sitename}/content/posts/ + +## Extras + +If you are an Emacs fan, you can use the +[ox-hugo](https://ox-hugo.scripter.co/doc/installation/) package to +export an org-mode sub-tree as a post, allowing you to blog on-the-fly +from your editor! + +# Configuration + +Hugo's themes can be changed by editing the "/mnt/dietpi_userdata/hugo/${hugo_sitename}/config.toml" file +See the [Configuration Guide](https://gohugo.io/getting-started/configuration/) for inspiration. + +## Configure a new blog + +If you want your own blog with a different theme and content, just clone the existing and modify the config.toml + + cp -rv /mnt/dietpi_userdata/hugo/${hugo_sitename} /mnt/dietpi_userdata/hugo/my_own_blog + ## then edit: /mnt/dietpi_userdata/hugo/my_own_blog/config.toml + +You will also need to update the default blog name (e.g. "my_own_blog") in the "/etc/default/hugo" file, and then restart the hugo service. + +_EOF_ + G_EXEC chown hugo: -R "$hugo_dir" + fi + if To_Install 38 # FreshRSS then # Install required PHP modules: https://github.com/FreshRSS/FreshRSS#requirements @@ -13185,6 +13306,14 @@ _EOF_ Remove_Database wordpress fi + if To_Uninstall 176 # Hugo + then + Remove_Service hugo + G_AGP hugo + ## Do not remove user post data + ## [[ -d '/mnt/dietpi_userdata/hugo' ]] && G_EXEC rm -R /mnt/dietpi_userdata/hugo + fi + if To_Uninstall 38 # FreshRSS then crontab -u www-data -l | grep -v '/opt/FreshRSS/app/actualize_script.php' | crontab -u www-data -