1

I'm trying to use pkgsrc on ubuntu 16.04 LTS.

Installation was vary easy.

$ cvs -q -z3 -d [email protected]:/cvsroot checkout -P pkgsrc
$ ./bootstrap --unprivileged

Then I installed unzip package from source. It looked success too.

$ cd pkgsrc/archivers/unzip/
$ bmake
$ bmake install
$ which unzip
/home/xxxx/pkg/bin/unzip

However it didn't work when it was executed.

$ cd ~

$ ls
aaa.zip

$unzip aaa.zip
UnZip 6.00 of 20 April 2009, by Info-ZIP.  Maintained by C. Spieler.  Send
bug reports using http://www.info-zip.org/zip-bug.html; see README for details.

Usage: unzip [-Z] [-opts[modifiers]] file[.zip] [list] [-x xlist] [-d exdir]
  Default action is to extract files in list, except those in xlist, to exdir;
  file[.zip] may be a wildcard.  -Z => ZipInfo mode ("unzip -Z" for usage).

  -p  extract files to pipe, no messages     -l  list files (short format)
  -f  freshen existing files, create none    -t  test compressed archive data
  -u  update files, create if necessary      -z  display archive comment only
  -v  list verbosely/show version info       -T  timestamp archive to latest
  -x  exclude files that follow (in xlist)   -d  extract files into exdir
modifiers:
  -n  never overwrite existing files         -q  quiet mode (-qq => quieter)
  -o  overwrite files WITHOUT prompting      -a  auto-convert any text files
  -j  junk paths (do not make directories)   -aa treat ALL files as text
  -C  match filenames case-insensitively     -L  make (some) names lowercase
  -X  restore UID/GID info                   -V  retain VMS version numbers
  -K  keep setuid/setgid/tacky permissions   -M  pipe through "more" pager
See "unzip -hh" or unzip.txt for more help.  Examples:
  unzip data1 -x joe   => extract all files except joe from zipfile data1.zip
  unzip -p foo | more  => send contents of foo.zip via pipe into program more
  unzip -fo foo ReadMe => quietly replace existing ReadMe if archive file newer

$ echo $?
10

$ ls
aaa.zip

The error code was 10, which means invalid options were specified on the command line. Why? I didn't think I added any options. I was confused.

So I deleted pkgsrc's unzip to compare ubuntu's unzip and it worked.

$ pkg_delete unzip

$ which unzip
/usr/bin/unzip

$ /usr/bin/unzip aaa.zip
Archive:  aaa.zip
 extracting: aaa.txt

$ls
aaa.txt aaa.zip

pkgsrc's unzip is broken? or did I overlook some settings I had to do?

update(2017-2-19 14:30): I'm reading the pkgsrc's source code(pkgsrc/archivers/unzip). it is generated after bmake. So far, I partially changed unzip.c as following:

-- unzip.c --
int MAIN(argc, argv)
  int argc;
  char *argv[];
{
  int r;

  CONSTRUCTGLOBALS();

  /* for debug ----> */
  int hoge;
  printf("argc %d\n", argc);
  for(hoge = 0; hoge < argc; hoge++){
     printf("argv[%d] %s\n", hoge, argv[hoge]);
  }
  /* for debug <---- */
    r = unzip(__G__ argc, argv);
    DESTROYGLOBALS();
    RETURN(r);
} 

....
....
int unzip(__G__ argc, argv)
  __GDEF
  int argc;
  char *argv[];
{
....
....
#endif /* !NO_ZIPINFO */

      /* for debug ----> */
      printf("argc: %d\n", argc);
      printf("&argc: %d\n", &argc);
      int hoge = 0;
      for(hoge = 0; hoge < argc; hoge++){
        printf("argv[%d]: %s\n", hoge, argv[hoge]);
      }
      /* for debug <---- */

      error = uz_opts(__G__ &argc, &argv);
}

int uz_opts(__G__ pargc, pargv)
  __GDEF
  int *pargc;
  char ***pargv;
{
...
...
  while (++argv, (--argc > 0 && *argv != NULL && **argv == '-')) {
    s = *argv + 1;
    while ((c = *s++) != 0) {    /* "!= 0":  prevent Turbo C warning */

    /* for debug ----> */
    printf("c: %c\n",c);
    /* for debug <---- */

#ifdef CMS_MVS
        switch (tolower(c))
#else
        switch (c)
#endif
       {
       case ('-'):
         ++negative;
         break;
       ...
       ...
       default:
         printf("SET ERROR\n"); /* for debug */
         error = TRUE;
         break;
       }
...
...
#endif /* !SFX */
  return USAGE(error);
...
...
}

#else /* !SFX */
#  ifdef VMS
#    define QUOT '\"'
#    define QUOTS "\""
#  else
#    define QUOT ' '
#    define QUOTS ""
#  endif

int usage(__G__ error)   /* return PK-type error code */
  __GDEF
  int error;
{
  if (error){
    /* for debug ----> */
    puts("PK_PARAM: L");
    /* for debug <---- */
    return PK_PARAM;
  } else {
  ...
  }
}

With this change I understood argc and argv is changed before uz_opts() in unzip(). And the option -O CP932, which is internally added, doesn't exist in the swich statement in uz_opts(), that cause exit code 10.

$ unzip aaa.zip
argc 2
argv[0] unzip
argv[1] /home/xxxx/aaa.zip
argc: 4
&argc: -740106452
argv[0]: unzip
argv[1]: -O
argv[2]: CP932
argv[3]: /home/xxxx/aaa.zip
c: O
SET ERROR
UnZip 6.00 of 20 April 2009, by Info-ZIP.  Maintained by C. Spieler.  Send
bug reports using http://www.info-zip.org/zip-bug.html; see README for details.

Usage: unzip [-Z] [-opts[modifiers]] file[.zip] [list] [-x xlist] [-d exdir]
  Default action is to extract files in list, except those in xlist, to exdir;
  file[.zip] may be a wildcard.  -Z => ZipInfo mode ("unzip -Z" for usage).

  -p  extract files to pipe, no messages     -l  list files (short format)
  -f  freshen existing files, create none    -t  test compressed archive data
  -u  update files, create if necessary      -z  display archive comment only
  -v  list verbosely/show version info       -T  timestamp archive to latest
  -x  exclude files that follow (in xlist)   -d  extract files into exdir
modifiers:
  -n  never overwrite existing files         -q  quiet mode (-qq => quieter)
  -o  overwrite files WITHOUT prompting      -a  auto-convert any text files
  -j  junk paths (do not make directories)   -aa treat ALL files as text
  -C  match filenames case-insensitively     -L  make (some) names lowercase
  -X  restore UID/GID info                   -V  retain VMS version numbers
  -K  keep setuid/setgid/tacky permissions   -M  pipe through "more" pager
See "unzip -hh" or unzip.txt for more help.  Examples:
  unzip data1 -x joe   => extract all files except joe from zipfile data1.zip
  unzip -p foo | more  => send contents of foo.zip via pipe into program more
  unzip -fo foo ReadMe => quietly replace existing ReadMe if archive file newer
PK_PARAM: L

Then I checked environment variables, it is there...

$env
...
... 
UNZIP=-O CP932

What is this? I couldn't confirm it in my .profile and .bashrc.

cul8er
  • 329
  • 3
  • 12
  • I suspect some incompatibility between the zips. – peterh Feb 18 '17 at 17:33
  • @peterh The `unzip` on Ubuntu yakkety is the same. – Kusalananda Feb 18 '17 at 17:41
  • I've just tested this with pkgsrc's unzip on Ubuntu Yakkety (16.10), and I can't reproduce it. – Kusalananda Feb 18 '17 at 18:29
  • my pkgsrc's unzip seems totally collapse. It doesn't work even `unzip -v`. I'm trying to read the source code and insert some output for debug. Otherwise, is it better to delete all pkgsrc and re-install? I installed postgresql server by pkgsrc, so it's helpful if I don't need to do that... – cul8er Feb 18 '17 at 19:18

1 Answers1

0

I understood the cause of this problem. It was an environment variable.

$ env | sort
...
...
UNZIP=-O CP932

According to this page(sorry, it is written in Japaese), this UNZIP variable is needed to extracting zip archives which are created in Windows and include multi byte characters such as Japanese one. I guess this variable is imported by Ubuntu's unzip package localized as Japanese version.

So, I had to disable the UNZIP variable as bellow:

$ UNZIP='' unzip aaa.zip
Archive:  aaa.zip
 extracting: aaa.txt

$ ls
aaa.zip aaa.txt
cul8er
  • 329
  • 3
  • 12