这是indexloc提供的服务,不要输入任何密码
Skip to content

Getting termux-tools ready for apt 3.0.0 #165

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

Merged
merged 2 commits into from
May 11, 2025

Conversation

TomJo2000
Copy link
Member

Apt 3.0.0 makes the "multiline" deb822 format the standard for package sources.
This PR aims to introduce support for this repo source format in termux-tools.

This initial commit only adds support in pkg.
I plan to add support in termux-info tomorrow, however that turned into half a refactor and I'm tired.


The changes to pkg introduce two possible return values from has_repo.

  • deb822, the new standard format (determined by the .sources file extension)
  • legacy, the old oneline format (determined by the .list file extension)
    Support for the legacy oneline .list format isn't slated to be removed until 20291,
    so it is kept for backwards compatibility in the meantime.
  • An empty return string ("") indicates that the repo is not present in either format.

I also fixed a couple shellcheck warnings and some indentation.
I may do a more extensive refactor of pkg as part of this PR later.

Footnotes

  1. https://man.archlinux.org/man/sources.list.5#ONE-LINE-STYLE_FORMAT

@robertkirkman
Copy link

I tested this, and I think it is working for me. There is something strange-looking about the indentation in some places, but I think you might already have noticed, and will be able to resolve that.

@TomJo2000
Copy link
Member Author

There is something strange-looking about the indentation in some places, but I think you might already have noticed, and will be able to resolve that.

Haven't noticed anything of the sort.
There's some over-indenting from conditionals that could be turned into guard clauses, but the indentation as is seems correct to me.
If you have any specific examples please do point them out.

@robertkirkman
Copy link

@TomJo2000
Copy link
Member Author

That part was already lined up with the line above, it just used spaces instead of tabs for indentation, which doesn't match the rest of the script.

@robertkirkman
Copy link

yes I understand that, but all I am trying to explain is that it is no longer "lined up" after this. This is how it looks on my screen.

image

@TomJo2000
Copy link
Member Author

Looks fine on my device.
image
Probably an issue with your set tapstop?

@TomJo2000 TomJo2000 force-pushed the migrate-to-deb822-format branch from 924edb6 to 8caa682 Compare April 24, 2025 18:23
@TomJo2000
Copy link
Member Author

There's snapped it back to 3 tabs.

@robertkirkman
Copy link

The problem is also visible in your screenshot, but then you fixed it in a force push so I guess you are now able to see the problem with how it was before

@TomJo2000
Copy link
Member Author

The problem is also visible in your screenshot

Then I'm not seeing what you meant.

@robertkirkman
Copy link

image

I screenshotted your screenshot and drew a line on it, in my opinion the line should be straight BUT it is ok and does not matter very much because:

  • it is purely whitespace-related and does not affect the script operation at all
  • you already fixed it by force pushing a commit which makes the line straight

@TomJo2000
Copy link
Member Author

It was aligned with un*|rem*|rm|del*, so I kept it aligned that way when I fixed the indentation from spaces to tabs.
But yeah it should just be straight.

@robertkirkman
Copy link

On my screen, the current change does not change the straight shape of the "line", but this discrepancy can come as a side effect of the different settings of tab width for each user, like you mentioned.

image

@TomJo2000
Copy link
Member Author

Just finished testing the termux-info changes.
The new version does away with the previous special casing for the sources.list file outside the sources.list.d directory by consolidating the find into a for loop, glob and case for classification instead.

@TomJo2000
Copy link
Member Author

@Grimler91
Copy link
Member

For some reason that I have not figured out termux-change-repo/pkg empties my .sources files:

$ cat $PREFIX/etc/apt/sources.list.d/main.sources
# The main termux repository, with cloudflare cache
Types: deb
URIs: https://packages-cf.termux.dev/apt/termux-main/
Suites: stable
Components: main
Signed-By: /data/data/com.termux/files/usr/etc/apt/trusted.gpg.d/grimler.gpg, /data/data/com.termux/files/usr/etc/apt/trusted.gpg.d/termux-autobuilds.gpg

# The main termux repository, without cloudflare cache
#Types: deb
#URIs: https://packages-cf.termux.dev/apt/termux-main/
#Suites: stable
#Components: main
#Signed-By: /data/data/com.termux/files/usr/etc/apt/trusted.gpg.d/grimler.gpg, /data/data/com.termux/files/usr/etc/apt/trusted.gpg.d/termux-autobuilds.gpg
$ termux-change-repo
[ ... ]
[*] Mirror grimler.se selected
[*] pkg --check-mirror update
grep: /data/data/com.termux/files/usr/etc/apt/sources.list: No such file or directory
Testing the available mirrors:
[*] (4) https://grimler.se/termux/termux-main: ok
Picking mirror: (1) /data/data/com.termux/files/usr/etc/termux/mirrors/europe/grimler.se
Hit:1 https://turdl.kcubeterm.com tur-packages InRelease
All packages are up to date.
$ more $PREFIX/etc/apt/sources.list.d/* $PREFIX/etc/apt/sources.list
::::::::::::::
/data/data/com.termux/files/usr/etc/apt/sources.list.d/main.sources
::::::::::::::
::::::::::::::
/data/data/com.termux/files/usr/etc/apt/sources.list.d/root.sources
::::::::::::::
::::::::::::::
/data/data/com.termux/files/usr/etc/apt/sources.list.d/tur.sources
::::::::::::::
# A single and trusted place for all unofficial/less popular termux packages
Types: deb
URIs: https://tur.kcubeterm.com/
Suites: tur-packages
Components: tur tur-on-device tur-continuous
Signed-By: /data/data/com.termux/files/usr/etc/apt/trusted.gpg.d/tur.gpg
::::::::::::::
/data/data/com.termux/files/usr/etc/apt/sources.list.d/x11.sources
::::::::::::::

scripts/pkg.in Outdated
source "$selected_mirror"

case "$(has_repo main)" in
'deb822') sed -ni -e "s|URIs:.*|URIs: $MAIN|" "@TERMUX_PREFIX@/etc/apt/sources.list.d/main.sources";;
Copy link
Member

Choose a reason for hiding this comment

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

Might be better to keep original *.sources in $PREFIX/etc/termux/ (or another suitable place), and then sed -n -e "s|URIs:.*|URIs: $MAIN|" "$some_path" > "@TERMUX_PREFIX@/etc/apt/sources.list.d/main.sources". That would make it possible to recover even if *.sources are emptied as in my issue

Copy link
Member

Choose a reason for hiding this comment

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

Seems like it is the -n option that empties the .sources files:

$ cat main.sources 
# The main termux repository, with cloudflare cache
Types: deb
URIs: https://mirror.accum.se/mirror/termux.dev/termux-main
Suites: stable
Components: main
Signed-By: /data/data/com.termux/files/usr/etc/apt/trusted.gpg.d/grimler.gpg, /data/data/com.termux/files/usr/etc/apt/trusted.gpg.d/termux-autobuilds.gpg

# The main termux repository, without cloudflare cache
#Types: deb
#URIs: https://mirror.accum.se/mirror/termux.dev/termux-main
#Suites: stable
#Components: main
#Signed-By: /data/data/com.termux/files/usr/etc/apt/trusted.gpg.d/grimler.gpg, /data/data/com.termux/files/usr/etc/apt/trusted.gpg.d/termux-autobuilds.gpg
$ sed -ni -e "s|URIs:.*|URIs: https://mirror.accum.se/mirror/termux.dev/termux-main|" main.sources 
$ cat main.sources
[ empty ]

Copy link
Member Author

Choose a reason for hiding this comment

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

Yep sorry that was leftover from testing, thought I had already removed those.
-n disables the implied p command causing the pattern space to be printed automatically.

I was using it during testing because I using --debug to step through the sed command.

# ~$ sed --debug -n -e "s/URIs:.*/URIs: testing/" $TERMUX__PREFIX/etc/apt/sources.list.d/main.sources
SED PROGRAM:
  s/URIs:.*/URIs: testing/
INPUT:   '/data/data/com.termux/files/usr/etc/apt/sources.list.d/main.sources' line 1
PATTERN: # The main termux repository, with cloudflare cache
COMMAND: s/URIs:.*/URIs: testing/
PATTERN: # The main termux repository, with cloudflare cache
END-OF-CYCLE:
INPUT:   '/data/data/com.termux/files/usr/etc/apt/sources.list.d/main.sources' line 2
PATTERN: Types: deb
COMMAND: s/URIs:.*/URIs: testing/
PATTERN: Types: deb
END-OF-CYCLE:
INPUT:   '/data/data/com.termux/files/usr/etc/apt/sources.list.d/main.sources' line 3
PATTERN: URIs: https://packages-cf.termux.dev/apt/termux-main/
COMMAND: s/URIs:.*/URIs: testing/
MATCHED REGEX REGISTERS
  regex[0] = 0-53 'URIs: https://packages-cf.termux.dev/apt/termux-main/'
PATTERN: URIs: testing
END-OF-CYCLE:
INPUT:   '/data/data/com.termux/files/usr/etc/apt/sources.list.d/main.sources' line 4
PATTERN: Suites: stable
COMMAND: s/URIs:.*/URIs: testing/
PATTERN: Suites: stable
END-OF-CYCLE:
INPUT:   '/data/data/com.termux/files/usr/etc/apt/sources.list.d/main.sources' line 5
PATTERN: Components: main
COMMAND: s/URIs:.*/URIs: testing/
PATTERN: Components: main
END-OF-CYCLE:
INPUT:   '/data/data/com.termux/files/usr/etc/apt/sources.list.d/main.sources' line 6
PATTERN: Signed-By: /data/data/com.termux/files/usr/etc/apt/trusted.gpg.d/grimler.gpg, /data/data/com.termux/files/usr/etc/apt/trusted.gpg.d/termux-autobuilds.gpg
COMMAND: s/URIs:.*/URIs: testing/
PATTERN: Signed-By: /data/data/com.termux/files/usr/etc/apt/trusted.gpg.d/grimler.gpg, /data/data/com.termux/files/usr/etc/apt/trusted.gpg.d/termux-autobuilds.gpg
END-OF-CYCLE:
INPUT:   '/data/data/com.termux/files/usr/etc/apt/sources.list.d/main.sources' line 7 PATTERN:
COMMAND: s/URIs:.*/URIs: testing/
PATTERN:
END-OF-CYCLE:
INPUT:   '/data/data/com.termux/files/usr/etc/apt/sources.list.d/main.sources' line 8
PATTERN: # The main termux repository, without cloudflare cache
COMMAND: s/URIs:.*/URIs: testing/
PATTERN: # The main termux repository, without cloudflare cache
END-OF-CYCLE:
INPUT:   '/data/data/com.termux/files/usr/etc/apt/sources.list.d/main.sources' line 9
PATTERN: #Types: deb
COMMAND: s/URIs:.*/URIs: testing/
PATTERN: #Types: deb
END-OF-CYCLE:
INPUT:   '/data/data/com.termux/files/usr/etc/apt/sources.list.d/main.sources' line 10
PATTERN: #URIs: https://packages-cf.termux.dev/apt/termux-main/
COMMAND: s/URIs:.*/URIs: testing/
MATCHED REGEX REGISTERS
  regex[0] = 1-54 'URIs: https://packages-cf.termux.dev/apt/termux-main/'
PATTERN: #URIs: testing
END-OF-CYCLE:
INPUT:   '/data/data/com.termux/files/usr/etc/apt/sources.list.d/main.sources' line 11
PATTERN: #Suites: stable
COMMAND: s/URIs:.*/URIs: testing/
PATTERN: #Suites: stable
END-OF-CYCLE:
INPUT:   '/data/data/com.termux/files/usr/etc/apt/sources.list.d/main.sources' line 12
PATTERN: #Components: main
COMMAND: s/URIs:.*/URIs: testing/
PATTERN: #Components: main
END-OF-CYCLE:
INPUT:   '/data/data/com.termux/files/usr/etc/apt/sources.list.d/main.sources' line 13
PATTERN: #Signed-By: /data/data/com.termux/files/usr/etc/apt/trusted.gpg.d/grimler.gpg, /data/data/com.termux/files/usr/etc/apt/trusted.gpg.d/termux-autobuilds.gpg
COMMAND: s/URIs:.*/URIs: testing/
PATTERN: #Signed-By: /data/data/com.termux/files/usr/etc/apt/trusted.gpg.d/grimler.gpg, /data/data/com.termux/files/usr/etc/apt/trusted.gpg.d/termux-autobuilds.gpg
END-OF-CYCLE:

scripts/pkg.in Outdated
source "$selected_mirror"

case "$(has_repo main)" in
'deb822') sed -ni -e "s|URIs:.*|URIs: $MAIN|" "@TERMUX_PREFIX@/etc/apt/sources.list.d/main.sources";;
Copy link
Member

Choose a reason for hiding this comment

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

Seems like it is the -n option that empties the .sources files:

$ cat main.sources 
# The main termux repository, with cloudflare cache
Types: deb
URIs: https://mirror.accum.se/mirror/termux.dev/termux-main
Suites: stable
Components: main
Signed-By: /data/data/com.termux/files/usr/etc/apt/trusted.gpg.d/grimler.gpg, /data/data/com.termux/files/usr/etc/apt/trusted.gpg.d/termux-autobuilds.gpg

# The main termux repository, without cloudflare cache
#Types: deb
#URIs: https://mirror.accum.se/mirror/termux.dev/termux-main
#Suites: stable
#Components: main
#Signed-By: /data/data/com.termux/files/usr/etc/apt/trusted.gpg.d/grimler.gpg, /data/data/com.termux/files/usr/etc/apt/trusted.gpg.d/termux-autobuilds.gpg
$ sed -ni -e "s|URIs:.*|URIs: https://mirror.accum.se/mirror/termux.dev/termux-main|" main.sources 
$ cat main.sources
[ empty ]

@Grimler91
Copy link
Member

I opened a PR: github.com/TomJo2000/pull/2 with fixes for my comments above, and also fixed so it can find current_mirror in deb822 format as well

@TomJo2000 TomJo2000 force-pushed the migrate-to-deb822-format branch from b26d819 to 8246af6 Compare May 9, 2025 15:47
@TomJo2000
Copy link
Member Author

I opened a PR: github.com/TomJo2000/pull/2 with fixes for my comments above, and also fixed so it can find current_mirror in deb822 format as well

Those changes have been manually merged into 4ba21f3.

@Grimler91
Copy link
Member

Those changes have been manually merged into 4ba21f3.

Thanks! Here's another PR which checks if both main.sources and sources.list exists, and deletes sources.list if main.sources seems to be a valid mirror: TomJo2000#3
If we get something like that in then I am happy and will gladly merge this!

@TomJo2000
Copy link
Member Author

Thanks! Here's another PR which checks if both main.sources and sources.list exists, and deletes sources.list if main.sources seems to be a valid mirror: TomJo2000#3 If we get something like that in then I am happy and will gladly merge this!

The way I was gonna handle that is for each *-repo package (and apt) to move their old .list entry to a .list.dpkg-old file instead.
That way each repo only modifies its own sources.

@Grimler91
Copy link
Member

@TomJo2000 right, that does sound better!

@TomJo2000
Copy link
Member Author

TomJo2000 commented May 10, 2025

@TomJo2000 right, that does sound better!

[ -f "$TERMUX_PREFIX/etc/apt/sources.list.d/{{repo}}.list" ] && {
	echo "Legacy repo file found for '{{repo}}' repository."
	echo "Migrating sources.list.d/{{repo}}.list to sources.list.d/{{repo}}.sources"
	mv -v "$TERMUX_PREFIX"/etc/apt/sources.list.d/{{repo}}.list{,.dpkg-old}
	echo "A backup copy of the old {{repo}}.list repo file"
	echo "has been saved to $TERMUX_PREFIX/etc/apt/sources.list.d/{{repo}}.list.dpkg-old"
}

(apt's does of course check for $TERMUX_PREFIX/etc/apt/sources.list instead)
It's currently duplicated for each repo, I don't think it's worth the additional effort to make it DRY.

Copy link
Member

@Grimler91 Grimler91 left a comment

Choose a reason for hiding this comment

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

This PR looks good to me, I will aim at merging and releasing it tomorrow evening unless there are more questions/comments by then!

@TomJo2000
Copy link
Member Author

This PR looks good to me, I will aim at merging and releasing it tomorrow evening unless there are more questions/comments by then!

We can merge this PR ahead of merging Apt 3.0.1,
I'd like to run final validation and testing tonight so we're ready to merge everything tomorrow.

@agnostic-apollo
Copy link
Member

Looks good otherwise.

@TomJo2000 TomJo2000 force-pushed the migrate-to-deb822-format branch from 8246af6 to 3b2d731 Compare May 11, 2025 13:05
@TomJo2000 TomJo2000 force-pushed the migrate-to-deb822-format branch from 3b2d731 to 9c60582 Compare May 11, 2025 13:12
@TomJo2000 TomJo2000 force-pushed the migrate-to-deb822-format branch 3 times, most recently from b63cc37 to 7db0105 Compare May 11, 2025 13:48
scripts/pkg.in Outdated
sed -i -e "s|URIs:.*|$(sed_escape_replacement "URIs: $ROOT")|" \
"@TERMUX_PREFIX@/etc/apt/sources.list.d/root.sources"
;;
'legacy') echo "deb $ROOT root stable" > @TERMUX_PREFIX@/etc/apt/sources.list.d/root.list;;
Copy link
Member

Choose a reason for hiding this comment

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

Quote.

Copy link
Member Author

Choose a reason for hiding this comment

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

Derp, yeah missed that one.

Copy link
Member Author

@TomJo2000 TomJo2000 May 11, 2025

Choose a reason for hiding this comment

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

@TomJo2000 TomJo2000 force-pushed the migrate-to-deb822-format branch from 7db0105 to aa8327d Compare May 11, 2025 14:35
@Grimler91
Copy link
Member

Needs one more update in update_apt_cache, where we run: sources_modified=$(last_modified "@TERMUX_PREFIX@/etc/apt/sources.list"), I will fix that and get this in

TomJo2000 and others added 2 commits May 11, 2025 21:36
Co-authored-by: Henrik Grimler <grimler@termux.dev>
Co-authored-by: agnostic-apollo <agnosticapollo@gmail.com>
@Grimler91 Grimler91 force-pushed the migrate-to-deb822-format branch from aa8327d to eba064d Compare May 11, 2025 19:39
@Grimler91 Grimler91 merged commit eba064d into termux:master May 11, 2025
@Grimler91
Copy link
Member

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants