If you need to execute anything more complex than a simple command with argument from -exec, then do so within an in-line script:
find . -type d -exec sh -c ' tmpfile=$(mktemp) || exit trap "rm -f \"\$tmpfile\"" EXIT for dirpath do "$HOME"/bin/opkg-utils/opkg-make-index "$dirpath" | gzip -c >"$tmpfile" && cp -- "$tmpfile" "$dirpath"/package.gz done' sh {} +
This passes batches of directory paths as arguments to the in-line sh -c script. This short script loops over these paths and for each it will call your utility and write the compressed output to a temporary file. After writing the file, it is moved into the directory and the loop continues with the next directory.
Note that this would recurse into subdirectories.
To avoid finding . use ! -path .:
find . ! -path . -type d -exec sh -c '...' sh {} +
Or, with GNU find (and some others), use -mindepth 1:
find . -mindepth 1 -type d -exec sh -c '...' sh {} +
To avoid recursing into subdirectories, use -prune as soon as you've found a directory:
find . ! -path . -type d -prune -exec sh -c '...' sh {} +
Or, with GNU find, use -maxdepth 1:
find . -mindepth 1 -maxdepth 1 -type d -exec sh -c '...' sh {} +
But if you're only interested in a single directory, without recursion, then you may instead use just a shell loop:
shopt -s nullglob dotglob tmpfile=$(mktemp) || exit trap 'rm -f "$tmpfile"' EXIT for dirpath in */; do dirpath=${dirpath%/} [ -h "$dirpath" ] && continue "$HOME"/bin/opkg-utils/opkg-make-index "$dirpath" | gzip -c >"$tmpfile" && cp -- "$tmpfile" "$dirpath"/package.gz done
This is essentially the same loop as in the in-line script that find executes, but it's a bash script and it does needs to carry out some of the work that find would otherwise perform (enable globbing hidden names, check that $dirpath is not a symbolic link etc.)