Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Forgejo to dietpi-software #7071

Open
wants to merge 6 commits into
base: dev
Choose a base branch
from
Open

Add Forgejo to dietpi-software #7071

wants to merge 6 commits into from

Conversation

jcnils
Copy link

@jcnils jcnils commented May 14, 2024

It works similar to Gitea. The docs can be reused.
#6133

1 - I need to confirm if jq comes with dietpi. It was on mine, but my installation is ancient, and I do not remember.

I used it to get the release url from the codeberg repo, as the returning json is different from github used by gitea. Line [10662]

2 - I wonder if there are any tags for ssh server dependencies like 'browser' show in
https://github.com/MichaIng/DietPi/wiki/How-to-add-a-new-software-title#asoftware_depssoftware_id

I noticed that there is also Dropbear besides OpenSSH.

@MichaIng
Copy link
Owner

MichaIng commented May 14, 2024

Many thanks. Linking the request discussion: #6133

I need to confirm if jq comes with dietpi

It does not.

2 - I wonder if there are any tags for ssh server dependencies like 'browser'

Nope, but I think it is not required. While common it is (should be) optional, an SSH server is pre-installed on DietPi, and in the dietpi-software, you have a prominent menu entry for it.

esac

local fallback_url="https://codeberg.org/forgejo/forgejo/releases/download/v7.0.2/forgejo-7.0.2-linux-$arch.xz"
Download_Install "$(curl -sSfL 'https://codeberg.org/api/v1/repos/forgejo/forgejo/releases/latest' | jq '.' | mawk -F\" "/\"browser_download_url\": \".*\/forgejo-[^\"\/]*-linux-$arch\.xz\"/{print \$4}")" /mnt/dietpi_userdata/forgejo/forgejo
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As an alternative to jg, mawk could loop through all fields, until it finds one which matches the URL pattern. I can write that, if needed.

Copy link
Author

@jcnils jcnils May 15, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not familiar with awk, but I found a manual, I am looking into it. https://www.gnu.org/software/gawk/manual/gawk.html

I could not use the gitea awk command because the json from github is readable https://api.github.com/repos/go-gitea/gitea/releases/latest, while the codeberg/forgejo api returns a single string. https://codeberg.org/api/v1/repos/forgejo/forgejo/releases/latest

https://codeberg.org/api/swagger#/repository/repoGetLatestRelease

I can find the fields I need with
curl -sSfL 'https://codeberg.org/api/v1/repos/forgejo/forgejo/releases/latest' | mawk -F: -v RS=, '$1~/"browser_download_url"/'
but there are some tweaks to do.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got it

curl -sSfL 'https://codeberg.org/api/v1/repos/forgejo/forgejo/releases/latest' | mawk -F:\" -v RS=, '/"browser_download_url":".*\/forgejo-[^\"\/]*-linux-arm64\.xz"/{gsub("\"|}| ]","",$2);print $2}'

I will update the file and test it, please let me know if I can improve the regex.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems to be working now.

I also added a line to start Forgejo after the installation is done. systemctl status was showing it as inactive before.

Copy link
Owner

@MichaIng MichaIng May 15, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With the "loop through fields" I actually meant something like this:

curl -sSfL 'https://codeberg.org/api/v1/repos/forgejo/forgejo/releases/latest' | mawk -F\" "{for(i=NF;i>0;i--) if(\$i~/^https:.*linux-$arch\.xz$/) {print \$i;exit}}"

But changing the record delimiter isn't a bad idea either. Running some tests, it seems to perform slightly faster. Can be simplified a little:

curl -sSfL 'https://codeberg.org/api/v1/repos/forgejo/forgejo/releases/latest' | mawk -v RS=, -F\" "/^\"browser_download_url\":\".*-linux-$arch\.xz\"/{print \$4;exit}"

Since every key: value pair must be separated by comma, no need to worry about additional ". And no need to separate fields by " as well as :, then removing all " to effectively use : as field separator only. Just use " only 😉.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is brilliant, it also solves the problem with the closing brackets.
It is also faster, I guess removing the gsub and adding the exit statement helps with that.

Thanks for the guidance.

I tested it here and updated the code.

@MichaIng MichaIng added this to the v9.5 milestone May 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants