Hi,

I've tested the test package. It updates as expected (does not install index.html when index.cgi exists), it installs as expected with an existing website (index.cgi exists, index.html is not installed), it installs as expected without an existing website (/var/www does not exist, is created and index.html is installed).

I've attached a terminal log.

So far, everything looks ok.

But there are some problems in postinst:

* Beancounting: The function is_fresh_install() is not properly indented

* If postinst has decided to copy index.html, it checks if /var/www/html is READABLE (test -r), if not, it invokes mkdir -p /var/www/html.  The test is nonsense, root can read even a FILE /var/www/html if it is chmod'ed to 000. Just always run mkdir -p /var/www/html, it won't touch anything if /var/www/html is an existing directory, it will fail and complain if /var/www is some non-directory:

root@debian-sid:~# cd /tmp/
root@debian-sid:/tmp# touch www
Try 'chmod --help' for more information.
root@debian-sid:/tmp# chmod 000 www
root@debian-sid:/tmp# mkdir -p /tmp/www/html
mkdir: cannot create directory ‘/tmp/www’: Not a directory
root@debian-sid:/tmp# ls -l www
---------- 1 root root 0 Jan 31 22:55 www
root@debian-sid:/tmp#
root@debian-sid:/tmp# mkdir -p /tmp/www
mkdir: cannot create directory ‘/tmp/www’: File exists

* You copied the two nested for-loops from apache2, searching for an index file in both /var/www and /var/www/html thanks to the outer for loop. Does that make any sense for mini_httpd? mini_httpd uses /var/www/html as document root and does not care about /var/www at all (unless reconfigured).

* You copied the inner for-loop too literally from apache2. mini-httpd has different default files than apache2.

apache2 (current postinst):  index.html index.cgi index.pl index.php index.xhtml index.htm

mini-httpd (executable): index.html index.htm index.xhtml index.xht Default.htm index.cgi index.php index.mini-httpd.html

index.xht, Default.htm, and index.mini-httpd.html are missing in postinst, index.pl should not be in postinst.

I think this loop can replace the two nested for loops:

        local do_copy = true
        # note: file name list must match index_names[] in compiled mini_httpd.c, order is not important         for file in index.html index.htm index.xhtml index.xht Default.htm index.cgi index.php index.mini-httpd.html ; do
            if [ -e "/var/www/html/$file" ] ; then
                do_copy = false
                break
            fi
        done



Thanks

Alexander

On 31.01.2024 21:35, Alexandru Mihail wrote:
Hi,
Hello again !
I have some free time to test updated packages, the VM is still set
up
as described, so yes, I can help testing.

The package is tiny (less than 50 kBytes in bookworm), so simply send
it
by email to my address.

Beautiful, thanks for the help ! I've already tested things myself, but
an extra set of eyes helps. I'll attach by mail.
I'm not that experienced with apt and dpkg, I know they exist and
some
magic spells work fine to update the system. "apt-get install foo"
and
"apt-get remove foo" work fine, too. But that's about all I know.

Is "dkpg -i ./mini-httpd.deb" sufficient to update? If not, what
commands are needed?
Please do not use dpkg -i unless it's the only way for a legacy or
ultra-broken package (in general, not only here). dpkg is apt (and apt-
get)'s backend, and using it directly mucks up apt metadata and can
lead to bizarre results down the line. apt maintains a list of
installed packages, their dependency trees, cached downloads, etc; dpkg
does not and cannot know about all of these. :)
To install a local .deb package (for example, this package) please use
sudo apt install ./mini-httpd-blah.deb (notice the dot slash before the
package name).

To help with testing, I've added a couple of echo calls in the postinst
script, please look out for these to verify if the package behaves
correctly and send the full apt-get install logs to me if possible.

So:
If we're doing a fresh install you should first see:
Doing a fresh install !
If we're updating you should see this :
Not a fresh install, doing nothing!
and NO other COPY: messages written below.

Further, if fresh installing and /var/www/html/index.cgi or index.html
or index.php etc,etc,etc exists already you should see:
NOCOPY: index.extension exists ! and no files should be changed.

If installing and /var/www/html itself does not exist AND (logically)
no /var/www/html/index.something exist you should see:
COPY: /var/www/html not readable, but we want to copy index.html there.
we mkdir html.
followed by
COPY: we copied default index.html !

If installing and the /var/www/html folder exists, yet does not contain
any index.* files you should just see:
COPY: we copied default index.html !

Naturally, please (if possible) repeat your usual testing (manually
check if your files were overwritten or any other broken behavior).

Finally, after I release the update (if everything is OK) please sudo
apt purge mini-httpd to get rid of the unofficial deb I'm sending to
you now and just apt install mini-httpd to get the official one.

Thanks a lot for helping Debian !

Do you want to keep the Debian bugtracker in CC?

I'd prefer to, yes. All development related talks should be open as per
DebianFreeSoftwareGuidelines and other guidelines. Do you have any
issues with this? If so, please do tell and we can omit CC.
Greetings

Alexander Foken

Have a great day !
Alexandru Mihail
mini-httpd maintainer

--
Alexander Foken
mailto:alexan...@foken.de
root@debian-sid:~# wget -q -O /dev/stdout http://localhost/
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd";>
<html xmlns="http://www.w3.org/1999/xhtml";>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Welcome page</title>
</head>
<body>
It works!
</body>
</html>
root@debian-sid:~# rm /var/www/html/index.
index.cgi   index.html
root@debian-sid:~# rm /var/www/html/index.html
root@debian-sid:~# wget -q -O /dev/stdout http://localhost/
*** HELLO FROM CGI ***
root@debian-sid:~# echo UPDATING mini-httpd
UPDATING mini-httpd
root@debian-sid:~# apt install /tmp/mini-httpd_1.30-8_amd64.deb
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
Note, selecting 'mini-httpd' instead of '/tmp/mini-httpd_1.30-8_amd64.deb'
The following packages were automatically installed and are no longer required:
  libcbor0.8 libfuse2 libperl5.36 linux-image-6.1.0-15-amd64 perl-modules-5.36
Use 'apt autoremove' to remove them.
The following packages will be upgraded:
  mini-httpd
1 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
Need to get 0 B/44.7 kB of archives.
After this operation, 0 B of additional disk space will be used.
Get:1 /tmp/mini-httpd_1.30-8_amd64.deb mini-httpd amd64 1.30-8 [44.7 kB]
Reading changelogs... Done
(Reading database ... 40751 files and directories currently installed.)
Preparing to unpack .../mini-httpd_1.30-8_amd64.deb ...
Unpacking mini-httpd (1.30-8) over (1.30-7) ...
Setting up mini-httpd (1.30-8) ...
Not a fresh install, doing nothing!
Processing triggers for man-db (2.12.0-3) ...
root@debian-sid:~# wget -q -O /dev/stdout http://localhost/
*** HELLO FROM CGI ***
root@debian-sid:~# ls -alF /var/www/html
total 12
drwxr-xr-x 2 root root 4096 Jan 31 22:15 ./
drwxr-xr-x 3 root root 4096 Jan 28 11:41 ../
-rwxr-xr-x 1 root root   86 Jan 28 11:55 index.cgi*
root@debian-sid:~# apt purge mini-httpd
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following packages were automatically installed and are no longer required:
  apache2-utils libapr1 libaprutil1 libcbor0.8 libfuse2 libperl5.36
  linux-image-6.1.0-15-amd64 perl-modules-5.36
Use 'apt autoremove' to remove them.
The following packages will be REMOVED:
  mini-httpd*
0 upgraded, 0 newly installed, 1 to remove and 0 not upgraded.
After this operation, 128 kB disk space will be freed.
Do you want to continue? [Y/n]
(Reading database ... 40751 files and directories currently installed.)
Removing mini-httpd (1.30-8) ...
Processing triggers for man-db (2.12.0-3) ...
(Reading database ... 40739 files and directories currently installed.)
Purging configuration files for mini-httpd (1.30-8) ...
root@debian-sid:~# ls -alF /var/www/html
total 12
drwxr-xr-x 2 root root 4096 Jan 31 22:15 ./
drwxr-xr-x 3 root root 4096 Jan 28 11:41 ../
-rwxr-xr-x 1 root root   86 Jan 28 11:55 index.cgi*
root@debian-sid:~# echo INSTALLING mini-httpd WITH EXISTING WEBSITE
INSTALLING mini-httpd WITH EXISTING WEBSITE
root@debian-sid:~# apt install /tmp/mini-httpd_1.30-8_amd64.deb
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
Note, selecting 'mini-httpd' instead of '/tmp/mini-httpd_1.30-8_amd64.deb'
The following packages were automatically installed and are no longer required:
  libcbor0.8 libfuse2 libperl5.36 linux-image-6.1.0-15-amd64 perl-modules-5.36
Use 'apt autoremove' to remove them.
The following NEW packages will be installed:
  mini-httpd
0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded.
Need to get 0 B/44.7 kB of archives.
After this operation, 128 kB of additional disk space will be used.
Get:1 /tmp/mini-httpd_1.30-8_amd64.deb mini-httpd amd64 1.30-8 [44.7 kB]
Selecting previously unselected package mini-httpd.
(Reading database ... 40736 files and directories currently installed.)
Preparing to unpack .../mini-httpd_1.30-8_amd64.deb ...
Unpacking mini-httpd (1.30-8) ...
Setting up mini-httpd (1.30-8) ...
Doing a fresh install !
NOCOPY: index.cgi exists !
Created symlink /etc/systemd/system/multi-user.target.wants/mini-httpd.service 
→ /usr/lib/systemd/system/mini-httpd.service.
Processing triggers for man-db (2.12.0-3) ...
root@debian-sid:~# wget -q -O /dev/stdout http://localhost/
#!/bin/bash
echo -en "Content-Type: text/plain\r\n\r\n"
echo "*** HELLO FROM CGI ***"
root@debian-sid:~# echo '(my fault, did not enable CGI)'
(my fault, did not enable CGI)
root@debian-sid:~# ls -alF /var/www/html
total 12
drwxr-xr-x 2 root root 4096 Jan 31 22:15 ./
drwxr-xr-x 3 root root 4096 Jan 28 11:41 ../
-rwxr-xr-x 1 root root   86 Jan 28 11:55 index.cgi*
root@debian-sid:~# apt purge mini-httpd
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following packages were automatically installed and are no longer required:
  apache2-utils libapr1 libaprutil1 libcbor0.8 libfuse2 libperl5.36
  linux-image-6.1.0-15-amd64 perl-modules-5.36
Use 'apt autoremove' to remove them.
The following packages will be REMOVED:
  mini-httpd*
0 upgraded, 0 newly installed, 1 to remove and 0 not upgraded.
After this operation, 128 kB disk space will be freed.
Do you want to continue? [Y/n]
(Reading database ... 40751 files and directories currently installed.)
Removing mini-httpd (1.30-8) ...
Processing triggers for man-db (2.12.0-3) ...
(Reading database ... 40739 files and directories currently installed.)
Purging configuration files for mini-httpd (1.30-8) ...
root@debian-sid:~# rm -rf /var/
backups/  lib/      lock/     mail/     run/      tmp/      www/
cache/    local/    log/      opt/      spool/    .updated
root@debian-sid:~# rm -rf /var/www
root@debian-sid:~# echo INSTALLING mini-httpd WITHOUT EXISTING WEBSITE
INSTALLING mini-httpd WITHOUT EXISTING WEBSITE
root@debian-sid:~# apt install /tmp/mini-httpd_1.30-8_amd64.deb
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
Note, selecting 'mini-httpd' instead of '/tmp/mini-httpd_1.30-8_amd64.deb'
The following packages were automatically installed and are no longer required:
  libcbor0.8 libfuse2 libperl5.36 linux-image-6.1.0-15-amd64 perl-modules-5.36
Use 'apt autoremove' to remove them.
The following NEW packages will be installed:
  mini-httpd
0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded.
Need to get 0 B/44.7 kB of archives.
After this operation, 128 kB of additional disk space will be used.
Get:1 /tmp/mini-httpd_1.30-8_amd64.deb mini-httpd amd64 1.30-8 [44.7 kB]
Selecting previously unselected package mini-httpd.
(Reading database ... 40736 files and directories currently installed.)
Preparing to unpack .../mini-httpd_1.30-8_amd64.deb ...
Unpacking mini-httpd (1.30-8) ...
Setting up mini-httpd (1.30-8) ...
Doing a fresh install !
COPY: /var/www/html not readable, but we want to copy index.html there. we 
mkdir html.
COPY: we copied default index.html !
Created symlink /etc/systemd/system/multi-user.target.wants/mini-httpd.service 
→ /usr/lib/systemd/system/mini-httpd.service.
Processing triggers for man-db (2.12.0-3) ...
root@debian-sid:~# ls -alF /var/www/html
total 12
drwxr-xr-x 2 root root 4096 Jan 31 22:29 ./
drwxr-xr-x 3 root root 4096 Jan 31 22:29 ../
-rw-r--r-- 1 root root  312 Jan 31 22:29 index.html
root@debian-sid:~# wget -q -O /dev/stdout http://localhost/
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd";>
<html xmlns="http://www.w3.org/1999/xhtml";>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Welcome page</title>
</head>
<body>
It works!
</body>
</html>
root@debian-sid:~#

Reply via email to