I have created a deb package that includes a postrm script that fails to be executed.
The error message says that the script cannot be found but it is well placed, it can be run manually with bash and the execution permissions seem ok. What else should I check to find out the cause of the failure?
Here there is an example of the error with minimal postrm script:
user@linux:~$ sudo apt-get remove mypkg
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following packages will be REMOVED:
mypkg
0 upgraded, 0 newly installed, 1 to remove and 79 not upgraded.
After this operation, 0 B of additional disk space will be used.
Do you want to continue? [Y/n] y
(Reading database ... 123043 files and directories currently installed.)
Removing mypkg (1.8.1) ...
dpkg (subprocess): unable to execute installed mypkg package post-removal script (/var/lib/dpkg/info/mypkg.postrm): No such file or directory
dpkg: error processing package mypkg (--remove):
installed mypkg package post-removal script subprocess returned error exit status 2
dpkg: too many errors, stopping
Errors were encountered while processing:
mypkg
Processing was halted because there were too many errors.
E: Sub-process /usr/bin/dpkg returned an error code (1)
user@linux:~$ more /var/lib/dpkg/info/mypkg.postrm
#!/bin/sh
echo "Post rm"
user@linux:~$ bash /var/lib/dpkg/info/mypkg.postrm
Post rm
user@linux:~$ ls -l /var/lib/dpkg/info/mypkg.*
-rwxr-xr-x 1 root root 30 Jun 15 17:39 /var/lib/dpkg/info/mypkg.conffiles
-rw-r--r-- 1 root root 60 Jun 21 10:27 /var/lib/dpkg/info/mypkg.list
-rw-r--r-- 1 root root 5052 Jun 21 10:21 /var/lib/dpkg/info/mypkg.md5sums
-rwxr-xr-x 1 root root 107 Jun 20 10:06 /var/lib/dpkg/info/mypkg.postinst
-rwxr-xr-x 1 root root 25 Jun 20 13:29 /var/lib/dpkg/info/mypkg.postrm
-rwxr-xr-x 1 root root 0 Jun 15 17:39 /var/lib/dpkg/info/mypkg.preinst
-rwxr-xr-x 1 root root 10 Jun 15 17:39 /var/lib/dpkg/info/mypkg.prerm
mypkg.postrm
has execute permissions, can you run it as just/var/lib/dpkg/info/mypkg.postrm
? (i.e. withoutbash
at the start of the line). If not, did you perhaps create that script on a windows machine with CRLF line-endings? What's the exit code (echo $?
) after executing it both ways? What doesfile /var/lib/dpkg/info/mypkg.postrm
say? What is /bin/sh on your system? a link to bash? or dash? something else? can you runsh -c 'echo "Post rm"'
without error? BTW, don't respond in comments - edit your question and add any results/details.