diff options
author | Paul Spooren <mail@aparcar.org> | 2020-09-13 16:02:02 -1000 |
---|---|---|
committer | Daniel Golle <daniel@makrotopia.org> | 2020-09-14 10:54:52 +0100 |
commit | 51ec51871fd57b80096baf76d6b21a2ae46e4748 (patch) | |
tree | 4864d3ba0837b471106280cf602973ff46c83955 /scripts | |
parent | 34cc2c9a99f6542f009aa660790061f169aa96b3 (diff) | |
download | upstream-51ec51871fd57b80096baf76d6b21a2ae46e4748.tar.gz upstream-51ec51871fd57b80096baf76d6b21a2ae46e4748.tar.bz2 upstream-51ec51871fd57b80096baf76d6b21a2ae46e4748.zip |
build: add user/group ID resolve function
With the introduction of `./tmp/userids` the `ipkg-build` script can now
resolve values of "PKG_FILE_MODES", allowing users to set names rather
than numeric values.
Signed-off-by: Paul Spooren <mail@aparcar.org>
Diffstat (limited to 'scripts')
-rwxr-xr-x | scripts/ipkg-build | 42 |
1 files changed, 40 insertions, 2 deletions
diff --git a/scripts/ipkg-build b/scripts/ipkg-build index e3a9a882cf..c9be18ec47 100755 --- a/scripts/ipkg-build +++ b/scripts/ipkg-build @@ -68,6 +68,40 @@ pkg_appears_sane() { return $PKG_ERROR } +resolve_file_mode_id() { + type="$1" + name="$2" + position=1 + if [ "$type" = "group" ]; then + position=2 + fi + + # root is always 0 + if [ "$name" = "root" ]; then + echo 0 + exit 0 + fi + + # return numeric names + if [ "$name" -eq "$name" 2>/dev/null ]; then + echo "$name" + exit 0 + fi + + ids=$(grep "$name" "$TOPDIR/tmp/userids") + for id in $ids; do + resolved_name=$(echo "$id" | cut -d ":" -f "$position" | cut -d "=" -f 1) + resolved_id=$(echo "$id" | cut -d ":" -f "$position" | cut -d "=" -f 2) + if [ "$resolved_name" = "$name" ]; then + echo "$resolved_id" + exit 0 + fi + done + + >&2 echo "No $type ID found for $name" + exit 1 +} + ### # ipkg-build "main" ### @@ -142,10 +176,14 @@ for file_mode in $file_modes; do ;; esac path=$(echo "$file_mode" | cut -d ':' -f 1) - user_group=$(echo "$file_mode" | cut -d ':' -f 2-3) + user=$(echo "$file_mode" | cut -d ':' -f 2) + group=$(echo "$file_mode" | cut -d ':' -f 3) mode=$(echo "$file_mode" | cut -d ':' -f 4) - chown "$user_group" "$pkg_dir/$path" + uid=$(resolve_file_mode_id user "$user") + gid=$(resolve_file_mode_id group "$group") + + chown "$uid:$gid" "$pkg_dir/$path" chmod "$mode" "$pkg_dir/$path" done $TAR -X $tmp_dir/tarX --format=gnu --sort=name -cpf - --mtime="$TIMESTAMP" . | $GZIP -n - > $tmp_dir/data.tar.gz |