I am trying to build a test package for a Synology DSM using their toolkit and one of the steps requires to execute a Python script. When I execute it an exception is thrown:
/pkgscripts-ng/include/check: line 93: /dev/null: Permission denied
ERROR: This script must be run as root
Here is the function responsible for this error:
CheckPermission()
{
# Only root can run this
id | grep "uid=0" >/dev/null
if [ $? != "0" ]; then
echo "ERROR: This script must be run as root";
echo "";
exit 1;
fi
# Stop!! If /root/.chroot does not exit
if [ ! -f /root/.chroot ]; then
echo "ERROR: Please chroot first!!"
echo ""
exit 1;
fi
}
My dev virtual machine runs on Ubuntu 22.04.3. Installed version of Python: 3.10.12
I am executing the script as a root user (executed sudo -i
in the terminal window, then double checked with whoami
), so my understanding is that all the required privileges are there. If I execute id | grep "uid=0" >/dev/null
in the same terminal window I don't get any error.
Unfortunately I am not a Python developer and googling didn't bring me much.
Okay, with the great help from @chepner, who understood the root cause of the problem, I was able to finally find a solution.
Basically, the problem is that Synology's script (SynologyOpenSource/pkgscripts-ng) doesn't mount /dev/null
and /dev/urandom
when chroot jail for dev environment is created. This causes the above mention error to be thrown.
The solution is to manually mount those devices by yourself. Afterwards I was able to build a package as expected.
Synology didn't update their scripts for years and their documentation mentions that everything works on Ubuntu 16, so it might be that my VM with Ubuntu 22.04 is somehow special.