Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions utils/afetch/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#
# Copyright (C) 2007-2026 OpenWrt.org
#
# This is free software, licensed under the GNU General Public License v2.
# See /LICENSE for more information.
#
Comment on lines +1 to +6
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Are you affiliated with OpenWrt somehow or not? If not, remove it.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Sorry, I misunderstood the documentation. I thought something like this was necessary as a formal way of saying that I am giving up the Makefile copyright to the OpenWrt project. I will remove this comment.


include $(TOPDIR)/rules.mk

PKG_NAME:=afetch
PKG_VERSION:=2.2.0
PKG_RELEASE:=1

PKG_BUILD_DIR:=$(BUILD_DIR)/$(PKG_NAME)-$(PKG_VERSION)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This is default.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Thanks, I'll remove that line.

PKG_SOURCE:=V$(PKG_VERSION).tar.gz
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This is wrong. :) We can not download tarball as vX.Y.Z.tar.gz and put it to the dl folder. What if this is going to be replaced by another tarball? There should be always name-version.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Thanks, I'll fix that.

PKG_SOURCE_URL:=https://github.com/13-CF/afetch/archive/refs/tags/
PKG_HASH:=e1f4630b2f8aea0edb76676afbfba9b92c819c6df5da68eb5b89da9c330e2fcd

PKG_MAINTAINER:=Tiago Rocha <tiagorocha@disroot.org>
PKG_LICENSE:=GPL-3.0-only
PKG_LICENSE_FILES:=COPYING
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Are you sure? I can not find COPYING in the repository.
There is LICENSE - https://github.com/13-CF/afetch/blob/master/LICENSE

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Sorry, this was a copy and paste error from an example in the documentation that went unnoticed.


include $(INCLUDE_DIR)/package.mk

define Package/afetch
SECTION:=utils
CATEGORY:=Utilities
TITLE:=Fast and simple system info written in C
URL:=https://github.com/13-CF/afetch
endef
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

No depends?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

As the only dependency I thought of was a libc I thought I didn't need to add anything. Should I have added the base-files package because of the /etc/os-release file?


define Package/afetch/description
Fast and simple system info (for UNIX based operating systems)
written in POSIX compliant C99.
endef
Comment on lines +32 to +35
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why do we need to have this in our repository? What is the usage? As it does not support OpenWrt given the patch, which you want to add here in downstream instead of adding it to upstream, I think majority of users will not use this.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

You're right, there is a real risk that afetch will no longer be maintained, it was precisely the upstream inactivity that led me to not send a patch there first. However, as the last 6 years have been insane, and many have stopped with personal projects, I believe it is worth giving more time for the upstream to return or fork to emerge. Of course there are other actively maintained fetches, but I believe they are too big and bloated for OpenWrt.

Regarding practical utility, afetch and similar tools should have no use other than being a fancy and cool way to share our setup. However, these tools are relatively popular among users of Linux and BSD distros.

Since there are some users who miss something like this in the official OpenWrt repositories, I thought I'd take the opportunity to give back and learn a little more about the project.


define Package/afetch/install
$(INSTALL_DIR) $(1)/usr/bin
$(INSTALL_BIN) $(PKG_BUILD_DIR)/afetch $(1)/usr/bin/
endef

$(eval $(call BuildPackage,afetch))
347 changes: 347 additions & 0 deletions utils/afetch/patches/100-add_openwrt_support_and_reduce_size.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,347 @@
Index: afetch-2.2.0/src/fetch.c
Comment thread
tiagorochaxyz marked this conversation as resolved.
===================================================================
--- afetch-2.2.0.orig/src/fetch.c
+++ afetch-2.2.0/src/fetch.c
@@ -155,334 +155,18 @@ void *os()
strcpy(osname, newContents);
free(newContents);
/* end */
- if (strncmp(osname, "Alpine Linux", 12) == 0) {
- info.col1 = BBLUE "\n";
- info.col2 = BBLUE " /\\ /\\ ";
- info.col3 = BBLUE " / \\ \\ ";
- info.col4 = BBLUE " / \\ \\ ";
- info.col5 = BBLUE " / \\ \\ ";
- info.col6 = BBLUE "/ \\ \\";
- info.col7 = BBLUE " \\ ";
+ if (strncmp(osname, "OpenWrt", 7) == 0) {
+ info.col1 = BWHITE " ______ \n" BBLUE;
+ info.col2 = BWHITE " / ____ \\ " BBLUE;
+ info.col3 = BWHITE " / __ \\ " BBLUE;
+ info.col4 = BBLUE " / "BWHITE"/ \\ "BBLUE"\\ " BBLUE;
+ info.col5 = BBLUE " \\ "BWHITE"()"BBLUE" / " BBLUE;
+ info.col6 = BBLUE " \\____/ " BBLUE;
+ info.col7 = BBLUE " OpenWrt " BBLUE;
info.col8 = BBLUE "";
info.getPkgCount =
"grep 'P:' /lib/apk/db/installed | wc -l";
- } else if (strncmp(osname, "Arch Linux", 10) == 0) {
- info.col1 = BCYAN "";
- info.col2 = BCYAN " /\\ ";
- info.col3 = BCYAN " / \\ ";
- info.col4 = BCYAN " /\\ \\ ";
- info.col5 = BCYAN " / \\ ";
- info.col6 = BCYAN " / ,, \\ ";
- info.col7 = BCYAN " / | | -\\ ";
- info.col8 = BCYAN "/_-'' ''-_\\\n";
- info.getPkgCount = "pacman -Qq | wc -l";
Comment on lines +5 to +37
- } else if (strncmp(osname, "Arch bang Linux", 15) ==
- 0) {
- info.col1 = BCYAN " ____\n";
- info.col2 = BCYAN " /\\ / /";
- info.col3 = BCYAN " / / / ";
- info.col4 = BCYAN " / / / ";
- info.col5 = BCYAN " / /_/\\ ";
- info.col6 = BCYAN " / __ \\ ";
- info.col7 = BCYAN " / /_/\\ \\ ";
- info.col8 = BCYAN "/_-'' ''-_\\\n";
- info.getPkgCount = "pacman -Qq | wc -l";
- } else if (strncmp(osname, "ArcoLinux", 9) == 0) {
- info.col1 = BBLUE "";
- info.col2 = BBLUE " /\\ ";
- info.col3 = BBLUE " / \\ ";
- info.col4 = BBLUE " / /\\ \\ ";
- info.col5 = BBLUE " / / \\ \\ ";
- info.col6 = BBLUE " / / \\ \\ ";
- info.col7 = BBLUE " / / _____\\ \\ ";
- info.col8 = BBLUE "/_/ `----.\\_\\\n";
- info.getPkgCount = "pacman -Qq | wc -l";
- } else if (strncmp(osname, "Artix Linux", 11) == 0) {
- info.col1 = BCYAN "";
- info.col2 = BCYAN " /\\ ";
- info.col3 = BCYAN " / \\ ";
- info.col4 = BCYAN " /`'.,\\ ";
- info.col5 = BCYAN " / ', ";
- info.col6 = BCYAN " / ,`\\ ";
- info.col7 = BCYAN " / ,.'`. \\ ";
- info.col8 = BCYAN "/.,'` `'.\\\n";
- info.getPkgCount = "pacman -Qq | wc -l";
- } else if (strncmp(osname, "Deepin", 6) == 0) {
- info.col1 = BRED "\n";
- info.col2 = BRED "";
- info.col3 = BRED "";
- info.col4 = BRED "";
- info.col5 = BRED "";
- info.col6 = BRED "";
- info.col7 = BRED "";
- info.col8 = BRED "";
- info.getPkgCount =
- "dpkg -l | tail -n+6 | wc -l";
- } else if (strncmp(osname, "Debian GNU/Linux", 16) ==
- 0) {
- info.col1 = BRED " _____\n";
- info.col2 = BRED " / __ \\ ";
- info.col3 = BRED "| / |";
- info.col4 = BRED "| \\___- ";
- info.col5 = BRED "-_ ";
- info.col6 = BRED " --_ ";
- info.col7 = BRED " ";
- info.col8 = BRED "";
- info.getPkgCount =
- "dpkg -l | tail -n+6 | wc -l";
- } else if (strncmp(osname, "elementary OS", 12) == 0) {
- info.col1 = BCYAN "";
- info.col2 = BCYAN " _______ ";
- info.col3 = BCYAN " / ____ \\ ";
- info.col4 = BCYAN "/ | / /\\";
- info.col5 = BCYAN "|__\\ / / |";
- info.col6 = BCYAN "\\ /__/ /";
- info.col7 = BCYAN " \\_______/ ";
- info.col8 = BCYAN "";
- info.getPkgCount =
- "dpkg -l | tail -n+6 | wc -l";
- } else if (strncmp(osname, "EndeavourOS", 11) == 0) {
- info.col1 = BCYAN "";
- info.col2 =
- BRED " /" BBLUE "\\ " BCYAN;
- info.col3 = BRED " /" BBLUE "/ \\" BCYAN
- "\\ " BCYAN;
- info.col4 = BRED " /" BBLUE "/ \\ " BCYAN
- "\\ " BCYAN;
- info.col5 = BRED " / " BBLUE "/ _) " BCYAN
- ")" BCYAN;
- info.col6 = BRED "/_" BBLUE "/___-- " BCYAN
- "__- " BCYAN;
- info.col7 = BCYAN " /____-- " BCYAN;
- info.col8 = BCYAN "";
- info.getPkgCount = "pacman -Qq | wc -l";
- } else if (strncmp(osname, "Fedora", 6) == 0) {
- info.col1 = BWHITE " _____\n" BBLUE;
- info.col2 = BWHITE " / __)" BBLUE "\\ ";
- info.col3 = BWHITE " | / " BBLUE "\\ \\";
- info.col4 = BWHITE " ___| |" BBLUE "__/ /";
- info.col5 =
- BBLUE " / " BWHITE "(_ _)" BBLUE "_/ ";
- info.col6 =
- BBLUE "/ / " BWHITE "| | " BBLUE;
- info.col7 =
- BBLUE "\\ \\" BWHITE "__/ | " BBLUE;
- info.col8 = BBLUE " \\" BWHITE "(_____/" BBLUE;
- info.getPkgCount =
- "[[ $(which sqlite3 2>/dev/null) && $? -ne "
- "1 ]] && (sqlite3 "
- "/var/lib/rpm/rpmdb.sqlite \"select * from "
- "Name\"|wc -l) || rpm -qa | wc -l";
- } else if (strncmp(osname, "Gentoo", 6) == 0) {
- info.col1 = BMAGENTA " _-----_ \n";
- info.col2 = BMAGENTA " ( \\ ";
- info.col3 = BMAGENTA " \\ 0 \\ ";
- info.col4 = BMAGENTA " \\ )";
- info.col5 = BMAGENTA " / _/ ";
- info.col6 = BMAGENTA " ( _- ";
- info.col7 = BMAGENTA " \\____- ";
- info.col8 = BWHITE "\n";
- info.getPkgCount = "qlist -IRv | wc -l";
- } else if (strncmp(osname, "KDE neon", 8) == 0) {
- info.col1 = BGREEN "";
- info.col2 = BGREEN " ";
- info.col3 = BGREEN " --- _ ";
- info.col4 = BGREEN " / --- \\ ";
- info.col5 = BGREEN " | | | |";
- info.col6 = BGREEN " \\ --- _/ ";
- info.col7 = BGREEN " --- ";
- info.col8 = BGREEN "";
- info.getPkgCount =
- "dpkg -l | tail -n+6 | wc -l";
- } else if (strncmp(osname, "Linux Mint", 10) == 0) {
- info.col1 = BGREEN " _____________ \n";
- info.col2 = BGREEN " |_ \\ ";
- info.col3 = BGREEN " | | _____ | ";
- info.col4 = BGREEN " | | | | | | ";
- info.col5 = BGREEN " | | | | | | ";
- info.col6 = BGREEN " | \\_____/ | ";
- info.col7 = BGREEN " \\___________/ ";
- info.col8 = BGREEN "\n";
- info.getPkgCount = "dpkg -l | tail -n+6 | wc -l";
- } else if (strncmp(osname, "Manjaro", 7) == 0) {
- info.col1 = BGREEN " ________ __ \n";
- info.col2 = BGREEN "| | | |";
- info.col3 = BGREEN "| ____| | |";
- info.col4 = BGREEN "| | __ | |";
- info.col5 = BGREEN "| | | | | |";
- info.col6 = BGREEN "| | | | | |";
- info.col7 = BGREEN "| | | | | |";
- info.col8 = BGREEN "|__| |__| |__|\n";
- info.getPkgCount = "pacman -Qq | wc -l";
- } else if (strncmp(osname, "NixOS", 5) == 0) {
- info.col1 = BMAGENTA " \n";
- info.col2 = BMAGENTA " \\\\ \\\\ // ";
- info.col3 = BMAGENTA " ==\\\\__\\\\/ // ";
- info.col4 = BMAGENTA " // \\\\// ";
- info.col5 = BMAGENTA "==// //== ";
- info.col6 = BMAGENTA " //\\\\___// ";
- info.col7 = BMAGENTA "// /\\\\ \\\\== ";
- info.col8 = BMAGENTA " // \\\\ \\\\ ";
- info.getPkgCount =
- "nix-store -q --requisites "
- "/run/current-system/sw | wc -l";
- } else if (strncmp(osname, "openSUSE Leap", 10) == 0 ||
- strncmp(osname, "openSUSE Tumbleweed", 19) ==
- 0) {
- info.col1 = BGREEN " _______\n";
- info.col2 = BGREEN "__| __ \\ ";
- info.col3 = BGREEN " / .\\ \\";
- info.col4 = BGREEN " \\__/ |";
- info.col5 = BGREEN " _______|";
- info.col6 = BGREEN " \\_______";
- info.col7 = BGREEN "__________/";
- info.col8 = BGREEN "";
- info.getPkgCount = "rpm -qa | wc -l";
- } else if (strncmp(osname, "Parabola", 8) == 0) {
- info.col1 = BMAGENTA "";
- info.col2 = BMAGENTA " __ __ __ _ ";
- info.col3 = BMAGENTA ".`_//_//_/ / `.";
- info.col4 = BMAGENTA " / .`";
- info.col5 = BMAGENTA " / .` ";
- info.col6 = BMAGENTA " /.` ";
- info.col7 = BMAGENTA " /` ";
- info.col8 = BMAGENTA "";
- info.getPkgCount = "pacman -Qq | wc -l";
- } else if (strncmp(osname, "Pop!_OS", 7) == 0) {
- info.col1 = BCYAN "______\n";
- info.col2 = BCYAN "\\ _ \\ __";
- info.col3 = BCYAN " \\ \\ \\ \\ / /";
- info.col4 = BCYAN " \\ \\_\\ \\ / / ";
- info.col5 = BCYAN " \\ ___\\ /_/ ";
- info.col6 = BCYAN " \\ \\ _ ";
- info.col7 = BCYAN " __\\_\\__(_)_ ";
- info.col8 = BCYAN " (___________)";
- info.getPkgCount =
- "dpkg -l | tail -n+6 | wc -l";
- } else if (strncmp(osname, "postmarketOS", 13) == 0) {
- info.col1 = BGREEN " /\\ \n";
- info.col2 = BGREEN " / \\ ";
- info.col3 = BGREEN " / \\ ";
- info.col4 = BGREEN " /\\__ \\ ";
- info.col5 = BGREEN " / /\\ _\\ ";
- info.col6 = BGREEN " / ___\\/ \\ ";
- info.col7 = BGREEN " / \\ \\ ";
- info.col8 = BGREEN "/_____/________\\";
- info.getPkgCount =
- "grep 'P:' /lib/apk/db/installed | wc -l";
- } else if (strncmp(osname, "Slackware", 10) == 0) {
- info.col1 = BBLUE " ________\n";
- info.col2 = BBLUE " / ______| ";
- info.col3 = BBLUE " | |______ ";
- info.col4 = BBLUE " \\______ \\ ";
- info.col5 = BBLUE " ______| | ";
- info.col6 = BBLUE "| |________/ ";
- info.col7 = BBLUE "|____________";
- info.col8 = BBLUE "";
- info.getPkgCount =
- "ls /var/log/packages | wc -l";
- } else if (strncmp(osname, "Solus", 5) == 0) {
- info.col1 = BMAGENTA " __________\n";
- info.col2 = BMAGENTA " / \\ ";
- info.col3 = BMAGENTA " / /\\ \\ \\ ";
- info.col4 = BMAGENTA " / / \\ \\ \\ ";
- info.col5 = BMAGENTA "| / \\ \\ |";
- info.col6 = BMAGENTA " \\--------------/ ";
- info.col7 = BMAGENTA " \\------------/ ";
- info.col8 = BMAGENTA " \\----------/";
- info.getPkgCount =
- "ls /var/lib/eopkg/package/ | wc -l";
- } else if (strncmp(osname, "Ubuntu", 6) == 0) {
- info.col1 = BRED "";
- info.col2 = BRED " _ ";
- info.col3 = BRED " ---(_) ";
- info.col4 = BRED " _/ --- \\ ";
- info.col5 = BRED "(_) | | ";
- info.col6 = BRED " \\ --- _/ ";
- info.col7 = BRED " ---(_) ";
- info.col8 = BRED "";
- info.getPkgCount =
- "dpkg -l | tail -n+6 | wc -l";
- } else if (strncmp(osname, "void", 4) == 0) {
- info.col1 = BGREEN " _____\n";
- info.col2 = BGREEN " _ \\____ - ";
- info.col3 = BGREEN " / / ____ \\ \\ ";
- info.col4 = BGREEN " / / / \\ \\ \\";
- info.col5 = BGREEN " | | " BGRAY BITAL "VOID " BGREEN "| |";
- info.col6 = BGREEN " \\ \\ \\____/ / /";
- info.col7 = BGREEN " \\ \\____ /_/ ";
- info.col8 = BGREEN " -_____\\\n";
- info.getPkgCount = "xbps-query -l | wc -l";
- } else if (strncmp(osname, "Zorin OS", 8) == 0) {
- info.col1 = BBLUE " ______ \n";
- info.col2 = BBLUE " /______\\ ";
- info.col3 = BBLUE " / / \\ ";
- info.col4 = BBLUE "/ / \\";
- info.col5 = BBLUE "\\ / /";
- info.col6 = BBLUE " \\ /___ / ";
- info.col7 = BBLUE " \\______/ ";
- info.col8 = BBLUE "";
- info.getPkgCount = "dpkg -l | tail -n+6 | wc -l";
}
- } else if (strncmp(sysInfo.sysname, "Darwin", 6) == 0) {
- info.col1 = "" BYELLOW;
- info.col2 = BGREEN " .:' " BYELLOW;
- info.col3 = BGREEN " __ :'__ " BYELLOW;
- info.col4 = BYELLOW " .'`__`-'__``." BYELLOW;
- info.col5 = BRED " :__________.-'" BYELLOW;
- info.col6 = BRED " :_________: " BYELLOW;
- info.col7 = BMAGENTA " :_________`-;" BYELLOW;
- info.col8 = BBLUE " `.__.-.__.' " BYELLOW;
- if ((strncmp(sysInfo.machine, "iPhone", 6) == 0) || (strncmp(sysInfo.machine, "iPad", 4) == 0) || (strncmp(sysInfo.machine, "iPod", 4) == 0)) {
- info.getPkgCount =
- "dpkg -l | tail -n+6 | wc -l";
-
- char *iosVer = malloc(1024);
- strcpy(iosVer, "iOS ");
- char *productVer = pipeRead("sw_vers -productVersion");
-
- strcat(iosVer, productVer);
- free(productVer);
- osname = iosVer;
- free(iosVer);
- } else {
- info.getPkgCount =
- "ls /usr/local/Cellar/* | grep ':' | wc -l | xargs";
-
- char *macVer = malloc(64);
- strcpy(macVer, "macOS ");
- char *productVer = pipeRead("sw_vers -productVersion");
-
- strcat(macVer, productVer);
- free(productVer);
- osname = macVer;
- free(macVer);
- }
- } else if (strncmp(sysInfo.sysname, "FreeBSD", 7) == 0) {
- info.col1 = BRED "";
- info.col2 = BRED "/\\,-'''''-,/\\";
- info.col3 = BRED "\\_) (_/";
- info.col4 = BRED "| |";
- info.col5 = BRED "| |";
- info.col6 = BRED " ; ; ";
- info.col7 = BRED " '-_____-' ";
- info.col8 = BRED "";
- info.getPkgCount = "pkg info | wc -l | tr -d ' '";
- osname = sysInfo.sysname;
- } else if (strncmp(sysInfo.sysname, "OpenBSD", 7) == 0) {
- info.col1 = BYELLOW " _____ \n";
- info.col2 = BYELLOW " \\- -/ ";
- info.col3 = BYELLOW " \\_/ \\ ";
- info.col4 = BYELLOW " | " BWHITE "O O" BYELLOW " |";
- info.col5 = BYELLOW " |_ < ) 3 )";
- info.col6 = BYELLOW " / \\ / ";
- info.col7 = BYELLOW " /-_____-\\ ";
- info.col8 = BYELLOW "";
- info.getPkgCount =
- "/bin/ls -1 /var/db/pkg/ | wc -l | tr -d ' '";
- osname = sysInfo.sysname;
- } else if (strncmp(sysInfo.sysname, "NetBSD", 6) == 0) {
-
}
pkgCount = pipeRead(info.getPkgCount);

Loading