summaryrefslogtreecommitdiffstats
path: root/package/base-files/files/lib/functions.sh
Commit message (Collapse)AuthorAgeFilesLines
* base-files: Reapply fixed "Ignore exit code of uci.sh inclusion"Paul Spooren2 days1-1/+1
| | | | | | | | This reverts commit 80d1c353b79e6c216dcb2534420470e3e6ed5d60 with the fix which won't break running systems. A logic error on how shell handles && and || more the init process. Signed-off-by: Paul Spooren <mail@aparcar.org>
* Revert "base-files: Ignore exit code of uci.sh inclusion"Robert Marko6 days1-1/+1
| | | | | | | | This reverts commit 17d8c5825e6f5c5d2e4d2c320c3b4b797f4ca0e9. This commit is breaking init somehow, even the hostname is not set, so until its fixed, revert it. Signed-off-by: Robert Marko <robimarko@gmail.com>
* base-files: Ignore exit code of uci.sh inclusionPaul Spooren7 days1-1/+1
| | | | | | | | When running unit tests this causes trouble since `/lib/config/uci.sh` isn't available in those cases. Instead exit with a clean status fo the unit test framework don't wrongly interpret things as an error. Signed-off-by: Paul Spooren <mail@aparcar.org>
* base-files: add compatibility for APK and OPKGPaul Spooren2024-05-171-7/+21
| | | | | | | Both package managers work slightly different, i.e. stores files at different places. Modify the `functions.sh` file to cover those. Signed-off-by: Paul Spooren <mail@aparcar.org>
* base-files: add update_alternatives functionPaul Spooren2024-05-171-0/+49
| | | | | | | The APK package manager does not support handling of package alternatives itself, so implement it via a simple shell script. Signed-off-by: Paul Spooren <mail@aparcar.org>
* base-files: fix uid/gid auto-enumeration to avoid 16-bit limitThomas Winkler2024-05-101-2/+2
| | | | | | | | | | | uid/gid range should be limited to 16bit unsigned integer range to avoid "wraparound" issues with permissions where jffs2 is employed for storage and chown 65536 (first auto-created user) becomes equivalent to chown 0 Fixes: #13927 Signed-off-by: Thomas Winkler <tewinkler86@gmail.com>
* base-files: Add new functions for ath11k caldataPaweł Owoc2024-04-231-0/+24
| | | | | | | | | | | | Add new functions for ath11k caldata: - ath11k_patch_mac (from 0 to 5) - ath11k_remove_regdomain - ath11k_set_macflag (some pre-caldata have the nvMacFlag flag unset which is needed to change the MAC address) Additionaly for ath10k caldata: - ath10k_remove_regdomain Signed-off-by: Paweł Owoc <frut3k7@gmail.com>
* base-files: functions.sh: prepend() always adds separatorPhilip Prindeville2024-01-151-1/+1
| | | | | | | | | | It shouldn't gate on the value, since the value will ostensibly always be set; instead it should depend on the variable being prepended to being non-empty. Fixes #14403 Signed-off-by: Philip Prindeville <philipp@redfish-solutions.com>
* base-files: execute package's "postinst" after executing uci-defaultsRafał Miłecki2023-12-271-5/+5
| | | | | | | | | | | | | | | | Allow "postinst" scripts to perform extra actions after applying all kind of fixups implemented using uci-defaults. This is needed e.g. by uhttpd-mod-ubus which after installation in a running systems needs to: 1. Update uhttpd config using its uci-defaults script 2. Reload uhttpd While this approach makes sense there is a risk it'll blow up some corner case postinst usages. There is only 1 way to find out. Cc: Hauke Mehrtens <hauke@hauke-m.de> Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
* base-files: functions.sh: Add prepend() homologue to append()Philip Prindeville2023-10-231-0/+8
| | | | | | | | | | | | | Sometimes it's useful to be able to prepend to a variable as well, such as when dealing with domain names, e.g. prepend fdqn "$subdomain" "." will result in: fqdn="$subdomain.$fqdn" Signed-off-by: Philip Prindeville <philipp@redfish-solutions.com>
* package: avoid the use of eval to parse ipcalc.sh outputLeon M. Busch-George2023-09-251-0/+5
| | | | | | | | | | | Add a function 'ipcalc' to /lib/functions.sh that sets variables more safely using export. With this new function, dnsmasq also handles the return value of ipcalc correctly. Fixes: e4bd3de1be8e ("dnsmasq: refuse to add empty DHCP range") Co-Authored-By: Philip Prindeville <philipp@redfish-solutions.com> Signed-off-by: Leon M. Busch-George <leon@georgemail.eu>
* base-files: simplify restorecon logicDaniel Golle2022-05-021-2/+2
| | | | | | | | | Remove forgotten redundant selinuxenabled call and skip the whole thing in case $IPKG_INSTROOT is set as labels are anyway applied only later on in fakeroot when squashfs is created. Fixes: 6d7272852e ("base-files: add missing $IPKG_INSTROOT to restorecon call") Signed-off-by: Daniel Golle <daniel@makrotopia.org>
* base-files: add missing $IPKG_INSTROOT to restorecon callDaniel Golle2022-05-021-1/+3
| | | | | | | Update to overlooked v2 version of Dominick Grift's patch. Fixes: 5109bd164c ("base-files: address sed in-place without SELinux awareness") Signed-off-by: Daniel Golle <daniel@makrotopia.org>
* base-files: address sed in-place without SELinux awarenessDominick Grift2022-05-021-0/+1
| | | | | | | | | | | | sed(1) in busybox does not support this functionality: https://git.savannah.gnu.org/cgit/sed.git/tree/sed/execute.c#n598 This causes /etc/group to become mislabeled when a package requests that a uid/gid be added on OpenWrt with SELinux Signed-off-by: Daniel Golle <daniel@makrotopia.org> [move restorecon inside lock] Signed-off-by: Dominick Grift <dominick.grift@defensec.nl>
* base-files: allow specifiying rootdev for find_mmc_partDaniel Golle2021-11-011-2/+8
| | | | | | | | Some devices got more than one mmc device. Allow specifying the root device as 2nd parameter of find_mmc_part so scripts can avoid matching irrelevant partitions on wrong mmc device. Signed-off-by: Daniel Golle <daniel@makrotopia.org>
* base-files: add minimal mmc supportDavide Fioravanti2021-11-011-0/+13
| | | | | | | | | | | | | | | | Added minimal mmc support for helper functions: - find_mmc_part: Look for a given partition name. Returns the coresponding partition path - caldata_extract_mmc: Look for a given partition name and then extracts the calibration data - mmc_get_mac_binary: Returns the mac address from a given partition name and offset Signed-off-by: Davide Fioravanti <pantanastyle@gmail.com> Signed-off-by: Robert Marko <robimarko@gmail.com> [replace dd with caldata_dd, moved sysupgrade mmc to orbi] Signed-off-by: Christian Lamparter <chunkeey@gmail.com>
* base-files, metadata: support additional group membershipDaniel Golle2021-10-281-3/+20
| | | | | | | | | | | | Some packages may require additional group membership for the system user added by that package. Allow defining additional groups as third member of the ':'-separated tuple, allowing to specify multiple ','-separated groups with optional GID. Example: USERID:=foouser=1000:foogroup=1000:addg1=1001,addg2=1002,addg3 Signed-off-by: Daniel Golle <daniel@makrotopia.org>
* base-files: functions: introduce new helper functionsDaniel Golle2021-03-311-0/+10
| | | | | | | | | | | Introduce cmdline_get_var() to /lib/function.sh and make use of it in export_rootdev() in /lib/upgrade/common.sh, making the code more simple and removing one level of indentation. Introduce get_partition_by_name() to /lib/upgrade/common.sh which is useful on non-EFI GPT platforms like mt7622. Remove some dead-code while at it. Signed-off-by: Daniel Golle <daniel@makrotopia.org>
* base-files: remove execute bit and shebang from functions.shAdrian Schmutzler2021-01-291-1/+0
| | | | | | | | | | | /lib/functions.sh was executable for no obvious reason and its execute property was even checked in package-ipkg.mk just to source it afterwards. Remove the execute bit and shebang as this is clearly a library. Signed-off-by: Adrian Schmutzler <freifunk@adrianschmutzler.de> Reviewed-by: Philip Prindeville <philipp@redfish-solutions.com>
* base-files: allow reusing of boolean value extraction logicOldřich Jedlička2021-01-011-5/+12
| | | | | | | | | | | | | | | | | | | The `functions.sh` script has `config_get_bool()` function, which is usable when using UCI config direct access API, but there is no equivalent for the callback API. Introduce `get_bool()` function to allow reusing it from init scripts. Example: ```sh option_cb() { local option="$1" local value="$(get_bool "$2")" ... } ``` Signed-off-by: Oldřich Jedlička <oldium.pro@gmail.com>
* base-files: functions.sh: replace [^...] with [!...] in caseRosen Penev2020-11-251-1/+1
| | | | | | | | | | | | | | | | Strictly speaking, ash does not support it. From https://wiki.ubuntu.com/DashAsBinSh#A.5B.5E.5D Not to be confused by sed's and other program's regular expression syntax. Uses of [^...] in case (parameter/word expansion in general) need to be replaced with [!...]. Found with shellcheck: https://github.com/koalaman/shellcheck/wiki/SC2169 Signed-off-by: Rosen Penev <rosenp@gmail.com> [minor commit title/message adjustments] Signed-off-by: Adrian Schmutzler <freifunk@adrianschmutzler.de>
* base-files: functions.sh: fix config_get() on invalid identifiersJo-Philipp Wich2020-08-071-3/+8
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | When passing a section or option value to config_get() which contains characters that happen to be valid variable interpolation expressions, the function returns a nonsensical expression result instead of the expected empty string. When the passed section or option name contains other characters which are not valid within a shell variable name, a substitution error is occuring instead. The issue can be easily reproduced by one of the following examples: root@OpenWrt:~# . /lib/functions.sh root@OpenWrt:~# config load system root@OpenWrt:~# config_get variable invalid-section option root@OpenWrt:~# echo "$variable" section_option:- root@OpenWrt:~# . /lib/functions.sh root@OpenWrt:~# config load system root@OpenWrt:~# config_get variable section invalid-option root@OpenWrt:~# echo "$variable" option:- root@OpenWrt:~# . /lib/functions.sh root@OpenWrt:~# config load system root@OpenWrt:~# config_get variable section invalid@option -ash: eval: syntax error: bad substitution Fix this issue by only performing interpolations when the given section and option arguments are free of illegal characters. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
* base-files/functions.sh: use command -v instead of whichRosen Penev2020-07-111-2/+2
| | | | | | | | which must be executed. command -v is a shell builtin. https://github.com/koalaman/shellcheck/wiki/SC2230 Signed-off-by: Rosen Penev <rosenp@gmail.com>
* base-files: do not source system.sh in functions.shAdrian Schmutzler2020-04-121-1/+0
| | | | | | | | | | | | | | | | | | The default_postinst() function in /lib/functions.sh sources /lib/functions/system.sh before cycling through uci-defaults files. This creates a pseudo-cyclic dependency as system.sh also uses functions that are located in functions.sh. Despite that, there is actually only one uci-defaults file in the entire repo that needs system.sh, and this one contains an explicit source for system.sh anyway. Consequently, this patch removes the sourcing of system.sh in functions.sh. There are no relevant uses in packages, routing and luci repositories. This may require adjustments for downstream, though. Signed-off-by: Adrian Schmutzler <freifunk@adrianschmutzler.de>
* base-files: convert leading spaces to tabs in functions.shAdrian Schmutzler2020-03-131-2/+2
| | | | | | Use tabs for indent consistently. Signed-off-by: Adrian Schmutzler <freifunk@adrianschmutzler.de>
* base-files/functions.sh: use grep -q instead of []Rosen Penev2020-01-181-4/+4
| | | | | | | | | | | | It's cleaner and faster as it does not need to do extra work. Also removed $() to avoid executing the output. The shell can handle it. https://github.com/koalaman/shellcheck/wiki/SC2143 Signed-off-by: Rosen Penev <rosenp@gmail.com> [correct || to && for one conversion] Signed-off-by: Adrian Schmutzler <freifunk@adrianschmutzler.de>
* base-files/functions.sh: use && instead of -aRosen Penev2020-01-171-2/+2
| | | | | | | | -a is not well defined. https://github.com/koalaman/shellcheck/wiki/SC2166 Signed-off-by: Rosen Penev <rosenp@gmail.com>
* base-files/functions.sh: remove useless catRosen Penev2020-01-171-2/+2
| | | | | | | | The cut command can take a file as an input. https://github.com/koalaman/shellcheck/wiki/SC2002 Signed-off-by: Rosen Penev <rosenp@gmail.com>
* base-files/functions.sh: don't use $var in $(())Rosen Penev2020-01-171-3/+3
| | | | | | | | It's not needed. It can also lead to subtle bugs. https://github.com/koalaman/shellcheck/wiki/Sc2004 Signed-off-by: Rosen Penev <rosenp@gmail.com>
* base-files: move xor() from caldata extraction to functions.shAdrian Schmutzler2019-10-131-0/+16
| | | | | | | | The xor() function is defined in each of the caldata extraction scripts for several targets. Move it to functions.sh to reduce duplicate code. Signed-off-by: Adrian Schmutzler <freifunk@adrianschmutzler.de>
* base-files: apply new sysctl.conf at postinstYousong Zhou2019-06-211-13/+20
| | | | | | | | | | | | | | | | This is mainly for kmod-br-netfilter. To turn off bridge-netfilter-call-xxx immediately after installation While at it - Define filelist="/usr/lib/opkg/info/${pkgname}.list" - Reuse "[ -z "$root" ]" - Grep with "-m1" Fixes FS#2300 Reported-by: Marco Sartorius <tidbits@ormoorgmen.info> Signed-off-by: Yousong Zhou <yszhou4tech@gmail.com>
* base-files: config_get: prevent filename globbingGünther Kelleter2019-01-301-1/+1
| | | | | | | | | When config_get is called as "config_get section option" the option is unexpectedly globbed by the shell which differs from the way options are read to a variable with "config_get variable section option". Add another layer of double quotes to fix it. Signed-off-by: Günther Kelleter <guenther.kelleter@devolo.de>
* base-files: fix prerm return value, align with postinst codeTony Ambardar2018-11-291-5/+10
| | | | | | | | | | | | | | | The return value of a package prerm script is discarded and not returned correctly by default_prerm(). This allows other operations like service shutdown to "leak" their return value, prompting workarounds like commit 48cfc826 which do not address the root cause. Preserve a package prerm script return value for use by default_prerm(), sharing the corresponding code from default_postinst() for consistency. Also use consistent code for handling of /etc/init.d/ scripts. Run Tested on: LEDE 17.01.4 running ar71xx. Signed-off-by: Tony Ambardar <itugrok@yahoo.com>
* base-files: fix postinstall uci-defaults removalTony Ambardar2018-09-241-4/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Commit 7f694582 introduced a bug where default_postinst() often fails to remove a uci-defaults script after application, leaving it to run again after a reboot. (Note: commit 7f694582 also introduced FS#1021, now fixed by 73c745f6) The subtle problem arises from the shell logical chain: [ -f "$i" ] && . "$i" && rm -f "$i" Most uci-defaults scripts contain a terminal 'exit 0' statement which, when sourced, results in the logic chain exiting before executing 'rm -f'. This was observed while testing upgrades of 'luci-app-sqm'. The solution is to wrap the shell sourcing in a subshell relative to the command 'rm -f': ( [ -f "$i" ] && . "$i" ) && rm -f "$i" Revert to using 'grep' to prefilter the list of entries from the control file, which yields the full path of uci-defaults scripts. This allows keeping the existence check, directory change and script sourcing inside the subshell, with the script removal correctly outside. This approach avoids adding a second subshell only around the "." (source) command. The change also preserves the fix FS#1021, since the full path is used to source the script, which is POSIX-portable irrespective of PATH variable or reference to the CWD. Run Tested on: LEDE 17.01.4 running ar71xx, while tracing installation of package luci-app-sqm with its associated /etc/uci-defaults/luci-sqm file. Signed-off-by: Tony Ambardar <itugrok@yahoo.com>
* base-files: fix UCI config parsing and callback handlingTony Ambardar2018-06-061-8/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | There are several long-standing issues present in the UCI shell API as documented in https://wiki.openwrt.org/doc/devel/config-scripting. They relate both to high-level, user-defined callback functions used to process UCI config files, and also to low-level functions used within scripts generally. The related problems have been encountered now and in the past, e.g. https://forum.openwrt.org/viewtopic.php?id=54295, and include: a) UCI parsing option() function and user-defined option_cb() callbacks being erroneously called during processing of "list" config file entries; b) normal usage of the low-level config_set() unexpectedy calling any defined option_cb() if present; and c) handling of the list_cb() not respecting the NO_CALLBACK variable. Root causes include a function stack "inversion", where the low-level config_set() function incorrectly calls the high-level option() function, intended only for processing the "option" keyword of UCI config files. This change addresses the inversion and other issues, making the option handling code more consistent and smaller, and simplifying developers' usage of UCI callbacks. Signed-off-by: Tony Ambardar <itugrok@yahoo.com> Signed-off-by: Hans Dedecker <dedeckeh@gmail.com> [PKG_RELEASE increase]
* base-files: /lib/functions.sh: remove unused insert_modulesMatthias Schiffer2018-04-171-10/+0
| | | | | | insert_modules has been unused since r5279. Signed-off-by: Matthias Schiffer <mschiffer@universe-factory.net>
* base-files: fix getting gid from group_add_nextYousong Zhou2017-11-091-7/+6
| | | | | | | | | | | | Shell function return code only has range [0, 255]. Other values will be truncated, e.g. return 65536 will have the same effect as return 0 While at it, drop other "return $rc" where rc will almost always take value 0 and whose value current callers actually do not check Fixes FS#988 Signed-off-by: Yousong Zhou <yszhou4tech@gmail.com>
* functions.sh: fix default_postinst functionMarko Ratkaj2017-11-081-1/+1
| | | | | | | | | | | | | | | | | | When we run "opkg install" on a package that installs an uci-defaults script, functions.sh will fail to evaluate that script in its default_postinst function. This happens because there is no "./" present and it searches for the file in paths specified by the PATH variable. This would work on bash, but it will not work on ash and some other shells like sh, zsh. This applys to the ". filename" directive used in this case. This patch will make the path relative to the /etc/uci-defaults directory. Fixes: FS#1021 Signed-off-by: Marko Ratkaj <marko.ratkaj@sartura.hr>
* include: kernel.mk: simplify module autoloadingJo-Philipp Wich2017-11-071-0/+4
| | | | | | | | | | | | | | | | | | Let the generic postinstall script invoke "kmodloader" when the just installed package contains any /etc/module.d/ entries. This allows us to skip the explicit "insert_module()" calls in the package postinstall. Due to the removed insert_module calls we do not need to assemble a complete list of modules per package anymore, which allows for vast simplification of the package generation code. While we're at it, also support specifying default parameters for modules using either the MODPARAM or MODPARAM.modulename variables in KernelPackage. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
* base-files: allocate uid/gid starting from 65536Yousong Zhou2017-06-181-4/+4
| | | | | | | | | | | There already exist static assignment of uid/gid 65533 in packages feed and we have nobody/nogroup taking 65534 as their ids. Let's change the pid of dynamic assignment to start from 65536 so that the two assignment scheme will not collide with each other While at it, fix the scan command checking existence of uid/gid Signed-off-by: Yousong Zhou <yszhou4tech@gmail.com>
* base-files: add generic board_name function to functions.shFelix Fietkau2017-03-221-0/+4
| | | | | | | This will be used to replace all those nasty board specific scripts that do basically the same thing Signed-off-by: Felix Fietkau <nbd@nbd.name>
* base-files: add support for overlaying rootfs contentRafał Miłecki2016-12-201-0/+5
| | | | | | | | | This adds support for install-overlay define. When used in package it allows installing files to a special directory that gets copied to the root when installing it. It allows overwriting files provided by other packages. Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
* base-files: ignore failure of stopping services on removalJonas Gorski2016-11-211-1/+1
| | | | | | | | | Packages that do a killall <cmd> with the same name as the init script will fail the prerm step when the service isn't running. Do make them removable without having to restart the service, ignore the return code. Signed-off-by: Jonas Gorski <jonas.gorski@gmail.com> Acked-by: Jo-Philipp Wich <jo@mein.io>
* base-files: don't modify enabled state of service on upgradeJonas Gorski2016-11-211-10/+12
| | | | | | | | Properly stop/start services on upgrade, but don't change the enabled state. Signed-off-by: Jonas Gorski <jonas.gorski@gmail.com> Acked-by: Jo-Philipp Wich <jo@mein.io>
* base-files: make default_prerm work offlineMatthias Schiffer2016-09-261-4/+12
| | | | | | | IPKG_INSTROOT must be respected for offline removal (used for per-device rootfs). Signed-off-by: Matthias Schiffer <mschiffer@universe-factory.net>
* base-files: rework postinstall uci-defaults handlingJo-Philipp Wich2016-05-271-5/+4
| | | | | | | | | | | | | | | Some package postinstall operations, e.g. those emitted by the LuCI build system, source and delete the uci-defaults themselves upon package insteall, causing the generic defaults apply code to trigger shell errors like: .../luci-app-ddns.postinst: .: line 130: can't open './40_luci-ddns' Rework the generic apply code to check the existence of the uci-defaults script before trying to source it, use sed to prefilter the list of entries from the control file and perform the directory change in a subshell, avoiding the need for cd $OLDPWD. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
* base-files: evaluate uci-defaults on run-time installationsDaniel Golle2016-05-041-0/+11
| | | | | | | | | | | | Packages may install scripts into /etc/uci-defaults to be executed once after installation, usually at the first boot of the target. This works fine if the package was installed to the rootfs during build or using the ImageBuilder. If the package is installed using opkg during run-time uci-defaults were applied only after a reboot of the device. Avoid the need to reboot by evaluting the package's uci-defaults in default-postinst. Signed-off-by: Daniel Golle <daniel@makrotopia.org>
* base-files: split user/group addition code into a functionJohn Crispin2016-04-291-4/+10
| | | | Signed-off-by: John Crispin <john@phrozen.org>
* base-files: refactor default_postinst()Jo-Philipp Wich2015-09-161-51/+50
| | | | | | | | | | | | - Simplify user spec parsing code - Alias IPKG_INSTROOT to shorten code - Quote variables where appropriate - Remove a useless-use-of-cat instance - Suppress errors in case control or list files are missing Signed-off-by: Jo-Philipp Wich <jow@openwrt.org> SVN-Revision: 46975
* base-files: default_postinst: propagate the real postinst return codeJohn Crispin2015-08-171-3/+7
| | | | | | | | | | | Using the postinst script for sanity checks and expecting opkg to fail if the postinst didn't return 0 was possible in Barrier Breaker, propagate the real postinst return code through default_postinst to restore this behaviour. Signed-off-by: Matthias Schiffer <mschiffer@universe-factory.net> SVN-Revision: 46653