From 55b513aed4898e42a9d69f2ba4f52cde29c3f63c Mon Sep 17 00:00:00 2001 From: Mehmet Tekman Date: Mon, 17 Jul 2023 17:27:30 +0200 Subject: [PATCH 1/4] add hugo static server shellfix common path to variable, removed git, extended first post real date added more information about configuration Update dietpi/dietpi-software new software id for hugo update readme first post dont remove user data on uninstall Added /etc/default/hugo env file that systemd can source hugo_sitename as a var --- dietpi/dietpi-software | 132 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 132 insertions(+) diff --git a/dietpi/dietpi-software b/dietpi/dietpi-software index d74fe303f0..098dc4175a 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,124 @@ _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_TITLE="DietPi Initial Blog" +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 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 +13309,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 - From 60c21943f24c1b57dba024b3aa06c1cac751cf05 Mon Sep 17 00:00:00 2001 From: Mehmet Tekman Date: Tue, 7 Oct 2025 23:51:18 +0100 Subject: [PATCH 2/4] shellcheck --- dietpi/dietpi-software | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/dietpi/dietpi-software b/dietpi/dietpi-software index 098dc4175a..d58da6c590 100755 --- a/dietpi/dietpi-software +++ b/dietpi/dietpi-software @@ -7075,7 +7075,7 @@ _EOF_ G_EXEC cd "$hugo_dir" if ! [[ -d "${hugo_dir}/${hugo_sitename}" ]]; then - G_EXEC hugo new site ${hugo_sitename} -f toml + G_EXEC hugo new site "${hugo_sitename}" -f toml fi G_EXEC cd "${hugo_dir}/${hugo_sitename}" if ! [[ -d themes/paper ]]; then @@ -7098,7 +7098,7 @@ HUGO_THEME="paper" _EOF_ ## Create a default config with a default theme - cat << _EOF_ > ${hugo_dir}/${hugo_sitename}/hugo.toml + cat << _EOF_ > "${hugo_dir}"/"${hugo_sitename}"/hugo.toml title = "DietPi Initial Blog" languageCode = 'en-us' @@ -7143,7 +7143,6 @@ This is the first post, which was generated by running the command 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 markdown editor, and it will update in real time. e.g. @@ -7175,7 +7174,6 @@ If you want your own blog with a different theme and content, just clone the exi 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_ From 8a43dac514f95ca2b7e1168cdfc754842facb3fa Mon Sep 17 00:00:00 2001 From: mtekman <20641402+mtekman@users.noreply.github.com> Date: Tue, 7 Oct 2025 23:58:39 +0100 Subject: [PATCH 3/4] unneeded var --- dietpi/dietpi-software | 1 - 1 file changed, 1 deletion(-) diff --git a/dietpi/dietpi-software b/dietpi/dietpi-software index d58da6c590..0b11b96f41 100755 --- a/dietpi/dietpi-software +++ b/dietpi/dietpi-software @@ -7093,7 +7093,6 @@ HUGO_BASEURL="http://$(G_GET_NET ip)" HUGO_PORT="8141" HUGO_LISTEN="0.0.0.0" ## Inherited by hugo.toml -HUGO_TITLE="DietPi Initial Blog" HUGO_THEME="paper" _EOF_ From adf469df5832eab8a7d288beffa95d1d78d466f2 Mon Sep 17 00:00:00 2001 From: mtekman <20641402+mtekman@users.noreply.github.com> Date: Tue, 7 Oct 2025 23:59:25 +0100 Subject: [PATCH 4/4] Update dietpi/dietpi-software Co-authored-by: MichaIng --- dietpi/dietpi-software | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dietpi/dietpi-software b/dietpi/dietpi-software index 0b11b96f41..6e23b5af3e 100755 --- a/dietpi/dietpi-software +++ b/dietpi/dietpi-software @@ -7142,7 +7142,7 @@ This is the first post, which was generated by running the command 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 markdown editor, and it will +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