Radix cross Linux package tools

Package Tools – is a set of utilities to create, install, and update RcL packages

3 Commits   0 Branches   2 Tags
11c606a6 (kx 2023-04-11 01:18:34 +0300    1) 
11c606a6 (kx 2023-04-11 01:18:34 +0300    2) /**********************************************************************
11c606a6 (kx 2023-04-11 01:18:34 +0300    3) 
11c606a6 (kx 2023-04-11 01:18:34 +0300    4)   Copyright 2019 Andrey V.Kosteltsev
11c606a6 (kx 2023-04-11 01:18:34 +0300    5) 
11c606a6 (kx 2023-04-11 01:18:34 +0300    6)   Licensed under the Radix.pro License, Version 1.0 (the "License");
11c606a6 (kx 2023-04-11 01:18:34 +0300    7)   you may not use this file  except  in compliance with the License.
11c606a6 (kx 2023-04-11 01:18:34 +0300    8)   You may obtain a copy of the License at
11c606a6 (kx 2023-04-11 01:18:34 +0300    9) 
11c606a6 (kx 2023-04-11 01:18:34 +0300   10)      https://radix.pro/licenses/LICENSE-1.0-en_US.txt
11c606a6 (kx 2023-04-11 01:18:34 +0300   11) 
11c606a6 (kx 2023-04-11 01:18:34 +0300   12)   Unless required by applicable law or agreed to in writing, software
11c606a6 (kx 2023-04-11 01:18:34 +0300   13)   distributed under the License is distributed on an "AS IS" BASIS,
11c606a6 (kx 2023-04-11 01:18:34 +0300   14)   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
11c606a6 (kx 2023-04-11 01:18:34 +0300   15)   implied.
11c606a6 (kx 2023-04-11 01:18:34 +0300   16) 
11c606a6 (kx 2023-04-11 01:18:34 +0300   17)  **********************************************************************/
11c606a6 (kx 2023-04-11 01:18:34 +0300   18) 
11c606a6 (kx 2023-04-11 01:18:34 +0300   19) #include <config.h>
11c606a6 (kx 2023-04-11 01:18:34 +0300   20) 
11c606a6 (kx 2023-04-11 01:18:34 +0300   21) #include <stdlib.h>
11c606a6 (kx 2023-04-11 01:18:34 +0300   22) #include <stdio.h>
11c606a6 (kx 2023-04-11 01:18:34 +0300   23) #include <sys/sysinfo.h>
11c606a6 (kx 2023-04-11 01:18:34 +0300   24) #include <sys/types.h>
11c606a6 (kx 2023-04-11 01:18:34 +0300   25) #include <stdint.h>
11c606a6 (kx 2023-04-11 01:18:34 +0300   26) #include <dirent.h>
11c606a6 (kx 2023-04-11 01:18:34 +0300   27) #include <sys/stat.h> /* chmod(2)    */
11c606a6 (kx 2023-04-11 01:18:34 +0300   28) #include <sys/file.h> /* flock(2)    */
11c606a6 (kx 2023-04-11 01:18:34 +0300   29) #include <fcntl.h>
11c606a6 (kx 2023-04-11 01:18:34 +0300   30) #include <linux/limits.h>
11c606a6 (kx 2023-04-11 01:18:34 +0300   31) #include <alloca.h>   /* alloca(3)   */
11c606a6 (kx 2023-04-11 01:18:34 +0300   32) #include <string.h>   /* strdup(3)   */
11c606a6 (kx 2023-04-11 01:18:34 +0300   33) #include <strings.h>  /* index(3)    */
11c606a6 (kx 2023-04-11 01:18:34 +0300   34) #include <libgen.h>   /* basename(3) */
11c606a6 (kx 2023-04-11 01:18:34 +0300   35) #include <ctype.h>    /* tolower(3)  */
11c606a6 (kx 2023-04-11 01:18:34 +0300   36) #include <errno.h>
11c606a6 (kx 2023-04-11 01:18:34 +0300   37) #include <time.h>
11c606a6 (kx 2023-04-11 01:18:34 +0300   38) #include <sys/time.h>
11c606a6 (kx 2023-04-11 01:18:34 +0300   39) #include <pwd.h>
11c606a6 (kx 2023-04-11 01:18:34 +0300   40) #include <grp.h>
11c606a6 (kx 2023-04-11 01:18:34 +0300   41) #include <stdarg.h>
11c606a6 (kx 2023-04-11 01:18:34 +0300   42) #include <unistd.h>
11c606a6 (kx 2023-04-11 01:18:34 +0300   43) 
11c606a6 (kx 2023-04-11 01:18:34 +0300   44) #include <math.h>
11c606a6 (kx 2023-04-11 01:18:34 +0300   45) 
11c606a6 (kx 2023-04-11 01:18:34 +0300   46) #include <sys/wait.h>
11c606a6 (kx 2023-04-11 01:18:34 +0300   47) 
11c606a6 (kx 2023-04-11 01:18:34 +0300   48) #include <sys/resource.h>
11c606a6 (kx 2023-04-11 01:18:34 +0300   49) 
11c606a6 (kx 2023-04-11 01:18:34 +0300   50) #include <signal.h>
11c606a6 (kx 2023-04-11 01:18:34 +0300   51) #if !defined SIGCHLD && defined SIGCLD
11c606a6 (kx 2023-04-11 01:18:34 +0300   52) # define SIGCHLD SIGCLD
11c606a6 (kx 2023-04-11 01:18:34 +0300   53) #endif
11c606a6 (kx 2023-04-11 01:18:34 +0300   54) 
11c606a6 (kx 2023-04-11 01:18:34 +0300   55) #define _GNU_SOURCE
11c606a6 (kx 2023-04-11 01:18:34 +0300   56) #include <getopt.h>
11c606a6 (kx 2023-04-11 01:18:34 +0300   57) 
11c606a6 (kx 2023-04-11 01:18:34 +0300   58) #include <config.h>
11c606a6 (kx 2023-04-11 01:18:34 +0300   59) 
11c606a6 (kx 2023-04-11 01:18:34 +0300   60) #include <msglog.h>
11c606a6 (kx 2023-04-11 01:18:34 +0300   61) #include <wrapper.h>
11c606a6 (kx 2023-04-11 01:18:34 +0300   62) #include <system.h>
11c606a6 (kx 2023-04-11 01:18:34 +0300   63) 
11c606a6 (kx 2023-04-11 01:18:34 +0300   64) #include <cmpvers.h>
11c606a6 (kx 2023-04-11 01:18:34 +0300   65) #include <dlist.h>
11c606a6 (kx 2023-04-11 01:18:34 +0300   66) 
11c606a6 (kx 2023-04-11 01:18:34 +0300   67) #if defined( HAVE_DIALOG )
11c606a6 (kx 2023-04-11 01:18:34 +0300   68) #include <dialog-ui.h>
11c606a6 (kx 2023-04-11 01:18:34 +0300   69) #endif
11c606a6 (kx 2023-04-11 01:18:34 +0300   70) 
11c606a6 (kx 2023-04-11 01:18:34 +0300   71) #define PROGRAM_NAME "install-package"
11c606a6 (kx 2023-04-11 01:18:34 +0300   72) 
11c606a6 (kx 2023-04-11 01:18:34 +0300   73) #include <defs.h>
11c606a6 (kx 2023-04-11 01:18:34 +0300   74) 
11c606a6 (kx 2023-04-11 01:18:34 +0300   75) 
11c606a6 (kx 2023-04-11 01:18:34 +0300   76) char *program = PROGRAM_NAME;
11c606a6 (kx 2023-04-11 01:18:34 +0300   77) char *root = NULL, *pkgs_path = NULL, *rempkgs_path = NULL,
11c606a6 (kx 2023-04-11 01:18:34 +0300   78)      *pkg_fname = NULL, *asc_fname = NULL, *pkglog_fname = NULL, *pkglist_fname = NULL,
11c606a6 (kx 2023-04-11 01:18:34 +0300   79)      *tmpdir = NULL, *curdir = NULL, *log_fname = NULL;
11c606a6 (kx 2023-04-11 01:18:34 +0300   80) 
a745159c (kx 2023-10-23 21:39:58 +0300   81) int   ask = 0, rqck = 0, gpgck = 0, ignore_chrefs_errors = 0, disable_chrefs = 0;
11c606a6 (kx 2023-04-11 01:18:34 +0300   82) char *description = NULL;
11c606a6 (kx 2023-04-11 01:18:34 +0300   83) 
11c606a6 (kx 2023-04-11 01:18:34 +0300   84) int   exit_status = EXIT_SUCCESS; /* errors counter */
11c606a6 (kx 2023-04-11 01:18:34 +0300   85) char *selfdir     = NULL;
11c606a6 (kx 2023-04-11 01:18:34 +0300   86) 
11c606a6 (kx 2023-04-11 01:18:34 +0300   87) static char           *pkgname = NULL,
11c606a6 (kx 2023-04-11 01:18:34 +0300   88)                        *pkgver = NULL,
11c606a6 (kx 2023-04-11 01:18:34 +0300   89)                          *arch = NULL,
11c606a6 (kx 2023-04-11 01:18:34 +0300   90)                    *distroname = NULL,
11c606a6 (kx 2023-04-11 01:18:34 +0300   91)                     *distrover = NULL,
11c606a6 (kx 2023-04-11 01:18:34 +0300   92)                         *group = NULL,
11c606a6 (kx 2023-04-11 01:18:34 +0300   93)             *short_description = NULL,
11c606a6 (kx 2023-04-11 01:18:34 +0300   94)                           *url = NULL,
11c606a6 (kx 2023-04-11 01:18:34 +0300   95)                       *license = NULL,
11c606a6 (kx 2023-04-11 01:18:34 +0300   96)             *uncompressed_size = NULL,
11c606a6 (kx 2023-04-11 01:18:34 +0300   97)               *compressed_size = NULL,
11c606a6 (kx 2023-04-11 01:18:34 +0300   98)                   *total_files = NULL;
11c606a6 (kx 2023-04-11 01:18:34 +0300   99) 
11c606a6 (kx 2023-04-11 01:18:34 +0300  100) enum _install_mode {
11c606a6 (kx 2023-04-11 01:18:34 +0300  101)   CONSOLE = 0,
11c606a6 (kx 2023-04-11 01:18:34 +0300  102)   INFODIALOG,
11c606a6 (kx 2023-04-11 01:18:34 +0300  103)   MENUDIALOG
11c606a6 (kx 2023-04-11 01:18:34 +0300  104) } install_mode = CONSOLE;
11c606a6 (kx 2023-04-11 01:18:34 +0300  105) 
11c606a6 (kx 2023-04-11 01:18:34 +0300  106) enum _priority {
11c606a6 (kx 2023-04-11 01:18:34 +0300  107)   REQUIRED = 0, /* synonims: REQUIRED    | required    | REQ | req */
11c606a6 (kx 2023-04-11 01:18:34 +0300  108)   RECOMMENDED,  /* synonims: RECOMMENDED | recommended | REC | rec */
11c606a6 (kx 2023-04-11 01:18:34 +0300  109)   OPTIONAL,     /* synonims: OPTIONAL    | optional    | OPT | opt */
11c606a6 (kx 2023-04-11 01:18:34 +0300  110)   SKIP          /* synonims: SKIP        | skip        | SKP | skp */
11c606a6 (kx 2023-04-11 01:18:34 +0300  111) } priority = REQUIRED;
11c606a6 (kx 2023-04-11 01:18:34 +0300  112) 
11c606a6 (kx 2023-04-11 01:18:34 +0300  113) enum _procedure
11c606a6 (kx 2023-04-11 01:18:34 +0300  114) {
11c606a6 (kx 2023-04-11 01:18:34 +0300  115)   INSTALL = 0, /* 'install' */
11c606a6 (kx 2023-04-11 01:18:34 +0300  116)   UPDATE       /* 'update'  */
11c606a6 (kx 2023-04-11 01:18:34 +0300  117) } procedure = INSTALL;
11c606a6 (kx 2023-04-11 01:18:34 +0300  118) 
11c606a6 (kx 2023-04-11 01:18:34 +0300  119) enum _input_type {
11c606a6 (kx 2023-04-11 01:18:34 +0300  120)   IFMT_PKG = 0,
11c606a6 (kx 2023-04-11 01:18:34 +0300  121)   IFMT_LOG,
11c606a6 (kx 2023-04-11 01:18:34 +0300  122) 
11c606a6 (kx 2023-04-11 01:18:34 +0300  123)   IFMT_UNKNOWN
11c606a6 (kx 2023-04-11 01:18:34 +0300  124) } input_format = IFMT_PKG;
11c606a6 (kx 2023-04-11 01:18:34 +0300  125) 
11c606a6 (kx 2023-04-11 01:18:34 +0300  126) char  uncompress = '\0';
11c606a6 (kx 2023-04-11 01:18:34 +0300  127) 
11c606a6 (kx 2023-04-11 01:18:34 +0300  128) static struct dlist *dirs  = NULL;
11c606a6 (kx 2023-04-11 01:18:34 +0300  129) static struct dlist *files = NULL;
11c606a6 (kx 2023-04-11 01:18:34 +0300  130) static struct dlist *links = NULL;
11c606a6 (kx 2023-04-11 01:18:34 +0300  131) 
11c606a6 (kx 2023-04-11 01:18:34 +0300  132) static void free_list( struct dlist *list );
11c606a6 (kx 2023-04-11 01:18:34 +0300  133) 
11c606a6 (kx 2023-04-11 01:18:34 +0300  134) 
11c606a6 (kx 2023-04-11 01:18:34 +0300  135) #define FREE_PKGINFO_VARIABLES() \
11c606a6 (kx 2023-04-11 01:18:34 +0300  136)   if( pkgname )           { free( pkgname );           } pkgname = NULL;            \
11c606a6 (kx 2023-04-11 01:18:34 +0300  137)   if( pkgver )            { free( pkgver );            } pkgver = NULL;             \
11c606a6 (kx 2023-04-11 01:18:34 +0300  138)   if( arch )              { free( arch );              } arch = NULL;               \
11c606a6 (kx 2023-04-11 01:18:34 +0300  139)   if( distroname )        { free( distroname );        } distroname = NULL;         \
11c606a6 (kx 2023-04-11 01:18:34 +0300  140)   if( distrover )         { free( distrover );         } distrover = NULL;          \
11c606a6 (kx 2023-04-11 01:18:34 +0300  141)   if( group )             { free( group );             } group = NULL;              \
11c606a6 (kx 2023-04-11 01:18:34 +0300  142)   if( short_description ) { free( short_description ); } short_description = NULL;  \
11c606a6 (kx 2023-04-11 01:18:34 +0300  143)   if( description )       { free( description );       } description = NULL;        \
11c606a6 (kx 2023-04-11 01:18:34 +0300  144)   if( url )               { free( url );               } url = NULL;                \
11c606a6 (kx 2023-04-11 01:18:34 +0300  145)   if( license )           { free( license );           } license = NULL;            \
11c606a6 (kx 2023-04-11 01:18:34 +0300  146)   if( uncompressed_size ) { free( uncompressed_size ); } uncompressed_size = NULL;  \
11c606a6 (kx 2023-04-11 01:18:34 +0300  147)   if( compressed_size )   { free( compressed_size );   } compressed_size = NULL;    \
11c606a6 (kx 2023-04-11 01:18:34 +0300  148)   if( total_files )       { free( total_files );       } total_files = NULL
11c606a6 (kx 2023-04-11 01:18:34 +0300  149) 
11c606a6 (kx 2023-04-11 01:18:34 +0300  150) void free_resources()
11c606a6 (kx 2023-04-11 01:18:34 +0300  151) {
11c606a6 (kx 2023-04-11 01:18:34 +0300  152)   if( root )          { free( root );          root          = NULL; }
11c606a6 (kx 2023-04-11 01:18:34 +0300  153)   if( pkgs_path )     { free( pkgs_path );     pkgs_path     = NULL; }
11c606a6 (kx 2023-04-11 01:18:34 +0300  154)   if( rempkgs_path )  { free( rempkgs_path );  rempkgs_path  = NULL; }
11c606a6 (kx 2023-04-11 01:18:34 +0300  155)   if( pkg_fname )     { free( pkg_fname );     pkg_fname     = NULL; }
11c606a6 (kx 2023-04-11 01:18:34 +0300  156)   if( asc_fname )     { free( asc_fname );     asc_fname     = NULL; }
11c606a6 (kx 2023-04-11 01:18:34 +0300  157)   if( pkglog_fname )  { free( pkglog_fname );  pkglog_fname  = NULL; }
11c606a6 (kx 2023-04-11 01:18:34 +0300  158) 
11c606a6 (kx 2023-04-11 01:18:34 +0300  159)   if( pkglist_fname ) { free( pkglist_fname ); pkglist_fname = NULL; }
11c606a6 (kx 2023-04-11 01:18:34 +0300  160) 
11c606a6 (kx 2023-04-11 01:18:34 +0300  161)   if( dirs )          { free_list( dirs );     dirs          = NULL; }
11c606a6 (kx 2023-04-11 01:18:34 +0300  162)   if( files )         { free_list( files );    files         = NULL; }
11c606a6 (kx 2023-04-11 01:18:34 +0300  163)   if( links )         { free_list( links );    links         = NULL; }
11c606a6 (kx 2023-04-11 01:18:34 +0300  164) 
11c606a6 (kx 2023-04-11 01:18:34 +0300  165)   if( curdir )        { free( curdir );        curdir        = NULL; }
11c606a6 (kx 2023-04-11 01:18:34 +0300  166)   if( log_fname )     { free( log_fname );     log_fname     = NULL; }
11c606a6 (kx 2023-04-11 01:18:34 +0300  167) 
11c606a6 (kx 2023-04-11 01:18:34 +0300  168)   if( selfdir )       { free( selfdir );       selfdir       = NULL; }
11c606a6 (kx 2023-04-11 01:18:34 +0300  169) 
11c606a6 (kx 2023-04-11 01:18:34 +0300  170)   FREE_PKGINFO_VARIABLES();
11c606a6 (kx 2023-04-11 01:18:34 +0300  171) }
11c606a6 (kx 2023-04-11 01:18:34 +0300  172) 
11c606a6 (kx 2023-04-11 01:18:34 +0300  173) void usage()
11c606a6 (kx 2023-04-11 01:18:34 +0300  174) {
11c606a6 (kx 2023-04-11 01:18:34 +0300  175)   free_resources();
11c606a6 (kx 2023-04-11 01:18:34 +0300  176) 
11c606a6 (kx 2023-04-11 01:18:34 +0300  177)   fprintf( stdout, "\n" );
11c606a6 (kx 2023-04-11 01:18:34 +0300  178)   fprintf( stdout, "Usage: %s [options] <package>\n", program );
11c606a6 (kx 2023-04-11 01:18:34 +0300  179)   fprintf( stdout, "\n" );
11c606a6 (kx 2023-04-11 01:18:34 +0300  180)   fprintf( stdout, "Install package.\n" );
11c606a6 (kx 2023-04-11 01:18:34 +0300  181)   fprintf( stdout, "\n" );
11c606a6 (kx 2023-04-11 01:18:34 +0300  182)   fprintf( stdout, "Options:\n" );
11c606a6 (kx 2023-04-11 01:18:34 +0300  183)   fprintf( stdout, "  -h,--help                     Display this information.\n" );
11c606a6 (kx 2023-04-11 01:18:34 +0300  184)   fprintf( stdout, "  -v,--version                  Display the version of %s utility.\n", program );
11c606a6 (kx 2023-04-11 01:18:34 +0300  185)   fprintf( stdout, "  -a,--always-ask               Used with menudialog mode: always ask\n" );
11c606a6 (kx 2023-04-11 01:18:34 +0300  186)   fprintf( stdout, "                                if a package should be installed regardless\n" );
11c606a6 (kx 2023-04-11 01:18:34 +0300  187)   fprintf( stdout, "                                of what the package priority is. Without\n" );
11c606a6 (kx 2023-04-11 01:18:34 +0300  188)   fprintf( stdout, "                                this option, if the priority is equal to\n" );
11c606a6 (kx 2023-04-11 01:18:34 +0300  189)   fprintf( stdout, "                                REQUIRED, the package is installed without\n" );
11c606a6 (kx 2023-04-11 01:18:34 +0300  190)   fprintf( stdout, "                                asking for confirmation the installation.\n" );
11c606a6 (kx 2023-04-11 01:18:34 +0300  191)   fprintf( stdout, "  -c,--check-requires           Check package requires before install.\n" );
11c606a6 (kx 2023-04-11 01:18:34 +0300  192) #if defined( HAVE_GPG2 )
11c606a6 (kx 2023-04-11 01:18:34 +0300  193)   fprintf( stdout, "  -g,--gpg-verify               Verify GPG2 signature. The signature must be\n" );
11c606a6 (kx 2023-04-11 01:18:34 +0300  194)   fprintf( stdout, "                                saved in a file whose name is the same as the\n" );
11c606a6 (kx 2023-04-11 01:18:34 +0300  195)   fprintf( stdout, "                                package file name, but with the extension '.asc'\n" );
11c606a6 (kx 2023-04-11 01:18:34 +0300  196)   fprintf( stdout, "                                and located in the same directory as the package.\n" );
11c606a6 (kx 2023-04-11 01:18:34 +0300  197) #endif
11c606a6 (kx 2023-04-11 01:18:34 +0300  198)   fprintf( stdout, "  --ignore-chrefs-errors        Ignore change references errors (code: 48).\n" );
a745159c (kx 2023-10-23 21:39:58 +0300  199)   fprintf( stdout, "  --disable-chrefs              Do not manage references to the package.\n" );
11c606a6 (kx 2023-04-11 01:18:34 +0300  200) #if defined( HAVE_DIALOG )
11c606a6 (kx 2023-04-11 01:18:34 +0300  201)   fprintf( stdout, "  -i,--info-dialog              Show package description during install\n" );
11c606a6 (kx 2023-04-11 01:18:34 +0300  202)   fprintf( stdout, "                                process using ncurses dialog.\n" );
11c606a6 (kx 2023-04-11 01:18:34 +0300  203)   fprintf( stdout, "  -m,--menu-dialog              Ask for confirmation the inatallation,\n" );
11c606a6 (kx 2023-04-11 01:18:34 +0300  204)   fprintf( stdout, "                                unless the priority is REQUIRED.\n" );
11c606a6 (kx 2023-04-11 01:18:34 +0300  205) #endif
11c606a6 (kx 2023-04-11 01:18:34 +0300  206)   fprintf( stdout, "  -l,--pkglist=<FILENAME>       Specify a different package list file\n" );
11c606a6 (kx 2023-04-11 01:18:34 +0300  207)   fprintf( stdout, "                                to use for read package priority and type\n" );
11c606a6 (kx 2023-04-11 01:18:34 +0300  208)   fprintf( stdout, "                                of install procedure. By default used the\n" );
11c606a6 (kx 2023-04-11 01:18:34 +0300  209)   fprintf( stdout, "                                '.pkglist' file found in the directory\n" );
11c606a6 (kx 2023-04-11 01:18:34 +0300  210)   fprintf( stdout, "                                where source package is placed.\n" );
11c606a6 (kx 2023-04-11 01:18:34 +0300  211)   fprintf( stdout, "  -p,--priority=<required|recommended|optional|skip>\n" );
11c606a6 (kx 2023-04-11 01:18:34 +0300  212)   fprintf( stdout, "                                Provides a priority of package instead of\n" );
11c606a6 (kx 2023-04-11 01:18:34 +0300  213)   fprintf( stdout, "                                the priority defined in the .pkglist file.\n" );
11c606a6 (kx 2023-04-11 01:18:34 +0300  214)   fprintf( stdout, "  -r,--root=<DIR>               Target rootfs path.\n" );
11c606a6 (kx 2023-04-11 01:18:34 +0300  215)   fprintf( stdout, "\n" );
11c606a6 (kx 2023-04-11 01:18:34 +0300  216)   fprintf( stdout, "Parameter:\n" );
11c606a6 (kx 2023-04-11 01:18:34 +0300  217)   fprintf( stdout, "  <package>                     The PACKAGE tarball.\n" );
11c606a6 (kx 2023-04-11 01:18:34 +0300  218)   fprintf( stdout, "\n" );
11c606a6 (kx 2023-04-11 01:18:34 +0300  219)   fprintf( stdout, "Return codes:\n" );
11c606a6 (kx 2023-04-11 01:18:34 +0300  220)   fprintf( stdout, "  ------+-------------------------------------------------------\n" );
11c606a6 (kx 2023-04-11 01:18:34 +0300  221)   fprintf( stdout, "   code | status\n"  );
11c606a6 (kx 2023-04-11 01:18:34 +0300  222)   fprintf( stdout, "  ------+-------------------------------------------------------\n" );
11c606a6 (kx 2023-04-11 01:18:34 +0300  223)   fprintf( stdout, "     31 | package is already installed\n" );
11c606a6 (kx 2023-04-11 01:18:34 +0300  224)   fprintf( stdout, "     32 | package is already installed but not correct\n" );
11c606a6 (kx 2023-04-11 01:18:34 +0300  225)   fprintf( stdout, "     33 | previous version is already installed\n" );
11c606a6 (kx 2023-04-11 01:18:34 +0300  226)   fprintf( stdout, "     34 | previous version is already installed but not correct\n" );
11c606a6 (kx 2023-04-11 01:18:34 +0300  227)   fprintf( stdout, "     35 | a newer version is already installed\n" );
11c606a6 (kx 2023-04-11 01:18:34 +0300  228)   fprintf( stdout, "     36 | a newer version is already installed but not correct\n" );
11c606a6 (kx 2023-04-11 01:18:34 +0300  229)   fprintf( stdout, "    ----+----\n" );
11c606a6 (kx 2023-04-11 01:18:34 +0300  230)   fprintf( stdout, "     41 | installation is aborted due to priority=SKIP\n" );
11c606a6 (kx 2023-04-11 01:18:34 +0300  231)   fprintf( stdout, "     42 | .pkglist appointed the 'update' procedure instead\n" );
11c606a6 (kx 2023-04-11 01:18:34 +0300  232)   fprintf( stdout, "     43 | pre-install script returned error status\n" );
11c606a6 (kx 2023-04-11 01:18:34 +0300  233)   fprintf( stdout, "     44 | uncompress process returned error status\n" );
11c606a6 (kx 2023-04-11 01:18:34 +0300  234)   fprintf( stdout, "     45 | restore-links script returned error status\n" );
11c606a6 (kx 2023-04-11 01:18:34 +0300  235)   fprintf( stdout, "     46 | post-install script returned error status\n" );
11c606a6 (kx 2023-04-11 01:18:34 +0300  236)   fprintf( stdout, "     47 | PKGLOG cannot be stored in the Setup Database\n" );
11c606a6 (kx 2023-04-11 01:18:34 +0300  237)   fprintf( stdout, "     48 | references cannot be updated in Setup Database\n" );
11c606a6 (kx 2023-04-11 01:18:34 +0300  238) #if defined( HAVE_GPG2 )
11c606a6 (kx 2023-04-11 01:18:34 +0300  239)   fprintf( stdout, "    ----+----\n" );
11c606a6 (kx 2023-04-11 01:18:34 +0300  240)   fprintf( stdout, "     51 | signature verification returned error status\n" );
11c606a6 (kx 2023-04-11 01:18:34 +0300  241) #endif
11c606a6 (kx 2023-04-11 01:18:34 +0300  242)   fprintf( stdout, "  ------+-------------------------------------------------------\n"  );
11c606a6 (kx 2023-04-11 01:18:34 +0300  243)   fprintf( stdout, "\n" );
11c606a6 (kx 2023-04-11 01:18:34 +0300  244)   fprintf( stdout, "Upon successful completion zero is returned. Other non-zero return\n" );
11c606a6 (kx 2023-04-11 01:18:34 +0300  245)   fprintf( stdout, "codes imply incorrect completion of the installation.\n" );
11c606a6 (kx 2023-04-11 01:18:34 +0300  246)   fprintf( stdout, "\n" );
11c606a6 (kx 2023-04-11 01:18:34 +0300  247) 
11c606a6 (kx 2023-04-11 01:18:34 +0300  248)   exit( EXIT_FAILURE );
11c606a6 (kx 2023-04-11 01:18:34 +0300  249) }
11c606a6 (kx 2023-04-11 01:18:34 +0300  250) 
11c606a6 (kx 2023-04-11 01:18:34 +0300  251) void to_lowercase( char *s )
11c606a6 (kx 2023-04-11 01:18:34 +0300  252) {
11c606a6 (kx 2023-04-11 01:18:34 +0300  253)   char *p = s;
11c606a6 (kx 2023-04-11 01:18:34 +0300  254)   while( p && *p ) { int c = *p; *p = tolower( c ); ++p; }
11c606a6 (kx 2023-04-11 01:18:34 +0300  255) }
11c606a6 (kx 2023-04-11 01:18:34 +0300  256) 
11c606a6 (kx 2023-04-11 01:18:34 +0300  257) void to_uppercase( char *s )
11c606a6 (kx 2023-04-11 01:18:34 +0300  258) {
11c606a6 (kx 2023-04-11 01:18:34 +0300  259)   char *p = s;
11c606a6 (kx 2023-04-11 01:18:34 +0300  260)   while( p && *p ) { int c = *p; *p = toupper( c ); ++p; }
11c606a6 (kx 2023-04-11 01:18:34 +0300  261) }
11c606a6 (kx 2023-04-11 01:18:34 +0300  262) 
11c606a6 (kx 2023-04-11 01:18:34 +0300  263) void version()
11c606a6 (kx 2023-04-11 01:18:34 +0300  264) {
11c606a6 (kx 2023-04-11 01:18:34 +0300  265)   char *upper = NULL;
11c606a6 (kx 2023-04-11 01:18:34 +0300  266) 
11c606a6 (kx 2023-04-11 01:18:34 +0300  267)   upper = (char *)alloca( strlen( program ) + 1 );
11c606a6 (kx 2023-04-11 01:18:34 +0300  268) 
11c606a6 (kx 2023-04-11 01:18:34 +0300  269)   strcpy( (char *)upper, (const char *)program );
11c606a6 (kx 2023-04-11 01:18:34 +0300  270)   to_uppercase( upper );
11c606a6 (kx 2023-04-11 01:18:34 +0300  271) 
11c606a6 (kx 2023-04-11 01:18:34 +0300  272)   fprintf( stdout, "%s (%s) %s\n", program, upper, PROGRAM_VERSION );
11c606a6 (kx 2023-04-11 01:18:34 +0300  273) 
11c606a6 (kx 2023-04-11 01:18:34 +0300  274)   fprintf( stdout, "Copyright (C) 2019 Andrey V.Kosteltsev.\n" );
11c606a6 (kx 2023-04-11 01:18:34 +0300  275)   fprintf( stdout, "This is free software.   There is NO warranty; not even\n" );
11c606a6 (kx 2023-04-11 01:18:34 +0300  276)   fprintf( stdout, "for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n" );
11c606a6 (kx 2023-04-11 01:18:34 +0300  277)   fprintf( stdout, "\n" );
11c606a6 (kx 2023-04-11 01:18:34 +0300  278) 
11c606a6 (kx 2023-04-11 01:18:34 +0300  279)   free_resources();
11c606a6 (kx 2023-04-11 01:18:34 +0300  280)   exit( EXIT_SUCCESS );
11c606a6 (kx 2023-04-11 01:18:34 +0300  281) }
11c606a6 (kx 2023-04-11 01:18:34 +0300  282) 
11c606a6 (kx 2023-04-11 01:18:34 +0300  283) 
11c606a6 (kx 2023-04-11 01:18:34 +0300  284) static void remove_trailing_slash( char *dir )
11c606a6 (kx 2023-04-11 01:18:34 +0300  285) {
11c606a6 (kx 2023-04-11 01:18:34 +0300  286)   char *s;
11c606a6 (kx 2023-04-11 01:18:34 +0300  287) 
11c606a6 (kx 2023-04-11 01:18:34 +0300  288)   if( !dir || dir[0] == '\0' ) return;
11c606a6 (kx 2023-04-11 01:18:34 +0300  289) 
11c606a6 (kx 2023-04-11 01:18:34 +0300  290)   s = dir + strlen( dir ) - 1;
11c606a6 (kx 2023-04-11 01:18:34 +0300  291)   while( *s == '/' )
11c606a6 (kx 2023-04-11 01:18:34 +0300  292)   {
11c606a6 (kx 2023-04-11 01:18:34 +0300  293)     *s = '\0'; --s;
11c606a6 (kx 2023-04-11 01:18:34 +0300  294)   }
11c606a6 (kx 2023-04-11 01:18:34 +0300  295) }
11c606a6 (kx 2023-04-11 01:18:34 +0300  296) 
11c606a6 (kx 2023-04-11 01:18:34 +0300  297) 
11c606a6 (kx 2023-04-11 01:18:34 +0300  298) static void bind_asc_extention( char *name )
11c606a6 (kx 2023-04-11 01:18:34 +0300  299) {
11c606a6 (kx 2023-04-11 01:18:34 +0300  300)   char *p = NULL, *q = NULL;
11c606a6 (kx 2023-04-11 01:18:34 +0300  301) 
11c606a6 (kx 2023-04-11 01:18:34 +0300  302)   if( (p = rindex( name, '.' )) && (strlen(p) < 5) )
11c606a6 (kx 2023-04-11 01:18:34 +0300  303)   {
11c606a6 (kx 2023-04-11 01:18:34 +0300  304)     if( !strncmp( p, ".gz",  3 ) ||
11c606a6 (kx 2023-04-11 01:18:34 +0300  305)         !strncmp( p, ".bz2", 4 ) ||
11c606a6 (kx 2023-04-11 01:18:34 +0300  306)         !strncmp( p, ".xz",  3 )   )
11c606a6 (kx 2023-04-11 01:18:34 +0300  307)     {
11c606a6 (kx 2023-04-11 01:18:34 +0300  308)       *p = '\0';
11c606a6 (kx 2023-04-11 01:18:34 +0300  309)       q = rindex( name, '.' );
11c606a6 (kx 2023-04-11 01:18:34 +0300  310)       if( q && (strlen(q) < 5) && !strncmp( q, ".tar", 4 ) )
11c606a6 (kx 2023-04-11 01:18:34 +0300  311)       {
11c606a6 (kx 2023-04-11 01:18:34 +0300  312)         *q = '\0';
11c606a6 (kx 2023-04-11 01:18:34 +0300  313)       }
11c606a6 (kx 2023-04-11 01:18:34 +0300  314)     }
11c606a6 (kx 2023-04-11 01:18:34 +0300  315)     else if( !strncmp( p, ".tar", 4 ) ||
11c606a6 (kx 2023-04-11 01:18:34 +0300  316)              !strncmp( p, ".tbz", 4 ) ||
11c606a6 (kx 2023-04-11 01:18:34 +0300  317)              !strncmp( p, ".tgz", 4 ) ||
11c606a6 (kx 2023-04-11 01:18:34 +0300  318)              !strncmp( p, ".txz", 4 )   )
11c606a6 (kx 2023-04-11 01:18:34 +0300  319)     {
11c606a6 (kx 2023-04-11 01:18:34 +0300  320)       *p = '\0';
11c606a6 (kx 2023-04-11 01:18:34 +0300  321)     }
11c606a6 (kx 2023-04-11 01:18:34 +0300  322)   }
11c606a6 (kx 2023-04-11 01:18:34 +0300  323) 
11c606a6 (kx 2023-04-11 01:18:34 +0300  324)   (void)strcat( name, ".asc" );
11c606a6 (kx 2023-04-11 01:18:34 +0300  325) }
11c606a6 (kx 2023-04-11 01:18:34 +0300  326) 
11c606a6 (kx 2023-04-11 01:18:34 +0300  327) ////////////////////////////////////////////////////
11c606a6 (kx 2023-04-11 01:18:34 +0300  328) //static char *strmode( enum _install_mode mode )
11c606a6 (kx 2023-04-11 01:18:34 +0300  329) //{
11c606a6 (kx 2023-04-11 01:18:34 +0300  330) //  char *p = NULL;
11c606a6 (kx 2023-04-11 01:18:34 +0300  331) //
11c606a6 (kx 2023-04-11 01:18:34 +0300  332) //  switch( mode )
11c606a6 (kx 2023-04-11 01:18:34 +0300  333) //  {
11c606a6 (kx 2023-04-11 01:18:34 +0300  334) //    case CONSOLE:
11c606a6 (kx 2023-04-11 01:18:34 +0300  335) //      p = "CONSOLE";
11c606a6 (kx 2023-04-11 01:18:34 +0300  336) //      break;
11c606a6 (kx 2023-04-11 01:18:34 +0300  337) //    case INFODIALOG:
11c606a6 (kx 2023-04-11 01:18:34 +0300  338) //      p = "INFODIALOG";
11c606a6 (kx 2023-04-11 01:18:34 +0300  339) //      break;
11c606a6 (kx 2023-04-11 01:18:34 +0300  340) //    case MENUDIALOG:
11c606a6 (kx 2023-04-11 01:18:34 +0300  341) //      p = "MENUDIALOG";
11c606a6 (kx 2023-04-11 01:18:34 +0300  342) //      break;
11c606a6 (kx 2023-04-11 01:18:34 +0300  343) //  }
11c606a6 (kx 2023-04-11 01:18:34 +0300  344) //  return p;
11c606a6 (kx 2023-04-11 01:18:34 +0300  345) //}
11c606a6 (kx 2023-04-11 01:18:34 +0300  346) ////////////////////////////////////////////////////
11c606a6 (kx 2023-04-11 01:18:34 +0300  347) 
11c606a6 (kx 2023-04-11 01:18:34 +0300  348) static char *strprio( enum _priority priority, int short_name )
11c606a6 (kx 2023-04-11 01:18:34 +0300  349) {
11c606a6 (kx 2023-04-11 01:18:34 +0300  350)   char *p = NULL;
11c606a6 (kx 2023-04-11 01:18:34 +0300  351) 
11c606a6 (kx 2023-04-11 01:18:34 +0300  352)   switch( priority )
11c606a6 (kx 2023-04-11 01:18:34 +0300  353)   {
11c606a6 (kx 2023-04-11 01:18:34 +0300  354)     case REQUIRED:
11c606a6 (kx 2023-04-11 01:18:34 +0300  355)       p = ( short_name ) ? "REQ" : "required";
11c606a6 (kx 2023-04-11 01:18:34 +0300  356)       break;
11c606a6 (kx 2023-04-11 01:18:34 +0300  357)     case RECOMMENDED:
11c606a6 (kx 2023-04-11 01:18:34 +0300  358)       p = ( short_name ) ? "REC" : "recommended";
11c606a6 (kx 2023-04-11 01:18:34 +0300  359)       break;
11c606a6 (kx 2023-04-11 01:18:34 +0300  360)     case OPTIONAL:
11c606a6 (kx 2023-04-11 01:18:34 +0300  361)       p = ( short_name ) ? "OPT" : "optional";
11c606a6 (kx 2023-04-11 01:18:34 +0300  362)       break;
11c606a6 (kx 2023-04-11 01:18:34 +0300  363)     case SKIP:
11c606a6 (kx 2023-04-11 01:18:34 +0300  364)       p = ( short_name ) ? "SKP" : "skip";
11c606a6 (kx 2023-04-11 01:18:34 +0300  365)       break;
11c606a6 (kx 2023-04-11 01:18:34 +0300  366)   }
11c606a6 (kx 2023-04-11 01:18:34 +0300  367)   return p;
11c606a6 (kx 2023-04-11 01:18:34 +0300  368) }
11c606a6 (kx 2023-04-11 01:18:34 +0300  369) 
11c606a6 (kx 2023-04-11 01:18:34 +0300  370) static char *strproc( enum _procedure procedure )
11c606a6 (kx 2023-04-11 01:18:34 +0300  371) {
11c606a6 (kx 2023-04-11 01:18:34 +0300  372)   char *p = NULL;
11c606a6 (kx 2023-04-11 01:18:34 +0300  373) 
11c606a6 (kx 2023-04-11 01:18:34 +0300  374)   switch( procedure )
11c606a6 (kx 2023-04-11 01:18:34 +0300  375)   {
11c606a6 (kx 2023-04-11 01:18:34 +0300  376)     case INSTALL:
11c606a6 (kx 2023-04-11 01:18:34 +0300  377)       p = "install";
11c606a6 (kx 2023-04-11 01:18:34 +0300  378)       break;
11c606a6 (kx 2023-04-11 01:18:34 +0300  379)     case UPDATE:
11c606a6 (kx 2023-04-11 01:18:34 +0300  380)       p = "update";
11c606a6 (kx 2023-04-11 01:18:34 +0300  381)       break;
11c606a6 (kx 2023-04-11 01:18:34 +0300  382)   }
11c606a6 (kx 2023-04-11 01:18:34 +0300  383)   return p;
11c606a6 (kx 2023-04-11 01:18:34 +0300  384) }
11c606a6 (kx 2023-04-11 01:18:34 +0300  385) 
11c606a6 (kx 2023-04-11 01:18:34 +0300  386) 
11c606a6 (kx 2023-04-11 01:18:34 +0300  387) static int _mkdir_p( const char *dir, const mode_t mode )
11c606a6 (kx 2023-04-11 01:18:34 +0300  388) {
11c606a6 (kx 2023-04-11 01:18:34 +0300  389)   char  *buf;
11c606a6 (kx 2023-04-11 01:18:34 +0300  390)   char  *p = NULL;
11c606a6 (kx 2023-04-11 01:18:34 +0300  391)   struct stat sb;
11c606a6 (kx 2023-04-11 01:18:34 +0300  392) 
11c606a6 (kx 2023-04-11 01:18:34 +0300  393)   if( !dir ) return -1;
11c606a6 (kx 2023-04-11 01:18:34 +0300  394) 
11c606a6 (kx 2023-04-11 01:18:34 +0300  395)   buf = (char *)alloca( strlen( dir ) + 1 );
11c606a6 (kx 2023-04-11 01:18:34 +0300  396)   strcpy( buf, dir );
11c606a6 (kx 2023-04-11 01:18:34 +0300  397) 
11c606a6 (kx 2023-04-11 01:18:34 +0300  398)   remove_trailing_slash( buf );
11c606a6 (kx 2023-04-11 01:18:34 +0300  399) 
11c606a6 (kx 2023-04-11 01:18:34 +0300  400)   /* check if path exists and is a directory */
11c606a6 (kx 2023-04-11 01:18:34 +0300  401)   if( stat( buf, &sb ) == 0 )
11c606a6 (kx 2023-04-11 01:18:34 +0300  402)   {
11c606a6 (kx 2023-04-11 01:18:34 +0300  403)     if( S_ISDIR(sb.st_mode) )
11c606a6 (kx 2023-04-11 01:18:34 +0300  404)     {
11c606a6 (kx 2023-04-11 01:18:34 +0300  405)       return 0;
11c606a6 (kx 2023-04-11 01:18:34 +0300  406)     }
11c606a6 (kx 2023-04-11 01:18:34 +0300  407)   }
11c606a6 (kx 2023-04-11 01:18:34 +0300  408) 
11c606a6 (kx 2023-04-11 01:18:34 +0300  409)   /* mkdir -p */
11c606a6 (kx 2023-04-11 01:18:34 +0300  410)   for( p = buf + 1; *p; ++p )
11c606a6 (kx 2023-04-11 01:18:34 +0300  411)   {
11c606a6 (kx 2023-04-11 01:18:34 +0300  412)     if( *p == '/' )
11c606a6 (kx 2023-04-11 01:18:34 +0300  413)     {
11c606a6 (kx 2023-04-11 01:18:34 +0300  414)       *p = 0;
11c606a6 (kx 2023-04-11 01:18:34 +0300  415)       /* test path */
11c606a6 (kx 2023-04-11 01:18:34 +0300  416)       if( stat( buf, &sb ) != 0 )
11c606a6 (kx 2023-04-11 01:18:34 +0300  417)       {
11c606a6 (kx 2023-04-11 01:18:34 +0300  418)         /* path does not exist - create directory */
11c606a6 (kx 2023-04-11 01:18:34 +0300  419)         if( mkdir( buf, mode ) < 0 )
11c606a6 (kx 2023-04-11 01:18:34 +0300  420)         {
11c606a6 (kx 2023-04-11 01:18:34 +0300  421)           return -1;
11c606a6 (kx 2023-04-11 01:18:34 +0300  422)         }
11c606a6 (kx 2023-04-11 01:18:34 +0300  423)       } else if( !S_ISDIR(sb.st_mode) )
11c606a6 (kx 2023-04-11 01:18:34 +0300  424)       {
11c606a6 (kx 2023-04-11 01:18:34 +0300  425)         /* not a directory */
11c606a6 (kx 2023-04-11 01:18:34 +0300  426)         return -1;
11c606a6 (kx 2023-04-11 01:18:34 +0300  427)       }
11c606a6 (kx 2023-04-11 01:18:34 +0300  428)       *p = '/';
11c606a6 (kx 2023-04-11 01:18:34 +0300  429)     }
11c606a6 (kx 2023-04-11 01:18:34 +0300  430)   }
11c606a6 (kx 2023-04-11 01:18:34 +0300  431) 
11c606a6 (kx 2023-04-11 01:18:34 +0300  432)   /* test path */
11c606a6 (kx 2023-04-11 01:18:34 +0300  433)   if( stat( buf, &sb ) != 0 )
11c606a6 (kx 2023-04-11 01:18:34 +0300  434)   {
11c606a6 (kx 2023-04-11 01:18:34 +0300  435)     /* path does not exist - create directory */
11c606a6 (kx 2023-04-11 01:18:34 +0300  436)     if( mkdir( buf, mode ) < 0 )
11c606a6 (kx 2023-04-11 01:18:34 +0300  437)     {
11c606a6 (kx 2023-04-11 01:18:34 +0300  438)       return -1;
11c606a6 (kx 2023-04-11 01:18:34 +0300  439)     }
11c606a6 (kx 2023-04-11 01:18:34 +0300  440)   } else if( !S_ISDIR(sb.st_mode) )
11c606a6 (kx 2023-04-11 01:18:34 +0300  441)   {
11c606a6 (kx 2023-04-11 01:18:34 +0300  442)     /* not a directory */
11c606a6 (kx 2023-04-11 01:18:34 +0300  443)     return -1;
11c606a6 (kx 2023-04-11 01:18:34 +0300  444)   }
11c606a6 (kx 2023-04-11 01:18:34 +0300  445) 
11c606a6 (kx 2023-04-11 01:18:34 +0300  446)   return 0;
11c606a6 (kx 2023-04-11 01:18:34 +0300  447) }
11c606a6 (kx 2023-04-11 01:18:34 +0300  448) 
11c606a6 (kx 2023-04-11 01:18:34 +0300  449) static void _rm_tmpdir( const char *dirpath )
11c606a6 (kx 2023-04-11 01:18:34 +0300  450) {
11c606a6 (kx 2023-04-11 01:18:34 +0300  451)   DIR    *dir;
11c606a6 (kx 2023-04-11 01:18:34 +0300  452)   char   *path;
11c606a6 (kx 2023-04-11 01:18:34 +0300  453)   size_t  len;
11c606a6 (kx 2023-04-11 01:18:34 +0300  454) 
11c606a6 (kx 2023-04-11 01:18:34 +0300  455)   struct stat    path_sb, entry_sb;
11c606a6 (kx 2023-04-11 01:18:34 +0300  456)   struct dirent *entry;
11c606a6 (kx 2023-04-11 01:18:34 +0300  457) 
11c606a6 (kx 2023-04-11 01:18:34 +0300  458)   if( stat( dirpath, &path_sb ) == -1 )
11c606a6 (kx 2023-04-11 01:18:34 +0300  459)   {
11c606a6 (kx 2023-04-11 01:18:34 +0300  460)     return; /* stat returns error code; errno is set */
11c606a6 (kx 2023-04-11 01:18:34 +0300  461)   }
11c606a6 (kx 2023-04-11 01:18:34 +0300  462) 
11c606a6 (kx 2023-04-11 01:18:34 +0300  463)   if( S_ISDIR(path_sb.st_mode) == 0 )
11c606a6 (kx 2023-04-11 01:18:34 +0300  464)   {
11c606a6 (kx 2023-04-11 01:18:34 +0300  465)     return; /* dirpath is not a directory */
11c606a6 (kx 2023-04-11 01:18:34 +0300  466)   }
11c606a6 (kx 2023-04-11 01:18:34 +0300  467) 
11c606a6 (kx 2023-04-11 01:18:34 +0300  468)   if( (dir = opendir(dirpath) ) == NULL )
11c606a6 (kx 2023-04-11 01:18:34 +0300  469)   {
11c606a6 (kx 2023-04-11 01:18:34 +0300  470)     return; /* Cannot open direcroty; errno is set */
11c606a6 (kx 2023-04-11 01:18:34 +0300  471)   }
11c606a6 (kx 2023-04-11 01:18:34 +0300  472) 
11c606a6 (kx 2023-04-11 01:18:34 +0300  473)   len = strlen( dirpath );
11c606a6 (kx 2023-04-11 01:18:34 +0300  474) 
11c606a6 (kx 2023-04-11 01:18:34 +0300  475)   while( (entry = readdir( dir )) != NULL)
11c606a6 (kx 2023-04-11 01:18:34 +0300  476)   {
11c606a6 (kx 2023-04-11 01:18:34 +0300  477) 
11c606a6 (kx 2023-04-11 01:18:34 +0300  478)     /* skip entries '.' and '..' */
11c606a6 (kx 2023-04-11 01:18:34 +0300  479)     if( ! strcmp( entry->d_name, "." ) || ! strcmp( entry->d_name, ".." ) ) continue;
11c606a6 (kx 2023-04-11 01:18:34 +0300  480) 
11c606a6 (kx 2023-04-11 01:18:34 +0300  481)     /* determinate a full name of an entry */
11c606a6 (kx 2023-04-11 01:18:34 +0300  482)     path = alloca( len + strlen( entry->d_name ) + 2 );
11c606a6 (kx 2023-04-11 01:18:34 +0300  483)     strcpy( path, dirpath );
11c606a6 (kx 2023-04-11 01:18:34 +0300  484)     strcat( path, "/" );
11c606a6 (kx 2023-04-11 01:18:34 +0300  485)     strcat( path, entry->d_name );
11c606a6 (kx 2023-04-11 01:18:34 +0300  486) 
11c606a6 (kx 2023-04-11 01:18:34 +0300  487)     if( stat( path, &entry_sb ) == 0 )
11c606a6 (kx 2023-04-11 01:18:34 +0300  488)     {
11c606a6 (kx 2023-04-11 01:18:34 +0300  489)       if( S_ISDIR(entry_sb.st_mode) )
11c606a6 (kx 2023-04-11 01:18:34 +0300  490)       {
11c606a6 (kx 2023-04-11 01:18:34 +0300  491)         /* recursively remove a nested directory */
11c606a6 (kx 2023-04-11 01:18:34 +0300  492)         _rm_tmpdir( path );
11c606a6 (kx 2023-04-11 01:18:34 +0300  493)       }
11c606a6 (kx 2023-04-11 01:18:34 +0300  494)       else
11c606a6 (kx 2023-04-11 01:18:34 +0300  495)       {
11c606a6 (kx 2023-04-11 01:18:34 +0300  496)         /* remove a file object */
11c606a6 (kx 2023-04-11 01:18:34 +0300  497)         (void)unlink( path );
11c606a6 (kx 2023-04-11 01:18:34 +0300  498)       }
11c606a6 (kx 2023-04-11 01:18:34 +0300  499)     }
11c606a6 (kx 2023-04-11 01:18:34 +0300  500)     /* else { stat() returns error code; errno is set; and we have to continue the loop } */
11c606a6 (kx 2023-04-11 01:18:34 +0300  501) 
11c606a6 (kx 2023-04-11 01:18:34 +0300  502)   }
11c606a6 (kx 2023-04-11 01:18:34 +0300  503) 
11c606a6 (kx 2023-04-11 01:18:34 +0300  504)   /* remove the devastated directory and close the object of this directory */
11c606a6 (kx 2023-04-11 01:18:34 +0300  505)   (void)rmdir( dirpath );
11c606a6 (kx 2023-04-11 01:18:34 +0300  506) 
11c606a6 (kx 2023-04-11 01:18:34 +0300  507)   closedir( dir );
11c606a6 (kx 2023-04-11 01:18:34 +0300  508) }
11c606a6 (kx 2023-04-11 01:18:34 +0300  509) 
11c606a6 (kx 2023-04-11 01:18:34 +0300  510) static char *_mk_tmpdir( void )
11c606a6 (kx 2023-04-11 01:18:34 +0300  511) {
11c606a6 (kx 2023-04-11 01:18:34 +0300  512)   char   *buf = NULL, *p, *tmp = "/tmp";
11c606a6 (kx 2023-04-11 01:18:34 +0300  513)   size_t  len = 0, size = 0;
11c606a6 (kx 2023-04-11 01:18:34 +0300  514) 
11c606a6 (kx 2023-04-11 01:18:34 +0300  515)   (void)umask( S_IWGRP | S_IWOTH ); /* octal 022 */
11c606a6 (kx 2023-04-11 01:18:34 +0300  516) 
11c606a6 (kx 2023-04-11 01:18:34 +0300  517)   /* Get preferred directory for tmp files */
11c606a6 (kx 2023-04-11 01:18:34 +0300  518)   if( (p = getenv( "TMP" )) != NULL ) {
11c606a6 (kx 2023-04-11 01:18:34 +0300  519)     tmp = p;
11c606a6 (kx 2023-04-11 01:18:34 +0300  520)   }
11c606a6 (kx 2023-04-11 01:18:34 +0300  521)   else if( (p = getenv( "TEMP" )) != NULL ) {
11c606a6 (kx 2023-04-11 01:18:34 +0300  522)     tmp = p;
11c606a6 (kx 2023-04-11 01:18:34 +0300  523)   }
11c606a6 (kx 2023-04-11 01:18:34 +0300  524) 
11c606a6 (kx 2023-04-11 01:18:34 +0300  525)   size = strlen( tmp ) + strlen( DISTRO_NAME ) + strlen( program ) + 12;
11c606a6 (kx 2023-04-11 01:18:34 +0300  526) 
11c606a6 (kx 2023-04-11 01:18:34 +0300  527)   buf = (char *)malloc( size );
11c606a6 (kx 2023-04-11 01:18:34 +0300  528)   if( !buf ) return NULL;
11c606a6 (kx 2023-04-11 01:18:34 +0300  529) 
11c606a6 (kx 2023-04-11 01:18:34 +0300  530)   len = snprintf( buf, size, (const char *)"%s/%s/%s-%.7u", tmp, DISTRO_NAME, program, getpid() );
11c606a6 (kx 2023-04-11 01:18:34 +0300  531)   if( len == 0 || len == size - 1 )
11c606a6 (kx 2023-04-11 01:18:34 +0300  532)   {
11c606a6 (kx 2023-04-11 01:18:34 +0300  533)     free( buf ); return NULL;
11c606a6 (kx 2023-04-11 01:18:34 +0300  534)   }
11c606a6 (kx 2023-04-11 01:18:34 +0300  535) 
11c606a6 (kx 2023-04-11 01:18:34 +0300  536)   _rm_tmpdir( (const char *)&buf[0] );
11c606a6 (kx 2023-04-11 01:18:34 +0300  537) 
11c606a6 (kx 2023-04-11 01:18:34 +0300  538)   if( _mkdir_p( buf, S_IRWXU | S_IRWXG | S_IRWXO ) == 0 )
11c606a6 (kx 2023-04-11 01:18:34 +0300  539)   {
11c606a6 (kx 2023-04-11 01:18:34 +0300  540)     return buf;
11c606a6 (kx 2023-04-11 01:18:34 +0300  541)   }
11c606a6 (kx 2023-04-11 01:18:34 +0300  542) 
11c606a6 (kx 2023-04-11 01:18:34 +0300  543)   free( buf ); return NULL;
11c606a6 (kx 2023-04-11 01:18:34 +0300  544) }
11c606a6 (kx 2023-04-11 01:18:34 +0300  545) 
11c606a6 (kx 2023-04-11 01:18:34 +0300  546) 
11c606a6 (kx 2023-04-11 01:18:34 +0300  547) void fatal_error_actions( void )
11c606a6 (kx 2023-04-11 01:18:34 +0300  548) {
11c606a6 (kx 2023-04-11 01:18:34 +0300  549)   logmsg( errlog, MSG_NOTICE, "Free resources on FATAL error..." );
11c606a6 (kx 2023-04-11 01:18:34 +0300  550)   if( tmpdir ) { _rm_tmpdir( (const char *)tmpdir ); free( tmpdir ); }
11c606a6 (kx 2023-04-11 01:18:34 +0300  551)   free_resources();
11c606a6 (kx 2023-04-11 01:18:34 +0300  552) }
11c606a6 (kx 2023-04-11 01:18:34 +0300  553) 
11c606a6 (kx 2023-04-11 01:18:34 +0300  554) void sigint( int signum )
11c606a6 (kx 2023-04-11 01:18:34 +0300  555) {
11c606a6 (kx 2023-04-11 01:18:34 +0300  556)   (void)signum;
11c606a6 (kx 2023-04-11 01:18:34 +0300  557) 
11c606a6 (kx 2023-04-11 01:18:34 +0300  558)   if( tmpdir ) { _rm_tmpdir( (const char *)tmpdir ); free( tmpdir ); }
11c606a6 (kx 2023-04-11 01:18:34 +0300  559)   free_resources();
11c606a6 (kx 2023-04-11 01:18:34 +0300  560) }
11c606a6 (kx 2023-04-11 01:18:34 +0300  561) 
11c606a6 (kx 2023-04-11 01:18:34 +0300  562) static void set_signal_handlers()
11c606a6 (kx 2023-04-11 01:18:34 +0300  563) {
11c606a6 (kx 2023-04-11 01:18:34 +0300  564)   struct sigaction  sa;
11c606a6 (kx 2023-04-11 01:18:34 +0300  565)   sigset_t          set;
11c606a6 (kx 2023-04-11 01:18:34 +0300  566) 
11c606a6 (kx 2023-04-11 01:18:34 +0300  567)   memset( &sa, 0, sizeof( sa ) );
11c606a6 (kx 2023-04-11 01:18:34 +0300  568)   sa.sa_handler = sigint;          /* TERM, INT */
11c606a6 (kx 2023-04-11 01:18:34 +0300  569)   sa.sa_flags = SA_RESTART;
11c606a6 (kx 2023-04-11 01:18:34 +0300  570)   sigemptyset( &set );
11c606a6 (kx 2023-04-11 01:18:34 +0300  571)   sigaddset( &set, SIGTERM );
11c606a6 (kx 2023-04-11 01:18:34 +0300  572)   sigaddset( &set, SIGINT );
11c606a6 (kx 2023-04-11 01:18:34 +0300  573)   sa.sa_mask = set;
11c606a6 (kx 2023-04-11 01:18:34 +0300  574)   sigaction( SIGTERM, &sa, NULL );
11c606a6 (kx 2023-04-11 01:18:34 +0300  575)   sigaction( SIGINT, &sa,  NULL );
11c606a6 (kx 2023-04-11 01:18:34 +0300  576) 
11c606a6 (kx 2023-04-11 01:18:34 +0300  577)   memset( &sa, 0, sizeof( sa ) );  /* ignore SIGPIPE */
11c606a6 (kx 2023-04-11 01:18:34 +0300  578)   sa.sa_handler = SIG_IGN;
11c606a6 (kx 2023-04-11 01:18:34 +0300  579)   sa.sa_flags = 0;
11c606a6 (kx 2023-04-11 01:18:34 +0300  580)   sigaction( SIGPIPE, &sa, NULL );
11c606a6 (kx 2023-04-11 01:18:34 +0300  581) 
11c606a6 (kx 2023-04-11 01:18:34 +0300  582)   /* System V fork+wait does not work if SIGCHLD is ignored */
11c606a6 (kx 2023-04-11 01:18:34 +0300  583)   signal( SIGCHLD, SIG_DFL );
11c606a6 (kx 2023-04-11 01:18:34 +0300  584) }
11c606a6 (kx 2023-04-11 01:18:34 +0300  585) 
11c606a6 (kx 2023-04-11 01:18:34 +0300  586) 
11c606a6 (kx 2023-04-11 01:18:34 +0300  587) static enum _input_type check_input_file( char *uncompress, const char *fname )
11c606a6 (kx 2023-04-11 01:18:34 +0300  588) {
11c606a6 (kx 2023-04-11 01:18:34 +0300  589)   struct stat st;
11c606a6 (kx 2023-04-11 01:18:34 +0300  590)   size_t pkglog_size = 0;
11c606a6 (kx 2023-04-11 01:18:34 +0300  591)   unsigned char buf[8];
11c606a6 (kx 2023-04-11 01:18:34 +0300  592)   int rc, fd;
11c606a6 (kx 2023-04-11 01:18:34 +0300  593) 
11c606a6 (kx 2023-04-11 01:18:34 +0300  594)   /* SIGNATURES: https://www.garykessler.net/library/file_sigs.html */
11c606a6 (kx 2023-04-11 01:18:34 +0300  595) 
11c606a6 (kx 2023-04-11 01:18:34 +0300  596)   if( uncompress )
11c606a6 (kx 2023-04-11 01:18:34 +0300  597)   {
11c606a6 (kx 2023-04-11 01:18:34 +0300  598)     *uncompress = '\0';
11c606a6 (kx 2023-04-11 01:18:34 +0300  599)   }
11c606a6 (kx 2023-04-11 01:18:34 +0300  600) 
11c606a6 (kx 2023-04-11 01:18:34 +0300  601)   if( stat( fname, &st ) == -1 )
11c606a6 (kx 2023-04-11 01:18:34 +0300  602)   {
11c606a6 (kx 2023-04-11 01:18:34 +0300  603)     FATAL_ERROR( "Cannot access %s file: %s", basename( (char *)fname ), strerror( errno ) );
11c606a6 (kx 2023-04-11 01:18:34 +0300  604)   }
11c606a6 (kx 2023-04-11 01:18:34 +0300  605) 
11c606a6 (kx 2023-04-11 01:18:34 +0300  606)   pkglog_size = st.st_size;
11c606a6 (kx 2023-04-11 01:18:34 +0300  607) 
11c606a6 (kx 2023-04-11 01:18:34 +0300  608)   if( (fd = open( fname, O_RDONLY )) == -1 )
11c606a6 (kx 2023-04-11 01:18:34 +0300  609)   {
11c606a6 (kx 2023-04-11 01:18:34 +0300  610)     FATAL_ERROR( "Cannot open %s file: %s", basename( (char *)fname ), strerror( errno ) );
11c606a6 (kx 2023-04-11 01:18:34 +0300  611)   }
11c606a6 (kx 2023-04-11 01:18:34 +0300  612) 
11c606a6 (kx 2023-04-11 01:18:34 +0300  613)   rc = (int)read( fd, (void *)&buf[0], 7 );
11c606a6 (kx 2023-04-11 01:18:34 +0300  614)   if( rc != 7 )
11c606a6 (kx 2023-04-11 01:18:34 +0300  615)   {
11c606a6 (kx 2023-04-11 01:18:34 +0300  616)     close( fd ); return IFMT_UNKNOWN;
11c606a6 (kx 2023-04-11 01:18:34 +0300  617)   }
11c606a6 (kx 2023-04-11 01:18:34 +0300  618)   buf[7] = '\0';
11c606a6 (kx 2023-04-11 01:18:34 +0300  619) 
11c606a6 (kx 2023-04-11 01:18:34 +0300  620)   /* TEXT */
11c606a6 (kx 2023-04-11 01:18:34 +0300  621)   if( !strncmp( (const char *)&buf[0], "PACKAGE", 7 ) )
11c606a6 (kx 2023-04-11 01:18:34 +0300  622)   {
11c606a6 (kx 2023-04-11 01:18:34 +0300  623)     close( fd ); return IFMT_LOG;
11c606a6 (kx 2023-04-11 01:18:34 +0300  624)   }
11c606a6 (kx 2023-04-11 01:18:34 +0300  625) 
11c606a6 (kx 2023-04-11 01:18:34 +0300  626)   /* GZ */
11c606a6 (kx 2023-04-11 01:18:34 +0300  627)   if( buf[0] == 0x1F && buf[1] == 0x8B && buf[2] == 0x08 )
11c606a6 (kx 2023-04-11 01:18:34 +0300  628)   {
11c606a6 (kx 2023-04-11 01:18:34 +0300  629)     if( uncompress ) { *uncompress = 'x'; }
11c606a6 (kx 2023-04-11 01:18:34 +0300  630)     close( fd ); return IFMT_PKG;
11c606a6 (kx 2023-04-11 01:18:34 +0300  631)   }
11c606a6 (kx 2023-04-11 01:18:34 +0300  632) 
11c606a6 (kx 2023-04-11 01:18:34 +0300  633)   /* BZ2 */
11c606a6 (kx 2023-04-11 01:18:34 +0300  634)   if( buf[0] == 0x42 && buf[1] == 0x5A && buf[2] == 0x68 )
11c606a6 (kx 2023-04-11 01:18:34 +0300  635)   {
11c606a6 (kx 2023-04-11 01:18:34 +0300  636)     if( uncompress ) { *uncompress = 'j'; }
11c606a6 (kx 2023-04-11 01:18:34 +0300  637)     close( fd ); return IFMT_PKG;
11c606a6 (kx 2023-04-11 01:18:34 +0300  638)   }
11c606a6 (kx 2023-04-11 01:18:34 +0300  639) 
11c606a6 (kx 2023-04-11 01:18:34 +0300  640)   /* XZ */
11c606a6 (kx 2023-04-11 01:18:34 +0300  641)   if( buf[0] == 0xFD && buf[1] == 0x37 && buf[2] == 0x7A &&
11c606a6 (kx 2023-04-11 01:18:34 +0300  642)       buf[3] == 0x58 && buf[4] == 0x5A && buf[5] == 0x00   )
11c606a6 (kx 2023-04-11 01:18:34 +0300  643)   {
11c606a6 (kx 2023-04-11 01:18:34 +0300  644)     if( uncompress ) { *uncompress = 'J'; }
11c606a6 (kx 2023-04-11 01:18:34 +0300  645)     close( fd ); return IFMT_PKG;
11c606a6 (kx 2023-04-11 01:18:34 +0300  646)   }
11c606a6 (kx 2023-04-11 01:18:34 +0300  647) 
11c606a6 (kx 2023-04-11 01:18:34 +0300  648)   if( pkglog_size > 262 )
11c606a6 (kx 2023-04-11 01:18:34 +0300  649)   {
11c606a6 (kx 2023-04-11 01:18:34 +0300  650)     if( lseek( fd, 257, SEEK_SET ) == -1 )
11c606a6 (kx 2023-04-11 01:18:34 +0300  651)     {
11c606a6 (kx 2023-04-11 01:18:34 +0300  652)       FATAL_ERROR( "Cannot check signature of %s file: %s", basename( (char *)fname ), strerror( errno ) );
11c606a6 (kx 2023-04-11 01:18:34 +0300  653)     }
11c606a6 (kx 2023-04-11 01:18:34 +0300  654)     rc = (int)read( fd, &buf[0], 5 );
11c606a6 (kx 2023-04-11 01:18:34 +0300  655)     if( rc != 5 )
11c606a6 (kx 2023-04-11 01:18:34 +0300  656)     {
11c606a6 (kx 2023-04-11 01:18:34 +0300  657)       FATAL_ERROR( "Cannot read signature of %s file", basename( (char *)fname ) );
11c606a6 (kx 2023-04-11 01:18:34 +0300  658)     }
11c606a6 (kx 2023-04-11 01:18:34 +0300  659)     /* TAR */
11c606a6 (kx 2023-04-11 01:18:34 +0300  660)     if( buf[0] == 0x75 && buf[1] == 0x73 && buf[2] == 0x74 && buf[3] == 0x61 && buf[4] == 0x72 )
11c606a6 (kx 2023-04-11 01:18:34 +0300  661)     {
11c606a6 (kx 2023-04-11 01:18:34 +0300  662)       close( fd ); return IFMT_PKG;
11c606a6 (kx 2023-04-11 01:18:34 +0300  663)     }
11c606a6 (kx 2023-04-11 01:18:34 +0300  664)   }
11c606a6 (kx 2023-04-11 01:18:34 +0300  665) 
11c606a6 (kx 2023-04-11 01:18:34 +0300  666)   close( fd ); return IFMT_UNKNOWN;
11c606a6 (kx 2023-04-11 01:18:34 +0300  667) }
11c606a6 (kx 2023-04-11 01:18:34 +0300  668) 
11c606a6 (kx 2023-04-11 01:18:34 +0300  669) 
11c606a6 (kx 2023-04-11 01:18:34 +0300  670) void get_args( int argc, char *argv[] )
11c606a6 (kx 2023-04-11 01:18:34 +0300  671) {
11c606a6 (kx 2023-04-11 01:18:34 +0300  672) #if defined( HAVE_GPG2 )
11c606a6 (kx 2023-04-11 01:18:34 +0300  673) #if defined( HAVE_DIALOG )
11c606a6 (kx 2023-04-11 01:18:34 +0300  674)   const char* short_options = "hvacgiml:p:r:";
11c606a6 (kx 2023-04-11 01:18:34 +0300  675) #else
11c606a6 (kx 2023-04-11 01:18:34 +0300  676)   const char* short_options = "hvacgl:p:r:";
11c606a6 (kx 2023-04-11 01:18:34 +0300  677) #endif
11c606a6 (kx 2023-04-11 01:18:34 +0300  678) #else
11c606a6 (kx 2023-04-11 01:18:34 +0300  679) #if defined( HAVE_DIALOG )
11c606a6 (kx 2023-04-11 01:18:34 +0300  680)   const char* short_options = "hvaciml:p:r:";
11c606a6 (kx 2023-04-11 01:18:34 +0300  681) #else
11c606a6 (kx 2023-04-11 01:18:34 +0300  682)   const char* short_options = "hvacl:p:r:";
11c606a6 (kx 2023-04-11 01:18:34 +0300  683) #endif
11c606a6 (kx 2023-04-11 01:18:34 +0300  684) #endif
11c606a6 (kx 2023-04-11 01:18:34 +0300  685) 
11c606a6 (kx 2023-04-11 01:18:34 +0300  686) #define IGNORE_CHREFS_ERRORS 872
a745159c (kx 2023-10-23 21:39:58 +0300  687) #define DISABLE_CHREFS       873
11c606a6 (kx 2023-04-11 01:18:34 +0300  688) 
11c606a6 (kx 2023-04-11 01:18:34 +0300  689)   const struct option long_options[] =
11c606a6 (kx 2023-04-11 01:18:34 +0300  690)   {
11c606a6 (kx 2023-04-11 01:18:34 +0300  691)     { "help",                 no_argument,       NULL, 'h' },
11c606a6 (kx 2023-04-11 01:18:34 +0300  692)     { "version",              no_argument,       NULL, 'v' },
11c606a6 (kx 2023-04-11 01:18:34 +0300  693)     { "always-ask",           no_argument,       NULL, 'a' },
11c606a6 (kx 2023-04-11 01:18:34 +0300  694)     { "check-requires",       no_argument,       NULL, 'c' },
11c606a6 (kx 2023-04-11 01:18:34 +0300  695) #if defined( HAVE_GPG2 )
11c606a6 (kx 2023-04-11 01:18:34 +0300  696)     { "gpg-verify",           no_argument,       NULL, 'g' },
11c606a6 (kx 2023-04-11 01:18:34 +0300  697) #endif
11c606a6 (kx 2023-04-11 01:18:34 +0300  698)     { "ignore-chrefs-errors", no_argument,       NULL, IGNORE_CHREFS_ERRORS },
a745159c (kx 2023-10-23 21:39:58 +0300  699)     { "disable-chrefs",       no_argument,       NULL, DISABLE_CHREFS },
11c606a6 (kx 2023-04-11 01:18:34 +0300  700) #if defined( HAVE_DIALOG )
11c606a6 (kx 2023-04-11 01:18:34 +0300  701)     { "info-dialog",          no_argument,       NULL, 'i' },
11c606a6 (kx 2023-04-11 01:18:34 +0300  702)     { "menu-dialog",          no_argument,       NULL, 'm' },
11c606a6 (kx 2023-04-11 01:18:34 +0300  703) #endif
11c606a6 (kx 2023-04-11 01:18:34 +0300  704)     { "pkglist",              required_argument, NULL, 'l' },
11c606a6 (kx 2023-04-11 01:18:34 +0300  705)     { "priority",             required_argument, NULL, 'p' },
11c606a6 (kx 2023-04-11 01:18:34 +0300  706)     { "root",                 required_argument, NULL, 'r' },
11c606a6 (kx 2023-04-11 01:18:34 +0300  707)     { NULL,                   0,                 NULL,  0  }
11c606a6 (kx 2023-04-11 01:18:34 +0300  708)   };
11c606a6 (kx 2023-04-11 01:18:34 +0300  709) 
11c606a6 (kx 2023-04-11 01:18:34 +0300  710)   int ret;
11c606a6 (kx 2023-04-11 01:18:34 +0300  711)   int option_index = 0;
11c606a6 (kx 2023-04-11 01:18:34 +0300  712) 
11c606a6 (kx 2023-04-11 01:18:34 +0300  713)   while( (ret = getopt_long( argc, argv, short_options, long_options, &option_index )) != -1 )
11c606a6 (kx 2023-04-11 01:18:34 +0300  714)   {
11c606a6 (kx 2023-04-11 01:18:34 +0300  715)     switch( ret )
11c606a6 (kx 2023-04-11 01:18:34 +0300  716)     {
11c606a6 (kx 2023-04-11 01:18:34 +0300  717)       case 'h':
11c606a6 (kx 2023-04-11 01:18:34 +0300  718)       {
11c606a6 (kx 2023-04-11 01:18:34 +0300  719)         usage();
11c606a6 (kx 2023-04-11 01:18:34 +0300  720)         break;
11c606a6 (kx 2023-04-11 01:18:34 +0300  721)       }
11c606a6 (kx 2023-04-11 01:18:34 +0300  722)       case 'v':
11c606a6 (kx 2023-04-11 01:18:34 +0300  723)       {
11c606a6 (kx 2023-04-11 01:18:34 +0300  724)         version();
11c606a6 (kx 2023-04-11 01:18:34 +0300  725)         break;
11c606a6 (kx 2023-04-11 01:18:34 +0300  726)       }
11c606a6 (kx 2023-04-11 01:18:34 +0300  727)       case 'a':
11c606a6 (kx 2023-04-11 01:18:34 +0300  728)       {
11c606a6 (kx 2023-04-11 01:18:34 +0300  729)         ask = 1;
11c606a6 (kx 2023-04-11 01:18:34 +0300  730)         break;
11c606a6 (kx 2023-04-11 01:18:34 +0300  731)       }
11c606a6 (kx 2023-04-11 01:18:34 +0300  732)       case 'c':
11c606a6 (kx 2023-04-11 01:18:34 +0300  733)       {
11c606a6 (kx 2023-04-11 01:18:34 +0300  734)         rqck = 1;
11c606a6 (kx 2023-04-11 01:18:34 +0300  735)         break;
11c606a6 (kx 2023-04-11 01:18:34 +0300  736)       }
11c606a6 (kx 2023-04-11 01:18:34 +0300  737) #if defined( HAVE_GPG2 )
11c606a6 (kx 2023-04-11 01:18:34 +0300  738)       case 'g':
11c606a6 (kx 2023-04-11 01:18:34 +0300  739)       {
11c606a6 (kx 2023-04-11 01:18:34 +0300  740)         gpgck = 1;
11c606a6 (kx 2023-04-11 01:18:34 +0300  741)         break;
11c606a6 (kx 2023-04-11 01:18:34 +0300  742)       }
11c606a6 (kx 2023-04-11 01:18:34 +0300  743) #endif
11c606a6 (kx 2023-04-11 01:18:34 +0300  744) 
11c606a6 (kx 2023-04-11 01:18:34 +0300  745) #if defined( HAVE_DIALOG )
11c606a6 (kx 2023-04-11 01:18:34 +0300  746)       case 'i':
11c606a6 (kx 2023-04-11 01:18:34 +0300  747)       {
11c606a6 (kx 2023-04-11 01:18:34 +0300  748)         install_mode = INFODIALOG;
11c606a6 (kx 2023-04-11 01:18:34 +0300  749)         break;
11c606a6 (kx 2023-04-11 01:18:34 +0300  750)       }
11c606a6 (kx 2023-04-11 01:18:34 +0300  751)       case 'm':
11c606a6 (kx 2023-04-11 01:18:34 +0300  752)       {
11c606a6 (kx 2023-04-11 01:18:34 +0300  753)         install_mode = MENUDIALOG;
11c606a6 (kx 2023-04-11 01:18:34 +0300  754)         break;
11c606a6 (kx 2023-04-11 01:18:34 +0300  755)       }
11c606a6 (kx 2023-04-11 01:18:34 +0300  756) #endif
11c606a6 (kx 2023-04-11 01:18:34 +0300  757) 
11c606a6 (kx 2023-04-11 01:18:34 +0300  758)       case IGNORE_CHREFS_ERRORS:
11c606a6 (kx 2023-04-11 01:18:34 +0300  759)       {
11c606a6 (kx 2023-04-11 01:18:34 +0300  760)         ignore_chrefs_errors = 1;
11c606a6 (kx 2023-04-11 01:18:34 +0300  761)         break;
11c606a6 (kx 2023-04-11 01:18:34 +0300  762)       }
11c606a6 (kx 2023-04-11 01:18:34 +0300  763) 
a745159c (kx 2023-10-23 21:39:58 +0300  764)       case DISABLE_CHREFS:
a745159c (kx 2023-10-23 21:39:58 +0300  765)       {
a745159c (kx 2023-10-23 21:39:58 +0300  766)         disable_chrefs = 1;
a745159c (kx 2023-10-23 21:39:58 +0300  767)         break;
a745159c (kx 2023-10-23 21:39:58 +0300  768)       }
a745159c (kx 2023-10-23 21:39:58 +0300  769) 
11c606a6 (kx 2023-04-11 01:18:34 +0300  770)       case 'p':
11c606a6 (kx 2023-04-11 01:18:34 +0300  771)       {
11c606a6 (kx 2023-04-11 01:18:34 +0300  772)         if( optarg != NULL )
11c606a6 (kx 2023-04-11 01:18:34 +0300  773)         {
11c606a6 (kx 2023-04-11 01:18:34 +0300  774)           char *match = NULL;
11c606a6 (kx 2023-04-11 01:18:34 +0300  775) 
11c606a6 (kx 2023-04-11 01:18:34 +0300  776)           if( strlen( (const char *)optarg ) > 2 )
11c606a6 (kx 2023-04-11 01:18:34 +0300  777)           {
11c606a6 (kx 2023-04-11 01:18:34 +0300  778)             to_lowercase( optarg );
11c606a6 (kx 2023-04-11 01:18:34 +0300  779)             if( (match = strstr( optarg, "req" )) && match == optarg ) {
11c606a6 (kx 2023-04-11 01:18:34 +0300  780)               priority = REQUIRED;
11c606a6 (kx 2023-04-11 01:18:34 +0300  781)             }
11c606a6 (kx 2023-04-11 01:18:34 +0300  782)             else if( (match = strstr( optarg, "rec" )) && match == optarg ) {
11c606a6 (kx 2023-04-11 01:18:34 +0300  783)               priority = RECOMMENDED;
11c606a6 (kx 2023-04-11 01:18:34 +0300  784)             }
11c606a6 (kx 2023-04-11 01:18:34 +0300  785)             else if( (match = strstr( optarg, "opt" )) && match == optarg ) {
11c606a6 (kx 2023-04-11 01:18:34 +0300  786)               priority = OPTIONAL;
11c606a6 (kx 2023-04-11 01:18:34 +0300  787)             }
11c606a6 (kx 2023-04-11 01:18:34 +0300  788)             else if( (match = strstr( optarg, "sk" )) && match == optarg ) {
11c606a6 (kx 2023-04-11 01:18:34 +0300  789)               priority = SKIP;
11c606a6 (kx 2023-04-11 01:18:34 +0300  790)             }
11c606a6 (kx 2023-04-11 01:18:34 +0300  791)             else {
11c606a6 (kx 2023-04-11 01:18:34 +0300  792)               FATAL_ERROR( "Unknown --priority '%s' value", optarg );
11c606a6 (kx 2023-04-11 01:18:34 +0300  793)             }
11c606a6 (kx 2023-04-11 01:18:34 +0300  794)           }
11c606a6 (kx 2023-04-11 01:18:34 +0300  795)           else
11c606a6 (kx 2023-04-11 01:18:34 +0300  796)           {
11c606a6 (kx 2023-04-11 01:18:34 +0300  797)             FATAL_ERROR( "Unknown --priority '%s' value", optarg );
11c606a6 (kx 2023-04-11 01:18:34 +0300  798)           }
11c606a6 (kx 2023-04-11 01:18:34 +0300  799)         }
11c606a6 (kx 2023-04-11 01:18:34 +0300  800)         else
11c606a6 (kx 2023-04-11 01:18:34 +0300  801)           /* option is present but without value */
11c606a6 (kx 2023-04-11 01:18:34 +0300  802)           usage();
11c606a6 (kx 2023-04-11 01:18:34 +0300  803)         break;
11c606a6 (kx 2023-04-11 01:18:34 +0300  804)       }
11c606a6 (kx 2023-04-11 01:18:34 +0300  805) 
11c606a6 (kx 2023-04-11 01:18:34 +0300  806)       case 'l':
11c606a6 (kx 2023-04-11 01:18:34 +0300  807)       {
11c606a6 (kx 2023-04-11 01:18:34 +0300  808)         if( optarg != NULL )
11c606a6 (kx 2023-04-11 01:18:34 +0300  809)         {
11c606a6 (kx 2023-04-11 01:18:34 +0300  810)           pkglist_fname = xstrdup( (const char *)optarg );
11c606a6 (kx 2023-04-11 01:18:34 +0300  811)         }
11c606a6 (kx 2023-04-11 01:18:34 +0300  812)         else
11c606a6 (kx 2023-04-11 01:18:34 +0300  813)           /* option is present but without value */
11c606a6 (kx 2023-04-11 01:18:34 +0300  814)           usage();
11c606a6 (kx 2023-04-11 01:18:34 +0300  815)         break;
11c606a6 (kx 2023-04-11 01:18:34 +0300  816)       }
11c606a6 (kx 2023-04-11 01:18:34 +0300  817) 
11c606a6 (kx 2023-04-11 01:18:34 +0300  818)       case 'r':
11c606a6 (kx 2023-04-11 01:18:34 +0300  819)       {
11c606a6 (kx 2023-04-11 01:18:34 +0300  820)         if( optarg != NULL )
11c606a6 (kx 2023-04-11 01:18:34 +0300  821)         {
11c606a6 (kx 2023-04-11 01:18:34 +0300  822)           char cwd[PATH_MAX];
11c606a6 (kx 2023-04-11 01:18:34 +0300  823) 
11c606a6 (kx 2023-04-11 01:18:34 +0300  824)           bzero( (void *)cwd, PATH_MAX );
11c606a6 (kx 2023-04-11 01:18:34 +0300  825)           if( optarg[0] != '/' && curdir )
11c606a6 (kx 2023-04-11 01:18:34 +0300  826)           {
11c606a6 (kx 2023-04-11 01:18:34 +0300  827)             /* skip current directory definition './' at start of argument: */
11c606a6 (kx 2023-04-11 01:18:34 +0300  828)             if( !strncmp( optarg, "./", 2 ) && strncmp( optarg, "..", 2 ) )
11c606a6 (kx 2023-04-11 01:18:34 +0300  829)               (void)sprintf( cwd, "%s/%s", curdir, optarg + 2 );
11c606a6 (kx 2023-04-11 01:18:34 +0300  830)             else if( (strlen( optarg ) == 1) && !strncmp( optarg, ".", 1 ) )
11c606a6 (kx 2023-04-11 01:18:34 +0300  831)               (void)sprintf( cwd, "%s", curdir );
11c606a6 (kx 2023-04-11 01:18:34 +0300  832)             else
11c606a6 (kx 2023-04-11 01:18:34 +0300  833)               (void)sprintf( cwd, "%s/%s", curdir, optarg );
11c606a6 (kx 2023-04-11 01:18:34 +0300  834)             root = xstrdup( (const char *)cwd );
11c606a6 (kx 2023-04-11 01:18:34 +0300  835)           }
11c606a6 (kx 2023-04-11 01:18:34 +0300  836)           else
11c606a6 (kx 2023-04-11 01:18:34 +0300  837)           {
11c606a6 (kx 2023-04-11 01:18:34 +0300  838)             root = xstrdup( (const char *)optarg );
11c606a6 (kx 2023-04-11 01:18:34 +0300  839)           }
11c606a6 (kx 2023-04-11 01:18:34 +0300  840)           remove_trailing_slash( root );
11c606a6 (kx 2023-04-11 01:18:34 +0300  841)         }
11c606a6 (kx 2023-04-11 01:18:34 +0300  842)         else
11c606a6 (kx 2023-04-11 01:18:34 +0300  843)           /* option is present but without value */
11c606a6 (kx 2023-04-11 01:18:34 +0300  844)           usage();
11c606a6 (kx 2023-04-11 01:18:34 +0300  845)         break;
11c606a6 (kx 2023-04-11 01:18:34 +0300  846)       }
11c606a6 (kx 2023-04-11 01:18:34 +0300  847) 
11c606a6 (kx 2023-04-11 01:18:34 +0300  848)       case '?': default:
11c606a6 (kx 2023-04-11 01:18:34 +0300  849)       {
11c606a6 (kx 2023-04-11 01:18:34 +0300  850)         usage();
11c606a6 (kx 2023-04-11 01:18:34 +0300  851)         break;
11c606a6 (kx 2023-04-11 01:18:34 +0300  852)       }
11c606a6 (kx 2023-04-11 01:18:34 +0300  853)     }
11c606a6 (kx 2023-04-11 01:18:34 +0300  854)   }
11c606a6 (kx 2023-04-11 01:18:34 +0300  855) 
11c606a6 (kx 2023-04-11 01:18:34 +0300  856) 
11c606a6 (kx 2023-04-11 01:18:34 +0300  857)   if( optind < argc )
11c606a6 (kx 2023-04-11 01:18:34 +0300  858)   {
11c606a6 (kx 2023-04-11 01:18:34 +0300  859)     struct stat st;
11c606a6 (kx 2023-04-11 01:18:34 +0300  860)     char  *buf = NULL;
11c606a6 (kx 2023-04-11 01:18:34 +0300  861) 
11c606a6 (kx 2023-04-11 01:18:34 +0300  862)     bzero( (void *)&st, sizeof( struct stat ) );
11c606a6 (kx 2023-04-11 01:18:34 +0300  863) 
11c606a6 (kx 2023-04-11 01:18:34 +0300  864)     buf = (char *)malloc( (size_t)PATH_MAX );
11c606a6 (kx 2023-04-11 01:18:34 +0300  865)     if( !buf ) { FATAL_ERROR( "Cannot allocate memory" ); }
11c606a6 (kx 2023-04-11 01:18:34 +0300  866)     bzero( (void *)buf, PATH_MAX );
11c606a6 (kx 2023-04-11 01:18:34 +0300  867) 
11c606a6 (kx 2023-04-11 01:18:34 +0300  868)     /* absolute path to input package: */
11c606a6 (kx 2023-04-11 01:18:34 +0300  869)     if( argv[optind][0] != '/' && curdir )
11c606a6 (kx 2023-04-11 01:18:34 +0300  870)       (void)sprintf( buf, "%s/%s", curdir, (const char *)argv[optind] );
11c606a6 (kx 2023-04-11 01:18:34 +0300  871)     else
11c606a6 (kx 2023-04-11 01:18:34 +0300  872)       (void)strcpy( buf, (const char *)argv[optind] );
11c606a6 (kx 2023-04-11 01:18:34 +0300  873) 
11c606a6 (kx 2023-04-11 01:18:34 +0300  874)     if( stat( (const char *)&buf[0], &st ) == -1 )
11c606a6 (kx 2023-04-11 01:18:34 +0300  875)     {
11c606a6 (kx 2023-04-11 01:18:34 +0300  876)       FATAL_ERROR( "Cannot access '%s' file: %s", buf, strerror( errno ) );
11c606a6 (kx 2023-04-11 01:18:34 +0300  877)     }
11c606a6 (kx 2023-04-11 01:18:34 +0300  878) 
11c606a6 (kx 2023-04-11 01:18:34 +0300  879)     if( S_ISREG(st.st_mode) )
11c606a6 (kx 2023-04-11 01:18:34 +0300  880)     {
11c606a6 (kx 2023-04-11 01:18:34 +0300  881)       pkg_fname = xstrdup( (const char *)&buf[0] );
11c606a6 (kx 2023-04-11 01:18:34 +0300  882)       bind_asc_extention( buf );
11c606a6 (kx 2023-04-11 01:18:34 +0300  883)       asc_fname = xstrdup( (const char *)&buf[0] );
11c606a6 (kx 2023-04-11 01:18:34 +0300  884)       free( buf );
11c606a6 (kx 2023-04-11 01:18:34 +0300  885)     }
11c606a6 (kx 2023-04-11 01:18:34 +0300  886)     else
11c606a6 (kx 2023-04-11 01:18:34 +0300  887)     {
11c606a6 (kx 2023-04-11 01:18:34 +0300  888)       FATAL_ERROR( "Input package '%s' is not a regular file", (const char *)argv[optind] );
11c606a6 (kx 2023-04-11 01:18:34 +0300  889)     }
11c606a6 (kx 2023-04-11 01:18:34 +0300  890)   }
11c606a6 (kx 2023-04-11 01:18:34 +0300  891)   else
11c606a6 (kx 2023-04-11 01:18:34 +0300  892)   {
11c606a6 (kx 2023-04-11 01:18:34 +0300  893)     usage();
11c606a6 (kx 2023-04-11 01:18:34 +0300  894)   }
11c606a6 (kx 2023-04-11 01:18:34 +0300  895) 
11c606a6 (kx 2023-04-11 01:18:34 +0300  896) 
11c606a6 (kx 2023-04-11 01:18:34 +0300  897)   if( !pkgs_path )
11c606a6 (kx 2023-04-11 01:18:34 +0300  898)   {
11c606a6 (kx 2023-04-11 01:18:34 +0300  899)     struct stat st;
11c606a6 (kx 2023-04-11 01:18:34 +0300  900)     char  *buf = NULL;
11c606a6 (kx 2023-04-11 01:18:34 +0300  901)     int    len;
11c606a6 (kx 2023-04-11 01:18:34 +0300  902) 
11c606a6 (kx 2023-04-11 01:18:34 +0300  903)     bzero( (void *)&st, sizeof( struct stat ) );
11c606a6 (kx 2023-04-11 01:18:34 +0300  904) 
11c606a6 (kx 2023-04-11 01:18:34 +0300  905)     buf = (char *)malloc( (size_t)PATH_MAX );
11c606a6 (kx 2023-04-11 01:18:34 +0300  906)     if( !buf ) { FATAL_ERROR( "Cannot allocate memory" ); }
11c606a6 (kx 2023-04-11 01:18:34 +0300  907)     bzero( (void *)buf, PATH_MAX );
11c606a6 (kx 2023-04-11 01:18:34 +0300  908) 
11c606a6 (kx 2023-04-11 01:18:34 +0300  909)     if( !root )
11c606a6 (kx 2023-04-11 01:18:34 +0300  910)     {
11c606a6 (kx 2023-04-11 01:18:34 +0300  911)       buf[0] = '/'; buf[1] = '\0';
11c606a6 (kx 2023-04-11 01:18:34 +0300  912)       root = xstrdup( (const char *)buf );
11c606a6 (kx 2023-04-11 01:18:34 +0300  913)     }
11c606a6 (kx 2023-04-11 01:18:34 +0300  914)     else
11c606a6 (kx 2023-04-11 01:18:34 +0300  915)     {
11c606a6 (kx 2023-04-11 01:18:34 +0300  916)       len = strlen( root );
11c606a6 (kx 2023-04-11 01:18:34 +0300  917) 
11c606a6 (kx 2023-04-11 01:18:34 +0300  918)       (void)strcpy( buf, (const char *)root );
11c606a6 (kx 2023-04-11 01:18:34 +0300  919)       if( buf[ len - 1 ] != '/' )
11c606a6 (kx 2023-04-11 01:18:34 +0300  920)       {
11c606a6 (kx 2023-04-11 01:18:34 +0300  921)         buf[len] = '/'; buf[len+1] = '\0';
11c606a6 (kx 2023-04-11 01:18:34 +0300  922)         free( root ); root = xstrdup( (const char *)buf );
11c606a6 (kx 2023-04-11 01:18:34 +0300  923)       }
11c606a6 (kx 2023-04-11 01:18:34 +0300  924)     }
11c606a6 (kx 2023-04-11 01:18:34 +0300  925) 
11c606a6 (kx 2023-04-11 01:18:34 +0300  926)     if( stat( (const char *)&buf[0], &st ) == -1 )
11c606a6 (kx 2023-04-11 01:18:34 +0300  927)     {
11c606a6 (kx 2023-04-11 01:18:34 +0300  928)       FATAL_ERROR( "Cannot access '%s' file or directory: %s", buf, strerror( errno ) );
11c606a6 (kx 2023-04-11 01:18:34 +0300  929)     }
11c606a6 (kx 2023-04-11 01:18:34 +0300  930)     if( !S_ISDIR(st.st_mode) )
11c606a6 (kx 2023-04-11 01:18:34 +0300  931)     {
11c606a6 (kx 2023-04-11 01:18:34 +0300  932)       FATAL_ERROR( "Defined --root '%s' is not a directory", buf );
11c606a6 (kx 2023-04-11 01:18:34 +0300  933)     }
11c606a6 (kx 2023-04-11 01:18:34 +0300  934) 
11c606a6 (kx 2023-04-11 01:18:34 +0300  935)     len = strlen( (const char *)buf );
11c606a6 (kx 2023-04-11 01:18:34 +0300  936) 
11c606a6 (kx 2023-04-11 01:18:34 +0300  937)     (void)strcat( buf, PACKAGES_PATH );
11c606a6 (kx 2023-04-11 01:18:34 +0300  938)     if( _mkdir_p( buf, S_IRWXU | S_IRWXG | S_IRWXO ) != 0 )
11c606a6 (kx 2023-04-11 01:18:34 +0300  939)     {
11c606a6 (kx 2023-04-11 01:18:34 +0300  940)       FATAL_ERROR( "Cannot access '/%s' directory", PACKAGES_PATH );
11c606a6 (kx 2023-04-11 01:18:34 +0300  941)     }
11c606a6 (kx 2023-04-11 01:18:34 +0300  942)     pkgs_path = xstrdup( (const char *)&buf[0] );
11c606a6 (kx 2023-04-11 01:18:34 +0300  943) 
11c606a6 (kx 2023-04-11 01:18:34 +0300  944)     /*********************************************
11c606a6 (kx 2023-04-11 01:18:34 +0300  945)       Create other directories of Setup Database:
11c606a6 (kx 2023-04-11 01:18:34 +0300  946)      */
11c606a6 (kx 2023-04-11 01:18:34 +0300  947)     buf[len] = '\0';
11c606a6 (kx 2023-04-11 01:18:34 +0300  948)     (void)strcat( buf, REMOVED_PKGS_PATH );
11c606a6 (kx 2023-04-11 01:18:34 +0300  949)     if( _mkdir_p( buf, S_IRWXU | S_IRWXG | S_IRWXO ) != 0 )
11c606a6 (kx 2023-04-11 01:18:34 +0300  950)     {
11c606a6 (kx 2023-04-11 01:18:34 +0300  951)       FATAL_ERROR( "Cannot access '/%s' directory", REMOVED_PKGS_PATH );
11c606a6 (kx 2023-04-11 01:18:34 +0300  952)     }
11c606a6 (kx 2023-04-11 01:18:34 +0300  953)     rempkgs_path = xstrdup( (const char *)&buf[0] );
11c606a6 (kx 2023-04-11 01:18:34 +0300  954) 
11c606a6 (kx 2023-04-11 01:18:34 +0300  955)     buf[len] = '\0';
11c606a6 (kx 2023-04-11 01:18:34 +0300  956)     (void)strcat( buf, SETUP_PATH );
11c606a6 (kx 2023-04-11 01:18:34 +0300  957)     if( _mkdir_p( buf, S_IRWXU | S_IRWXG | S_IRWXO ) != 0 )
11c606a6 (kx 2023-04-11 01:18:34 +0300  958)     {
11c606a6 (kx 2023-04-11 01:18:34 +0300  959)       FATAL_ERROR( "Cannot access '/%s' directory", SETUP_PATH );
11c606a6 (kx 2023-04-11 01:18:34 +0300  960)     }
11c606a6 (kx 2023-04-11 01:18:34 +0300  961) 
11c606a6 (kx 2023-04-11 01:18:34 +0300  962)     /*********************************************
11c606a6 (kx 2023-04-11 01:18:34 +0300  963)       Allocate memory for Setup LOG File name:
11c606a6 (kx 2023-04-11 01:18:34 +0300  964)      */
11c606a6 (kx 2023-04-11 01:18:34 +0300  965)     buf[len] = '\0';
11c606a6 (kx 2023-04-11 01:18:34 +0300  966)     (void)strcat( buf, LOG_PATH );
11c606a6 (kx 2023-04-11 01:18:34 +0300  967)     (void)strcat( buf, SETUP_LOG_FILE );
11c606a6 (kx 2023-04-11 01:18:34 +0300  968)     log_fname = xstrdup( (const char *)&buf[0] );
11c606a6 (kx 2023-04-11 01:18:34 +0300  969) 
11c606a6 (kx 2023-04-11 01:18:34 +0300  970)     free( buf );
11c606a6 (kx 2023-04-11 01:18:34 +0300  971) 
11c606a6 (kx 2023-04-11 01:18:34 +0300  972)   } /* End if( !pkgs_path ) */
11c606a6 (kx 2023-04-11 01:18:34 +0300  973) }
11c606a6 (kx 2023-04-11 01:18:34 +0300  974) 
11c606a6 (kx 2023-04-11 01:18:34 +0300  975) static void setup_log( char *format, ... )
11c606a6 (kx 2023-04-11 01:18:34 +0300  976) {
11c606a6 (kx 2023-04-11 01:18:34 +0300  977)   FILE *fp = NULL;
11c606a6 (kx 2023-04-11 01:18:34 +0300  978) 
11c606a6 (kx 2023-04-11 01:18:34 +0300  979)   time_t     t = time( NULL );
11c606a6 (kx 2023-04-11 01:18:34 +0300  980)   struct tm tm = *localtime(&t);
11c606a6 (kx 2023-04-11 01:18:34 +0300  981) 
11c606a6 (kx 2023-04-11 01:18:34 +0300  982)   va_list argp;
11c606a6 (kx 2023-04-11 01:18:34 +0300  983) 
11c606a6 (kx 2023-04-11 01:18:34 +0300  984)   if( ! format ) return;
11c606a6 (kx 2023-04-11 01:18:34 +0300  985) 
11c606a6 (kx 2023-04-11 01:18:34 +0300  986)   fp = fopen( (const char *)log_fname, "a" );
11c606a6 (kx 2023-04-11 01:18:34 +0300  987)   if( !fp )
11c606a6 (kx 2023-04-11 01:18:34 +0300  988)   {
11c606a6 (kx 2023-04-11 01:18:34 +0300  989)     FATAL_ERROR( "Cannot open /%s%s file", LOG_PATH, SETUP_LOG_FILE );
11c606a6 (kx 2023-04-11 01:18:34 +0300  990)   }
11c606a6 (kx 2023-04-11 01:18:34 +0300  991) 
11c606a6 (kx 2023-04-11 01:18:34 +0300  992)   fprintf( fp, "[%04d-%02d-%02d %02d:%02d:%02d]: ",
11c606a6 (kx 2023-04-11 01:18:34 +0300  993)                   tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday,
11c606a6 (kx 2023-04-11 01:18:34 +0300  994)                                  tm.tm_hour, tm.tm_min, tm.tm_sec );
11c606a6 (kx 2023-04-11 01:18:34 +0300  995) 
11c606a6 (kx 2023-04-11 01:18:34 +0300  996)   va_start( argp, format );
11c606a6 (kx 2023-04-11 01:18:34 +0300  997)   vfprintf( fp, format, argp );
11c606a6 (kx 2023-04-11 01:18:34 +0300  998)   fprintf( fp, "\n" );
11c606a6 (kx 2023-04-11 01:18:34 +0300  999) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1000)   fflush( fp );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1001)   fclose( fp );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1002) }
11c606a6 (kx 2023-04-11 01:18:34 +0300 1003) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1004) /***********************************************************
11c606a6 (kx 2023-04-11 01:18:34 +0300 1005)   Remove leading spaces and take non-space characters only:
11c606a6 (kx 2023-04-11 01:18:34 +0300 1006)   (Especialy for pkginfo lines)
11c606a6 (kx 2023-04-11 01:18:34 +0300 1007)  */
11c606a6 (kx 2023-04-11 01:18:34 +0300 1008) static char *skip_spaces( char *s )
11c606a6 (kx 2023-04-11 01:18:34 +0300 1009) {
11c606a6 (kx 2023-04-11 01:18:34 +0300 1010)   char *q, *p = (char *)0;
11c606a6 (kx 2023-04-11 01:18:34 +0300 1011) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1012)   if( !s || *s == '\0' ) return p;
11c606a6 (kx 2023-04-11 01:18:34 +0300 1013) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1014)   p = s;
11c606a6 (kx 2023-04-11 01:18:34 +0300 1015) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1016)   while( (*p == ' ' || *p == '\t') && *p != '\0' ) { ++p; } q = p;
11c606a6 (kx 2023-04-11 01:18:34 +0300 1017)   while(  *q != ' ' && *q != '\t'  && *q != '\0' ) { ++q; } *q = '\0';
11c606a6 (kx 2023-04-11 01:18:34 +0300 1018) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1019)   if( *p == '\0' ) return (char *)0;
11c606a6 (kx 2023-04-11 01:18:34 +0300 1020) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1021)   return( xstrdup( (const char *)p ) );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1022) }
11c606a6 (kx 2023-04-11 01:18:34 +0300 1023) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1024) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1025) /*******************************
11c606a6 (kx 2023-04-11 01:18:34 +0300 1026)   remove spaces at end of line:
11c606a6 (kx 2023-04-11 01:18:34 +0300 1027)  */
11c606a6 (kx 2023-04-11 01:18:34 +0300 1028) static void skip_eol_spaces( char *s )
11c606a6 (kx 2023-04-11 01:18:34 +0300 1029) {
11c606a6 (kx 2023-04-11 01:18:34 +0300 1030)   char *p = (char *)0;
11c606a6 (kx 2023-04-11 01:18:34 +0300 1031) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1032)   if( !s || *s == '\0' ) return;
11c606a6 (kx 2023-04-11 01:18:34 +0300 1033) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1034)   p = s + strlen( s ) - 1;
11c606a6 (kx 2023-04-11 01:18:34 +0300 1035)   while( isspace( *p ) ) { *p-- = '\0'; }
11c606a6 (kx 2023-04-11 01:18:34 +0300 1036) }
11c606a6 (kx 2023-04-11 01:18:34 +0300 1037) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1038) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1039) static char *trim( char *s )
11c606a6 (kx 2023-04-11 01:18:34 +0300 1040) {
11c606a6 (kx 2023-04-11 01:18:34 +0300 1041)   char *p = (char *)0;
11c606a6 (kx 2023-04-11 01:18:34 +0300 1042) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1043)   if( !s || *s == '\0' ) return p;
11c606a6 (kx 2023-04-11 01:18:34 +0300 1044) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1045)   p = s + strlen( s ) - 1;
11c606a6 (kx 2023-04-11 01:18:34 +0300 1046)   while( isspace( *p ) ) { *p-- = '\0'; }
11c606a6 (kx 2023-04-11 01:18:34 +0300 1047)   p = s; while( isspace( *p ) ) { ++p; }
11c606a6 (kx 2023-04-11 01:18:34 +0300 1048) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1049)   return( p );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1050) }
11c606a6 (kx 2023-04-11 01:18:34 +0300 1051) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1052) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1053) static char *size_to_string( size_t pkgsize )
11c606a6 (kx 2023-04-11 01:18:34 +0300 1054) {
11c606a6 (kx 2023-04-11 01:18:34 +0300 1055)   int    nd;
11c606a6 (kx 2023-04-11 01:18:34 +0300 1056)   double sz = (double)pkgsize / (double)1024;
11c606a6 (kx 2023-04-11 01:18:34 +0300 1057) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1058)   char  *ret = NULL;
11c606a6 (kx 2023-04-11 01:18:34 +0300 1059)   char  *tmp = NULL;
11c606a6 (kx 2023-04-11 01:18:34 +0300 1060) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1061)   tmp = (char *)malloc( PATH_MAX );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1062)   if( !tmp ) { FATAL_ERROR( "Cannot allocate memory" ); }
11c606a6 (kx 2023-04-11 01:18:34 +0300 1063)   bzero( (void *)tmp, PATH_MAX );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1064) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1065)   if( sz > (double)1048576 )
11c606a6 (kx 2023-04-11 01:18:34 +0300 1066)   {
11c606a6 (kx 2023-04-11 01:18:34 +0300 1067)     sz = sz / (double)1048576;
11c606a6 (kx 2023-04-11 01:18:34 +0300 1068)     /*
11c606a6 (kx 2023-04-11 01:18:34 +0300 1069)       NOTE:
11c606a6 (kx 2023-04-11 01:18:34 +0300 1070)       ----
11c606a6 (kx 2023-04-11 01:18:34 +0300 1071)       Операция округления до одного знака после десятичной точки: sz = round(sz*10.0)/10.0;
11c606a6 (kx 2023-04-11 01:18:34 +0300 1072)       здесь не нужна; можно обойтись вычислением количества цифр, выводимых на печать с помощью
11c606a6 (kx 2023-04-11 01:18:34 +0300 1073)       формата '%.*g':
11c606a6 (kx 2023-04-11 01:18:34 +0300 1074) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1075)       Количество десятичных цифр, необходимое для предстваления целой части числа + 1(одна)
11c606a6 (kx 2023-04-11 01:18:34 +0300 1076)       десятичная цифра после десятичной точки. Формат %.*g не будет выводить дробную часть
11c606a6 (kx 2023-04-11 01:18:34 +0300 1077)       числа, если после округления, до одного знака после десятичной точки, дробная часть
11c606a6 (kx 2023-04-11 01:18:34 +0300 1078)       равна нулю:
11c606a6 (kx 2023-04-11 01:18:34 +0300 1079)      */
11c606a6 (kx 2023-04-11 01:18:34 +0300 1080)     nd = (int)ceil(log10(floor(sz) + 1.0)) + 1;
11c606a6 (kx 2023-04-11 01:18:34 +0300 1081)     (void)sprintf( (char *)&tmp[0], "%.*gG", nd, sz );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1082)   }
11c606a6 (kx 2023-04-11 01:18:34 +0300 1083)   else if( sz > (double)1024 )
11c606a6 (kx 2023-04-11 01:18:34 +0300 1084)   {
11c606a6 (kx 2023-04-11 01:18:34 +0300 1085)     sz = sz / (double)1024;
11c606a6 (kx 2023-04-11 01:18:34 +0300 1086)     nd = (int)ceil(log10(floor(sz) + 1.0)) + 1;
11c606a6 (kx 2023-04-11 01:18:34 +0300 1087)     (void)sprintf( (char *)&tmp[0], "%.*gM", nd, sz );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1088)   }
11c606a6 (kx 2023-04-11 01:18:34 +0300 1089)   else
11c606a6 (kx 2023-04-11 01:18:34 +0300 1090)   {
11c606a6 (kx 2023-04-11 01:18:34 +0300 1091)     nd = (int)ceil(log10(floor(sz) + 1.0)) + 1;
11c606a6 (kx 2023-04-11 01:18:34 +0300 1092)     (void)sprintf( (char *)&tmp[0], "%.*gK", nd, sz );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1093)   }
11c606a6 (kx 2023-04-11 01:18:34 +0300 1094) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1095)   ret = xstrdup( (const char *)&tmp[0] );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1096)   free( tmp );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1097) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1098)   return ret;
11c606a6 (kx 2023-04-11 01:18:34 +0300 1099) }
11c606a6 (kx 2023-04-11 01:18:34 +0300 1100) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1101) static void read_input_pkginfo( const char *pkginfo_fname )
11c606a6 (kx 2023-04-11 01:18:34 +0300 1102) {
11c606a6 (kx 2023-04-11 01:18:34 +0300 1103)   char *ln      = NULL;
11c606a6 (kx 2023-04-11 01:18:34 +0300 1104)   char *line    = NULL;
11c606a6 (kx 2023-04-11 01:18:34 +0300 1105) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1106)   FILE *pkginfo = NULL;
11c606a6 (kx 2023-04-11 01:18:34 +0300 1107) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1108)   if( pkginfo_fname != NULL )
11c606a6 (kx 2023-04-11 01:18:34 +0300 1109)   {
11c606a6 (kx 2023-04-11 01:18:34 +0300 1110)     pkginfo = fopen( (const char *)pkginfo_fname, "r" );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1111)     if( !pkginfo )
11c606a6 (kx 2023-04-11 01:18:34 +0300 1112)     {
11c606a6 (kx 2023-04-11 01:18:34 +0300 1113)       FATAL_ERROR( "Cannot open %s file", pkginfo_fname );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1114)     }
11c606a6 (kx 2023-04-11 01:18:34 +0300 1115)   }
11c606a6 (kx 2023-04-11 01:18:34 +0300 1116) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1117)   line = (char *)malloc( (size_t)PATH_MAX );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1118)   if( !line )
11c606a6 (kx 2023-04-11 01:18:34 +0300 1119)   {
11c606a6 (kx 2023-04-11 01:18:34 +0300 1120)     FATAL_ERROR( "Cannot allocate memory" );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1121)   }
11c606a6 (kx 2023-04-11 01:18:34 +0300 1122) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1123)   while( (ln = fgets( line, PATH_MAX, pkginfo )) )
11c606a6 (kx 2023-04-11 01:18:34 +0300 1124)   {
11c606a6 (kx 2023-04-11 01:18:34 +0300 1125)     char *match = NULL;
11c606a6 (kx 2023-04-11 01:18:34 +0300 1126) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1127)     ln[strlen(ln) - 1] = '\0'; /* replace new-line symbol      */
11c606a6 (kx 2023-04-11 01:18:34 +0300 1128)     skip_eol_spaces( ln );     /* remove spaces at end-of-line */
11c606a6 (kx 2023-04-11 01:18:34 +0300 1129) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1130)     if( (match = strstr( ln, "pkgname" )) && match == ln ) {
11c606a6 (kx 2023-04-11 01:18:34 +0300 1131)       char *p = index( match, '=' ) + 1;
11c606a6 (kx 2023-04-11 01:18:34 +0300 1132)       if( p != NULL ) pkgname = skip_spaces( p );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1133)     }
11c606a6 (kx 2023-04-11 01:18:34 +0300 1134)     if( (match = strstr( ln, "pkgver" )) && match == ln ) {
11c606a6 (kx 2023-04-11 01:18:34 +0300 1135)       char *p = index( match, '=' ) + 1;
11c606a6 (kx 2023-04-11 01:18:34 +0300 1136)       if( p != NULL ) pkgver = skip_spaces( p );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1137)     }
11c606a6 (kx 2023-04-11 01:18:34 +0300 1138)     if( (match = strstr( ln, "arch" )) && match == ln ) {
11c606a6 (kx 2023-04-11 01:18:34 +0300 1139)       char *p = index( match, '=' ) + 1;
11c606a6 (kx 2023-04-11 01:18:34 +0300 1140)       if( p != NULL ) arch = skip_spaces( p );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1141)     }
11c606a6 (kx 2023-04-11 01:18:34 +0300 1142)     if( (match = strstr( ln, "distroname" )) && match == ln ) {
11c606a6 (kx 2023-04-11 01:18:34 +0300 1143)       char *p = index( match, '=' ) + 1;
11c606a6 (kx 2023-04-11 01:18:34 +0300 1144)       if( p != NULL ) distroname = skip_spaces( p );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1145)     }
11c606a6 (kx 2023-04-11 01:18:34 +0300 1146)     if( (match = strstr( ln, "distrover" )) && match == ln ) {
11c606a6 (kx 2023-04-11 01:18:34 +0300 1147)       char *p = index( match, '=' ) + 1;
11c606a6 (kx 2023-04-11 01:18:34 +0300 1148)       if( p != NULL ) distrover = skip_spaces( p );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1149)     }
11c606a6 (kx 2023-04-11 01:18:34 +0300 1150) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1151)     if( (match = strstr( ln, "group" )) && match == ln ) {
11c606a6 (kx 2023-04-11 01:18:34 +0300 1152)       char *p = index( match, '=' ) + 1;
11c606a6 (kx 2023-04-11 01:18:34 +0300 1153)       if( p != NULL ) group = skip_spaces( p );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1154)     }
11c606a6 (kx 2023-04-11 01:18:34 +0300 1155) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1156)     if( (match = strstr( ln, "short_description" )) && match == ln ) {
11c606a6 (kx 2023-04-11 01:18:34 +0300 1157)       char *p = index( match, '=' ) + 1;
11c606a6 (kx 2023-04-11 01:18:34 +0300 1158)       if( p != NULL )
11c606a6 (kx 2023-04-11 01:18:34 +0300 1159)       {
11c606a6 (kx 2023-04-11 01:18:34 +0300 1160)         char *b =  index( p, '"'),
11c606a6 (kx 2023-04-11 01:18:34 +0300 1161)              *e = rindex( p, '"');
11c606a6 (kx 2023-04-11 01:18:34 +0300 1162)         if( b && e && ( b != e ) )
11c606a6 (kx 2023-04-11 01:18:34 +0300 1163)         {
11c606a6 (kx 2023-04-11 01:18:34 +0300 1164)           p = ++b; *e = '\0';
11c606a6 (kx 2023-04-11 01:18:34 +0300 1165)           short_description = xstrdup( (const char *)p );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1166)         }
11c606a6 (kx 2023-04-11 01:18:34 +0300 1167)       }
11c606a6 (kx 2023-04-11 01:18:34 +0300 1168)     }
11c606a6 (kx 2023-04-11 01:18:34 +0300 1169)     if( (match = strstr( ln, "url" )) && match == ln ) {
11c606a6 (kx 2023-04-11 01:18:34 +0300 1170)       char *p = index( match, '=' ) + 1;
11c606a6 (kx 2023-04-11 01:18:34 +0300 1171)       if( p != NULL ) url = skip_spaces( p );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1172)     }
11c606a6 (kx 2023-04-11 01:18:34 +0300 1173)     if( (match = strstr( ln, "license" )) && match == ln ) {
11c606a6 (kx 2023-04-11 01:18:34 +0300 1174)       char *p = index( match, '=' ) + 1;
11c606a6 (kx 2023-04-11 01:18:34 +0300 1175)       if( p != NULL ) license = skip_spaces( p );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1176)     }
11c606a6 (kx 2023-04-11 01:18:34 +0300 1177) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1178)     if( (match = strstr( ln, "uncompressed_size" )) && match == ln ) {
11c606a6 (kx 2023-04-11 01:18:34 +0300 1179)       char *p = index( match, '=' ) + 1;
11c606a6 (kx 2023-04-11 01:18:34 +0300 1180)       if( p != NULL ) uncompressed_size = skip_spaces( p );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1181)     }
11c606a6 (kx 2023-04-11 01:18:34 +0300 1182)     if( (match = strstr( ln, "total_files" )) && match == ln ) {
11c606a6 (kx 2023-04-11 01:18:34 +0300 1183)       char *p = index( match, '=' ) + 1;
11c606a6 (kx 2023-04-11 01:18:34 +0300 1184)       if( p != NULL ) total_files = skip_spaces( p );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1185)     }
11c606a6 (kx 2023-04-11 01:18:34 +0300 1186)   }
11c606a6 (kx 2023-04-11 01:18:34 +0300 1187) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1188)   free( line );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1189) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1190)   if( !pkgname || !pkgver || !arch || !distroname || !distrover )
11c606a6 (kx 2023-04-11 01:18:34 +0300 1191)   {
11c606a6 (kx 2023-04-11 01:18:34 +0300 1192)     FATAL_ERROR( "Invalid input .PKGINFO file" );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1193)   }
11c606a6 (kx 2023-04-11 01:18:34 +0300 1194) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1195)   fclose( pkginfo );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1196) }
11c606a6 (kx 2023-04-11 01:18:34 +0300 1197) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1198) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1199) static void read_service_files( void )
11c606a6 (kx 2023-04-11 01:18:34 +0300 1200) {
11c606a6 (kx 2023-04-11 01:18:34 +0300 1201)   struct stat st;
11c606a6 (kx 2023-04-11 01:18:34 +0300 1202)   char *fname = pkg_fname;
11c606a6 (kx 2023-04-11 01:18:34 +0300 1203) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1204)   enum _input_type  type = IFMT_UNKNOWN;
11c606a6 (kx 2023-04-11 01:18:34 +0300 1205) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1206)   bzero( (void *)&st, sizeof( struct stat ) );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1207) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1208)   if( stat( (const char *)fname, &st ) == -1 )
11c606a6 (kx 2023-04-11 01:18:34 +0300 1209)   {
11c606a6 (kx 2023-04-11 01:18:34 +0300 1210)     FATAL_ERROR( "Cannot access input '%s' file: %s", fname, strerror( errno ) );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1211)   }
11c606a6 (kx 2023-04-11 01:18:34 +0300 1212) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1213)   type = check_input_file( &uncompress, fname );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1214)   if( type != IFMT_PKG )
11c606a6 (kx 2023-04-11 01:18:34 +0300 1215)   {
11c606a6 (kx 2023-04-11 01:18:34 +0300 1216)     FATAL_ERROR( "Unknown format of input '%s' file", fname );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1217)   }
11c606a6 (kx 2023-04-11 01:18:34 +0300 1218) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1219)   if( S_ISREG(st.st_mode) )
11c606a6 (kx 2023-04-11 01:18:34 +0300 1220)   {
11c606a6 (kx 2023-04-11 01:18:34 +0300 1221)     pid_t p = (pid_t) -1;
11c606a6 (kx 2023-04-11 01:18:34 +0300 1222)     int   rc;
11c606a6 (kx 2023-04-11 01:18:34 +0300 1223) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1224)     int   len = 0;
11c606a6 (kx 2023-04-11 01:18:34 +0300 1225)     char *tmp= NULL, *cmd = NULL;
11c606a6 (kx 2023-04-11 01:18:34 +0300 1226) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1227)     tmp = (char *)malloc( (size_t)PATH_MAX );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1228)     if( !tmp ) { FATAL_ERROR( "Cannot allocate memory" ); }
11c606a6 (kx 2023-04-11 01:18:34 +0300 1229)     bzero( (void *)tmp, PATH_MAX );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1230) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1231)     (void)sprintf( &tmp[0], "%s", tmpdir );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1232)     if( _mkdir_p( tmp, S_IRWXU | S_IRWXG | S_IRWXO ) != 0 )
11c606a6 (kx 2023-04-11 01:18:34 +0300 1233)     {
11c606a6 (kx 2023-04-11 01:18:34 +0300 1234)       FATAL_ERROR( "Cannot get PKGINFO from '%s' file", basename( (char *)fname ) );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1235)     }
11c606a6 (kx 2023-04-11 01:18:34 +0300 1236) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1237)     cmd = (char *)malloc( (size_t)PATH_MAX );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1238)     if( !cmd ) { FATAL_ERROR( "Cannot allocate memory" ); }
11c606a6 (kx 2023-04-11 01:18:34 +0300 1239)     bzero( (void *)cmd, PATH_MAX );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1240) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1241)     len = snprintf( &cmd[0], PATH_MAX,
11c606a6 (kx 2023-04-11 01:18:34 +0300 1242)                     "%s/pkginfo -d %s"
11c606a6 (kx 2023-04-11 01:18:34 +0300 1243)                     " -o pkginfo,description,requires,restore-links,install-script,filelist"
11c606a6 (kx 2023-04-11 01:18:34 +0300 1244)                     " %s > /dev/null 2>&1",
11c606a6 (kx 2023-04-11 01:18:34 +0300 1245)                     selfdir, tmp, fname );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1246)     if( len == 0 || len == PATH_MAX - 1 )
11c606a6 (kx 2023-04-11 01:18:34 +0300 1247)     {
11c606a6 (kx 2023-04-11 01:18:34 +0300 1248)       FATAL_ERROR( "Cannot get PKGINFO from %s file", basename( (char *)fname ) );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1249)     }
11c606a6 (kx 2023-04-11 01:18:34 +0300 1250)     p = sys_exec_command( cmd );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1251)     rc = sys_wait_command( p, (char *)NULL, PATH_MAX );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1252)     if( rc != 0 )
11c606a6 (kx 2023-04-11 01:18:34 +0300 1253)     {
11c606a6 (kx 2023-04-11 01:18:34 +0300 1254)       FATAL_ERROR( "Cannot get PKGINFO from '%s' file", basename( (char *)fname ) );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1255)     }
11c606a6 (kx 2023-04-11 01:18:34 +0300 1256) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1257)     (void)strcat( tmp, "/.PKGINFO" );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1258)     read_input_pkginfo( (const char *)&tmp[0] );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1259)     *(strstr( tmp, "/.PKGINFO" )) = '\0'; /* :restore tmpdir in tmp[] buffer */
11c606a6 (kx 2023-04-11 01:18:34 +0300 1260) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1261)     compressed_size = size_to_string( st.st_size );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1262) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1263)     /******************
11c606a6 (kx 2023-04-11 01:18:34 +0300 1264)       Get PKGLOG file:
11c606a6 (kx 2023-04-11 01:18:34 +0300 1265)      */
11c606a6 (kx 2023-04-11 01:18:34 +0300 1266)     len = snprintf( &cmd[0], PATH_MAX,
11c606a6 (kx 2023-04-11 01:18:34 +0300 1267)                     "%s/pkglog -m -d %s %s  > /dev/null 2>&1",
11c606a6 (kx 2023-04-11 01:18:34 +0300 1268)                     selfdir, tmp, tmp );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1269)     if( len == 0 || len == PATH_MAX - 1 )
11c606a6 (kx 2023-04-11 01:18:34 +0300 1270)     {
11c606a6 (kx 2023-04-11 01:18:34 +0300 1271)       FATAL_ERROR( "Cannot get PKGLOG from %s file", basename( (char *)fname ) );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1272)     }
11c606a6 (kx 2023-04-11 01:18:34 +0300 1273)     p = sys_exec_command( cmd );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1274)     rc = sys_wait_command( p, (char *)NULL, PATH_MAX );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1275)     if( rc != 0 )
11c606a6 (kx 2023-04-11 01:18:34 +0300 1276)     {
11c606a6 (kx 2023-04-11 01:18:34 +0300 1277)       FATAL_ERROR( "Cannot get PKGLOG from '%s' file", basename( (char *)fname ) );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1278)     }
11c606a6 (kx 2023-04-11 01:18:34 +0300 1279) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1280)     if( group )
11c606a6 (kx 2023-04-11 01:18:34 +0300 1281)       (void)sprintf( cmd, "%s/%s/%s-%s-%s-%s-%s", tmp, group, pkgname, pkgver, arch, distroname, distrover );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1282)     else
11c606a6 (kx 2023-04-11 01:18:34 +0300 1283)       (void)sprintf( cmd, "%s/%s-%s-%s-%s-%s", tmp, pkgname, pkgver, arch, distroname, distrover );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1284) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1285)     bzero( (void *)&st, sizeof( struct stat ) );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1286)     if( stat( (const char *)cmd, &st ) == -1 )
11c606a6 (kx 2023-04-11 01:18:34 +0300 1287)     {
11c606a6 (kx 2023-04-11 01:18:34 +0300 1288)       FATAL_ERROR( "Cannot get PKGLOG from '%s' file: %s", basename( (char *)fname ), strerror( errno ) );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1289)     }
11c606a6 (kx 2023-04-11 01:18:34 +0300 1290) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1291)     pkglog_fname = xstrdup( (const char *)cmd );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1292) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1293)     /*************************************
11c606a6 (kx 2023-04-11 01:18:34 +0300 1294)       Attempt to read packages list file:
11c606a6 (kx 2023-04-11 01:18:34 +0300 1295)      */
11c606a6 (kx 2023-04-11 01:18:34 +0300 1296)     {
11c606a6 (kx 2023-04-11 01:18:34 +0300 1297)       if( !pkglist_fname )
11c606a6 (kx 2023-04-11 01:18:34 +0300 1298)       {
11c606a6 (kx 2023-04-11 01:18:34 +0300 1299)         /*****************************************
11c606a6 (kx 2023-04-11 01:18:34 +0300 1300)           Get source packages path if applicable:
11c606a6 (kx 2023-04-11 01:18:34 +0300 1301)          */
11c606a6 (kx 2023-04-11 01:18:34 +0300 1302)         (void)strcpy( cmd, (const char *)fname );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1303)         (void)strcpy( tmp, dirname( cmd ) );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1304) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1305)         if( group && !strcmp( group, basename( tmp ) ) )
11c606a6 (kx 2023-04-11 01:18:34 +0300 1306)           (void)strcpy( cmd, (const char *)dirname( tmp ) );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1307)         else
11c606a6 (kx 2023-04-11 01:18:34 +0300 1308)           (void)strcpy( cmd, (const char *)tmp );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1309) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1310)         /*****************************************
11c606a6 (kx 2023-04-11 01:18:34 +0300 1311)           Save default packages list file name:
11c606a6 (kx 2023-04-11 01:18:34 +0300 1312)          */
11c606a6 (kx 2023-04-11 01:18:34 +0300 1313)         (void)strcat( cmd, "/.pkglist" );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1314)         pkglist_fname = xstrdup( (const char *)cmd );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1315)       }
11c606a6 (kx 2023-04-11 01:18:34 +0300 1316) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1317)       /**************************
11c606a6 (kx 2023-04-11 01:18:34 +0300 1318)         read .pkglist if exists:
11c606a6 (kx 2023-04-11 01:18:34 +0300 1319)        */
11c606a6 (kx 2023-04-11 01:18:34 +0300 1320)       bzero( (void *)&st, sizeof( struct stat ) );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1321)       if( (stat( (const char *)pkglist_fname, &st ) == 0) && S_ISREG(st.st_mode) )
11c606a6 (kx 2023-04-11 01:18:34 +0300 1322)       {
11c606a6 (kx 2023-04-11 01:18:34 +0300 1323)         char *ln      = NULL;
11c606a6 (kx 2023-04-11 01:18:34 +0300 1324)         char *line    = NULL;
11c606a6 (kx 2023-04-11 01:18:34 +0300 1325) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1326)         FILE *pkglist = NULL;
11c606a6 (kx 2023-04-11 01:18:34 +0300 1327) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1328)         pkglist = fopen( (const char *)pkglist_fname, "r" );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1329)         if( !pkglist )
11c606a6 (kx 2023-04-11 01:18:34 +0300 1330)         {
11c606a6 (kx 2023-04-11 01:18:34 +0300 1331)           FATAL_ERROR( "Cannot open %s file", pkglist_fname );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1332)         }
11c606a6 (kx 2023-04-11 01:18:34 +0300 1333) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1334)         line = (char *)malloc( (size_t)PATH_MAX );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1335)         if( !line )
11c606a6 (kx 2023-04-11 01:18:34 +0300 1336)         {
11c606a6 (kx 2023-04-11 01:18:34 +0300 1337)           FATAL_ERROR( "Cannot allocate memory" );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1338)         }
11c606a6 (kx 2023-04-11 01:18:34 +0300 1339) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1340)         while( (ln = fgets( line, PATH_MAX, pkglist )) )
11c606a6 (kx 2023-04-11 01:18:34 +0300 1341)         {
11c606a6 (kx 2023-04-11 01:18:34 +0300 1342)           char *match = NULL;
11c606a6 (kx 2023-04-11 01:18:34 +0300 1343) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1344)           ln[strlen(ln) - 1] = '\0'; /* replace new-line symbol      */
11c606a6 (kx 2023-04-11 01:18:34 +0300 1345)           skip_eol_spaces( ln );     /* remove spaces at end-of-line */
11c606a6 (kx 2023-04-11 01:18:34 +0300 1346) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1347)           if( (match = strstr( ln, pkgname )) && match == ln )
11c606a6 (kx 2023-04-11 01:18:34 +0300 1348)           {
11c606a6 (kx 2023-04-11 01:18:34 +0300 1349)             char *p = NULL;
11c606a6 (kx 2023-04-11 01:18:34 +0300 1350)             char *name = NULL, *vers = NULL, *desc = NULL, *ball = NULL, *proc = NULL, *prio = NULL;
11c606a6 (kx 2023-04-11 01:18:34 +0300 1351) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1352)             name = ln;
11c606a6 (kx 2023-04-11 01:18:34 +0300 1353)             if( (p = index( (const char *)name, ':' )) ) { *p = '\0'; vers = ++p; name = trim( name ); } else continue;
11c606a6 (kx 2023-04-11 01:18:34 +0300 1354)             if( (p = index( (const char *)vers, ':' )) ) { *p = '\0'; desc = ++p; vers = trim( vers ); } else continue;
11c606a6 (kx 2023-04-11 01:18:34 +0300 1355)             if( (p = index( (const char *)desc, ':' )) ) { *p = '\0'; ball = ++p; desc = trim( desc ); } else continue;
11c606a6 (kx 2023-04-11 01:18:34 +0300 1356)             if( (p = index( (const char *)ball, ':' )) ) { *p = '\0'; proc = ++p; ball = trim( ball ); } else continue;
11c606a6 (kx 2023-04-11 01:18:34 +0300 1357)             if( (p = index( (const char *)proc, ':' )) ) { *p = '\0'; prio = ++p; proc = trim( proc ); } else continue;
11c606a6 (kx 2023-04-11 01:18:34 +0300 1358)             prio = trim( prio );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1359) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1360)             if( name && vers && desc && ball && proc && prio )
11c606a6 (kx 2023-04-11 01:18:34 +0300 1361)             {
11c606a6 (kx 2023-04-11 01:18:34 +0300 1362)               char *grp = index( (const char *)ball, '/' );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1363)               if( grp )
11c606a6 (kx 2023-04-11 01:18:34 +0300 1364)               {
11c606a6 (kx 2023-04-11 01:18:34 +0300 1365)                 *grp = '\0'; grp = ball; grp = trim( grp );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1366)                 if( strcmp( group, grp ) ) continue;
11c606a6 (kx 2023-04-11 01:18:34 +0300 1367)               }
11c606a6 (kx 2023-04-11 01:18:34 +0300 1368) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1369)               /* read priority: */
11c606a6 (kx 2023-04-11 01:18:34 +0300 1370)               if( strlen( (const char*)prio ) > 2 )
11c606a6 (kx 2023-04-11 01:18:34 +0300 1371)               {
11c606a6 (kx 2023-04-11 01:18:34 +0300 1372)                 char *m = NULL;
11c606a6 (kx 2023-04-11 01:18:34 +0300 1373) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1374)                 to_lowercase( prio );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1375)                 if( (m = strstr( prio, "req" )) && m == prio ) {
11c606a6 (kx 2023-04-11 01:18:34 +0300 1376)                   priority = REQUIRED;
11c606a6 (kx 2023-04-11 01:18:34 +0300 1377)                 }
11c606a6 (kx 2023-04-11 01:18:34 +0300 1378)                 else if( (m = strstr( prio, "rec" )) && m == prio ) {
11c606a6 (kx 2023-04-11 01:18:34 +0300 1379)                   priority = RECOMMENDED;
11c606a6 (kx 2023-04-11 01:18:34 +0300 1380)                 }
11c606a6 (kx 2023-04-11 01:18:34 +0300 1381)                 else if( (m = strstr( prio, "opt" )) && m == prio ) {
11c606a6 (kx 2023-04-11 01:18:34 +0300 1382)                   priority = OPTIONAL;
11c606a6 (kx 2023-04-11 01:18:34 +0300 1383)                 }
11c606a6 (kx 2023-04-11 01:18:34 +0300 1384)                 else if( (m = strstr( prio, "sk" )) && m == prio ) {
11c606a6 (kx 2023-04-11 01:18:34 +0300 1385)                   priority = SKIP;
11c606a6 (kx 2023-04-11 01:18:34 +0300 1386)                 }
11c606a6 (kx 2023-04-11 01:18:34 +0300 1387)                 else {
11c606a6 (kx 2023-04-11 01:18:34 +0300 1388)                   priority = REQUIRED;
11c606a6 (kx 2023-04-11 01:18:34 +0300 1389)                 }
11c606a6 (kx 2023-04-11 01:18:34 +0300 1390)               }
11c606a6 (kx 2023-04-11 01:18:34 +0300 1391)               else
11c606a6 (kx 2023-04-11 01:18:34 +0300 1392)               {
11c606a6 (kx 2023-04-11 01:18:34 +0300 1393)                 priority = REQUIRED;
11c606a6 (kx 2023-04-11 01:18:34 +0300 1394)               }
11c606a6 (kx 2023-04-11 01:18:34 +0300 1395) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1396)               /* read procedure: */
11c606a6 (kx 2023-04-11 01:18:34 +0300 1397)               if( strlen( (const char*)proc ) > 5 )
11c606a6 (kx 2023-04-11 01:18:34 +0300 1398)               {
11c606a6 (kx 2023-04-11 01:18:34 +0300 1399)                 char *m = NULL;
11c606a6 (kx 2023-04-11 01:18:34 +0300 1400) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1401)                 to_lowercase( proc );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1402)                 if( (m = strstr( proc, "install" )) && m == proc ) {
11c606a6 (kx 2023-04-11 01:18:34 +0300 1403)                   procedure = INSTALL;
11c606a6 (kx 2023-04-11 01:18:34 +0300 1404)                 }
11c606a6 (kx 2023-04-11 01:18:34 +0300 1405)                 else if( (m = strstr( proc, "update" )) && m == proc ) {
11c606a6 (kx 2023-04-11 01:18:34 +0300 1406)                   procedure = UPDATE;
11c606a6 (kx 2023-04-11 01:18:34 +0300 1407)                 }
11c606a6 (kx 2023-04-11 01:18:34 +0300 1408)                 else {
11c606a6 (kx 2023-04-11 01:18:34 +0300 1409)                   procedure = INSTALL;
11c606a6 (kx 2023-04-11 01:18:34 +0300 1410)                 }
11c606a6 (kx 2023-04-11 01:18:34 +0300 1411)               }
11c606a6 (kx 2023-04-11 01:18:34 +0300 1412)               else
11c606a6 (kx 2023-04-11 01:18:34 +0300 1413)               {
11c606a6 (kx 2023-04-11 01:18:34 +0300 1414)                 procedure = INSTALL;
11c606a6 (kx 2023-04-11 01:18:34 +0300 1415)               }
11c606a6 (kx 2023-04-11 01:18:34 +0300 1416)             }
11c606a6 (kx 2023-04-11 01:18:34 +0300 1417) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1418)           } /* End if( match ) */
11c606a6 (kx 2023-04-11 01:18:34 +0300 1419) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1420)         } /* End of while( ln = fgets() ) */
11c606a6 (kx 2023-04-11 01:18:34 +0300 1421) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1422)         free( line );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1423)         fclose( pkglist );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1424) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1425)       } /* End of reading .pkglist */
11c606a6 (kx 2023-04-11 01:18:34 +0300 1426) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1427)     } /* End of attemption of reading .pkflist file */
11c606a6 (kx 2023-04-11 01:18:34 +0300 1428) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1429)     free( cmd );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1430)     free( tmp );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1431) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1432)     if( priority == SKIP )
11c606a6 (kx 2023-04-11 01:18:34 +0300 1433)     {
11c606a6 (kx 2023-04-11 01:18:34 +0300 1434)       exit_status = 41;
11c606a6 (kx 2023-04-11 01:18:34 +0300 1435) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1436)       if( install_mode != CONSOLE )
11c606a6 (kx 2023-04-11 01:18:34 +0300 1437)       {
11c606a6 (kx 2023-04-11 01:18:34 +0300 1438) #if defined( HAVE_DIALOG )
11c606a6 (kx 2023-04-11 01:18:34 +0300 1439)         char *tmp = NULL;
11c606a6 (kx 2023-04-11 01:18:34 +0300 1440) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1441)         tmp = (char *)malloc( (size_t)PATH_MAX );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1442)         if( !tmp ) { FATAL_ERROR( "Cannot allocate memory" ); }
11c606a6 (kx 2023-04-11 01:18:34 +0300 1443)         bzero( (void *)tmp, PATH_MAX );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1444) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1445)         (void)sprintf( &tmp[0],
11c606a6 (kx 2023-04-11 01:18:34 +0300 1446)                        "\nInstall procedure is skipped due to specified\nthe '%s' priority.\n",
11c606a6 (kx 2023-04-11 01:18:34 +0300 1447)                        strprio( priority, 0 ) );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1448) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1449)         info_pkg_box( "Install:", pkgname, pkgver, strprio( priority, 0 ),
11c606a6 (kx 2023-04-11 01:18:34 +0300 1450)                       (const char *)&tmp[0], 6, 0, 0 );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1451) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1452)         free( tmp );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1453) #else
11c606a6 (kx 2023-04-11 01:18:34 +0300 1454)         fprintf( stdout,
11c606a6 (kx 2023-04-11 01:18:34 +0300 1455)                  "\nInstall procedure of package '%s-%s' is skipped due to specified '%s' priority.\n\n",
11c606a6 (kx 2023-04-11 01:18:34 +0300 1456)                  pkgname, pkgver, strprio( priority, 0 ) );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1457) #endif
11c606a6 (kx 2023-04-11 01:18:34 +0300 1458)       }
11c606a6 (kx 2023-04-11 01:18:34 +0300 1459)       else
11c606a6 (kx 2023-04-11 01:18:34 +0300 1460)       {
11c606a6 (kx 2023-04-11 01:18:34 +0300 1461)         fprintf( stdout,
11c606a6 (kx 2023-04-11 01:18:34 +0300 1462)                  "\nInstall procedure of package '%s-%s' is skipped due to specified '%s' priority.\n\n",
11c606a6 (kx 2023-04-11 01:18:34 +0300 1463)                  pkgname, pkgver, strprio( priority, 0 ) );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1464)       }
11c606a6 (kx 2023-04-11 01:18:34 +0300 1465) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1466)       if( tmpdir ) { _rm_tmpdir( (const char *)tmpdir ); free( tmpdir ); }
11c606a6 (kx 2023-04-11 01:18:34 +0300 1467)       free_resources();
11c606a6 (kx 2023-04-11 01:18:34 +0300 1468) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1469)       exit( exit_status );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1470)     }
11c606a6 (kx 2023-04-11 01:18:34 +0300 1471) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1472)     if( procedure != INSTALL )
11c606a6 (kx 2023-04-11 01:18:34 +0300 1473)     {
11c606a6 (kx 2023-04-11 01:18:34 +0300 1474)       exit_status = 42;
11c606a6 (kx 2023-04-11 01:18:34 +0300 1475) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1476)       if( install_mode != CONSOLE )
11c606a6 (kx 2023-04-11 01:18:34 +0300 1477)       {
11c606a6 (kx 2023-04-11 01:18:34 +0300 1478) #if defined( HAVE_DIALOG )
11c606a6 (kx 2023-04-11 01:18:34 +0300 1479)         char *tmp = NULL;
11c606a6 (kx 2023-04-11 01:18:34 +0300 1480) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1481)         tmp = (char *)malloc( (size_t)PATH_MAX );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1482)         if( !tmp ) { FATAL_ERROR( "Cannot allocate memory" ); }
11c606a6 (kx 2023-04-11 01:18:34 +0300 1483)         bzero( (void *)tmp, PATH_MAX );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1484) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1485)         (void)sprintf( &tmp[0],
11c606a6 (kx 2023-04-11 01:18:34 +0300 1486)                        "\nInstall procedure is skipped because the '%s' procedure\nis specified.\n",
11c606a6 (kx 2023-04-11 01:18:34 +0300 1487)                        strproc( procedure ) );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1488) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1489)         info_pkg_box( "Install:", pkgname, pkgver, strprio( priority, 0 ),
11c606a6 (kx 2023-04-11 01:18:34 +0300 1490)                       (const char *)&tmp[0], 6, 0, 0 );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1491) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1492)         free( tmp );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1493) #else
11c606a6 (kx 2023-04-11 01:18:34 +0300 1494)         fprintf( stdout,
11c606a6 (kx 2023-04-11 01:18:34 +0300 1495)                  "\nInstall procedure of package '%s-%s' is skipped because the '%s' procedure is specified.\n\n",
11c606a6 (kx 2023-04-11 01:18:34 +0300 1496)                  pkgname, pkgver, strproc( procedure ) );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1497) #endif
11c606a6 (kx 2023-04-11 01:18:34 +0300 1498)       }
11c606a6 (kx 2023-04-11 01:18:34 +0300 1499)       else
11c606a6 (kx 2023-04-11 01:18:34 +0300 1500)       {
11c606a6 (kx 2023-04-11 01:18:34 +0300 1501)         fprintf( stdout,
11c606a6 (kx 2023-04-11 01:18:34 +0300 1502)                  "\nInstall procedure of package '%s-%s' is skipped because the '%s' procedure is specified.\n\n",
11c606a6 (kx 2023-04-11 01:18:34 +0300 1503)                  pkgname, pkgver, strproc( procedure ) );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1504)       }
11c606a6 (kx 2023-04-11 01:18:34 +0300 1505) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1506)       if( tmpdir ) { _rm_tmpdir( (const char *)tmpdir ); free( tmpdir ); }
11c606a6 (kx 2023-04-11 01:18:34 +0300 1507)       free_resources();
11c606a6 (kx 2023-04-11 01:18:34 +0300 1508) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1509)       exit( exit_status );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1510)     }
11c606a6 (kx 2023-04-11 01:18:34 +0300 1511) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1512)   }
11c606a6 (kx 2023-04-11 01:18:34 +0300 1513)   else
11c606a6 (kx 2023-04-11 01:18:34 +0300 1514)   {
11c606a6 (kx 2023-04-11 01:18:34 +0300 1515)     FATAL_ERROR( "Input %s file is not a regular file", basename( (char *)fname ) );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1516)   }
11c606a6 (kx 2023-04-11 01:18:34 +0300 1517) }
11c606a6 (kx 2023-04-11 01:18:34 +0300 1518) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1519) static void check_package( void )
11c606a6 (kx 2023-04-11 01:18:34 +0300 1520) {
a745159c (kx 2023-10-23 21:39:58 +0300 1521)   pid_t  p = (pid_t) -1;
a745159c (kx 2023-10-23 21:39:58 +0300 1522)   int   rc = EXIT_SUCCESS;
11c606a6 (kx 2023-04-11 01:18:34 +0300 1523) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1524)   int   len = 0;
11c606a6 (kx 2023-04-11 01:18:34 +0300 1525)   char *cmd = NULL;
11c606a6 (kx 2023-04-11 01:18:34 +0300 1526) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1527)   cmd = (char *)malloc( (size_t)PATH_MAX );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1528)   if( !cmd ) { FATAL_ERROR( "Cannot allocate memory" ); }
11c606a6 (kx 2023-04-11 01:18:34 +0300 1529)   bzero( (void *)cmd, PATH_MAX );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1530) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1531)   len = snprintf( &cmd[0], PATH_MAX,
11c606a6 (kx 2023-04-11 01:18:34 +0300 1532)                   "%s/check-package --quiet --root=%s %s > /dev/null 2>&1",
11c606a6 (kx 2023-04-11 01:18:34 +0300 1533)                   selfdir, root, pkglog_fname );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1534)   if( len == 0 || len == PATH_MAX - 1 )
11c606a6 (kx 2023-04-11 01:18:34 +0300 1535)   {
11c606a6 (kx 2023-04-11 01:18:34 +0300 1536)     FATAL_ERROR( "Cannot check whether the package '%s-%s' is already installed", pkgname, pkgver );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1537)   }
11c606a6 (kx 2023-04-11 01:18:34 +0300 1538)   p = sys_exec_command( cmd );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1539)   rc = sys_wait_command( p, (char *)NULL, PATH_MAX );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1540)   switch( rc )
11c606a6 (kx 2023-04-11 01:18:34 +0300 1541)   {
11c606a6 (kx 2023-04-11 01:18:34 +0300 1542)     case 30:
11c606a6 (kx 2023-04-11 01:18:34 +0300 1543)       /* Package is not installed. Continue the installation. */
11c606a6 (kx 2023-04-11 01:18:34 +0300 1544)       break;
11c606a6 (kx 2023-04-11 01:18:34 +0300 1545)     case 31:
11c606a6 (kx 2023-04-11 01:18:34 +0300 1546)       if( install_mode != CONSOLE )
11c606a6 (kx 2023-04-11 01:18:34 +0300 1547)       {
11c606a6 (kx 2023-04-11 01:18:34 +0300 1548) #if defined( HAVE_DIALOG )
11c606a6 (kx 2023-04-11 01:18:34 +0300 1549)         info_pkg_box( "Install:", pkgname, pkgver, strprio( priority, 0 ),
11c606a6 (kx 2023-04-11 01:18:34 +0300 1550)                       "\nPackage is already installed.\n", 5, 0, 0 );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1551) #else
11c606a6 (kx 2023-04-11 01:18:34 +0300 1552)         fprintf( stdout, "\nPackage '%s-%s' is already installed.\n\n", pkgname, pkgver );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1553) #endif
11c606a6 (kx 2023-04-11 01:18:34 +0300 1554)       }
11c606a6 (kx 2023-04-11 01:18:34 +0300 1555)       else
11c606a6 (kx 2023-04-11 01:18:34 +0300 1556)       {
11c606a6 (kx 2023-04-11 01:18:34 +0300 1557)         fprintf( stdout, "\nPackage '%s-%s' is already installed.\n\n", pkgname, pkgver );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1558)       }
11c606a6 (kx 2023-04-11 01:18:34 +0300 1559)       break;
11c606a6 (kx 2023-04-11 01:18:34 +0300 1560)     case 32:
11c606a6 (kx 2023-04-11 01:18:34 +0300 1561)       if( install_mode != CONSOLE )
11c606a6 (kx 2023-04-11 01:18:34 +0300 1562)       {
11c606a6 (kx 2023-04-11 01:18:34 +0300 1563) #if defined( HAVE_DIALOG )
11c606a6 (kx 2023-04-11 01:18:34 +0300 1564)         info_pkg_box( "Install:", pkgname, pkgver, strprio( priority, 0 ),
11c606a6 (kx 2023-04-11 01:18:34 +0300 1565)                       "\nPackage is already installed but not correct.\n", 5, 0, 0 );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1566) #else
11c606a6 (kx 2023-04-11 01:18:34 +0300 1567)         fprintf( stdout, "\nPackage '%s-%s' is already installed but not correct.\n\n", pkgname, pkgver );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1568) #endif
11c606a6 (kx 2023-04-11 01:18:34 +0300 1569)       }
11c606a6 (kx 2023-04-11 01:18:34 +0300 1570)       else
11c606a6 (kx 2023-04-11 01:18:34 +0300 1571)       {
11c606a6 (kx 2023-04-11 01:18:34 +0300 1572)         fprintf( stdout, "\nPackage '%s-%s' is already installed but not correct.\n\n", pkgname, pkgver );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1573)       }
11c606a6 (kx 2023-04-11 01:18:34 +0300 1574)       break;
11c606a6 (kx 2023-04-11 01:18:34 +0300 1575)     case 33:
11c606a6 (kx 2023-04-11 01:18:34 +0300 1576)       if( install_mode != CONSOLE )
11c606a6 (kx 2023-04-11 01:18:34 +0300 1577)       {
11c606a6 (kx 2023-04-11 01:18:34 +0300 1578) #if defined( HAVE_DIALOG )
11c606a6 (kx 2023-04-11 01:18:34 +0300 1579)         info_pkg_box( "Install:", pkgname, pkgver, strprio( priority, 0 ),
11c606a6 (kx 2023-04-11 01:18:34 +0300 1580)                       "\nPrevious version of package is installed.\n", 5, 0, 0 );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1581) #else
11c606a6 (kx 2023-04-11 01:18:34 +0300 1582)         fprintf( stdout, "\nPrevious version of package '%s-%s' is installed.\n\n", pkgname, pkgver );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1583) #endif
11c606a6 (kx 2023-04-11 01:18:34 +0300 1584)       }
11c606a6 (kx 2023-04-11 01:18:34 +0300 1585)       else
11c606a6 (kx 2023-04-11 01:18:34 +0300 1586)       {
11c606a6 (kx 2023-04-11 01:18:34 +0300 1587)         fprintf( stdout, "\nPrevious version of package '%s-%s' is installed.\n\n", pkgname, pkgver );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1588)       }
11c606a6 (kx 2023-04-11 01:18:34 +0300 1589)       break;
11c606a6 (kx 2023-04-11 01:18:34 +0300 1590)     case 34:
11c606a6 (kx 2023-04-11 01:18:34 +0300 1591)       if( install_mode != CONSOLE )
11c606a6 (kx 2023-04-11 01:18:34 +0300 1592)       {
11c606a6 (kx 2023-04-11 01:18:34 +0300 1593) #if defined( HAVE_DIALOG )
11c606a6 (kx 2023-04-11 01:18:34 +0300 1594)         info_pkg_box( "Install:", pkgname, pkgver, strprio( priority, 0 ),
11c606a6 (kx 2023-04-11 01:18:34 +0300 1595)                       "\nPrevious version of package is installed but not correct.\n", 5, 0, 0 );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1596) #else
11c606a6 (kx 2023-04-11 01:18:34 +0300 1597)         fprintf( stdout, "\nPrevious version of package '%s-%s' is installed but not correct.\n\n", pkgname, pkgver );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1598) #endif
11c606a6 (kx 2023-04-11 01:18:34 +0300 1599)       }
11c606a6 (kx 2023-04-11 01:18:34 +0300 1600)       else
11c606a6 (kx 2023-04-11 01:18:34 +0300 1601)       {
11c606a6 (kx 2023-04-11 01:18:34 +0300 1602)         fprintf( stdout, "\nPrevious version of package '%s-%s' is installed but not correct.\n\n", pkgname, pkgver );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1603)       }
11c606a6 (kx 2023-04-11 01:18:34 +0300 1604)       break;
11c606a6 (kx 2023-04-11 01:18:34 +0300 1605)     case 35:
11c606a6 (kx 2023-04-11 01:18:34 +0300 1606)       if( install_mode != CONSOLE )
11c606a6 (kx 2023-04-11 01:18:34 +0300 1607)       {
11c606a6 (kx 2023-04-11 01:18:34 +0300 1608) #if defined( HAVE_DIALOG )
11c606a6 (kx 2023-04-11 01:18:34 +0300 1609)         info_pkg_box( "Install:", pkgname, pkgver, strprio( priority, 0 ),
11c606a6 (kx 2023-04-11 01:18:34 +0300 1610)                       "\nA newer version of package is already installed.\n", 5, 0, 0 );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1611) #else
11c606a6 (kx 2023-04-11 01:18:34 +0300 1612)         fprintf( stdout, "\nA newer version of package '%s-%s' is already installed.\n\n", pkgname, pkgver );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1613) #endif
11c606a6 (kx 2023-04-11 01:18:34 +0300 1614)       }
11c606a6 (kx 2023-04-11 01:18:34 +0300 1615)       else
11c606a6 (kx 2023-04-11 01:18:34 +0300 1616)       {
11c606a6 (kx 2023-04-11 01:18:34 +0300 1617)         fprintf( stdout, "\nA newer version of package '%s-%s' is already installed.\n\n", pkgname, pkgver );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1618)       }
11c606a6 (kx 2023-04-11 01:18:34 +0300 1619)       break;
11c606a6 (kx 2023-04-11 01:18:34 +0300 1620)     case 36:
11c606a6 (kx 2023-04-11 01:18:34 +0300 1621)       if( install_mode != CONSOLE )
11c606a6 (kx 2023-04-11 01:18:34 +0300 1622)       {
11c606a6 (kx 2023-04-11 01:18:34 +0300 1623) #if defined( HAVE_DIALOG )
11c606a6 (kx 2023-04-11 01:18:34 +0300 1624)         info_pkg_box( "Install:", pkgname, pkgver, strprio( priority, 0 ),
11c606a6 (kx 2023-04-11 01:18:34 +0300 1625)                       "\nA newer version of package is installed but not correct.\n", 5, 0, 0 );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1626) #else
11c606a6 (kx 2023-04-11 01:18:34 +0300 1627)         fprintf( stdout, "\nA newer version of package '%s-%s' is installed but not correct.\n\n", pkgname, pkgver );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1628) #endif
11c606a6 (kx 2023-04-11 01:18:34 +0300 1629)       }
11c606a6 (kx 2023-04-11 01:18:34 +0300 1630)       else
11c606a6 (kx 2023-04-11 01:18:34 +0300 1631)       {
11c606a6 (kx 2023-04-11 01:18:34 +0300 1632)         fprintf( stdout, "\nA newer version of package '%s-%s' is installed but not correct.\n\n", pkgname, pkgver );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1633)       }
11c606a6 (kx 2023-04-11 01:18:34 +0300 1634)       break;
11c606a6 (kx 2023-04-11 01:18:34 +0300 1635)     default:
11c606a6 (kx 2023-04-11 01:18:34 +0300 1636)       FATAL_ERROR( "Cannot check whether the package '%s-%s' is already installed", pkgname, pkgver );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1637)       break;
11c606a6 (kx 2023-04-11 01:18:34 +0300 1638)   }
11c606a6 (kx 2023-04-11 01:18:34 +0300 1639) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1640)   free( cmd );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1641) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1642)   if( rc != 30 )
11c606a6 (kx 2023-04-11 01:18:34 +0300 1643)   {
11c606a6 (kx 2023-04-11 01:18:34 +0300 1644)     if( tmpdir ) { _rm_tmpdir( (const char *)tmpdir ); free( tmpdir ); }
11c606a6 (kx 2023-04-11 01:18:34 +0300 1645)     free_resources();
11c606a6 (kx 2023-04-11 01:18:34 +0300 1646)     exit( rc );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1647)   }
11c606a6 (kx 2023-04-11 01:18:34 +0300 1648) }
11c606a6 (kx 2023-04-11 01:18:34 +0300 1649) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1650) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1651) static void check_requires( void )
11c606a6 (kx 2023-04-11 01:18:34 +0300 1652) {
11c606a6 (kx 2023-04-11 01:18:34 +0300 1653)   pid_t p = (pid_t) -1;
11c606a6 (kx 2023-04-11 01:18:34 +0300 1654)   int   rc;
11c606a6 (kx 2023-04-11 01:18:34 +0300 1655) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1656)   int   len = 0;
11c606a6 (kx 2023-04-11 01:18:34 +0300 1657)   char *cmd = NULL;
11c606a6 (kx 2023-04-11 01:18:34 +0300 1658) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1659)   cmd = (char *)malloc( (size_t)PATH_MAX );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1660)   if( !cmd ) { FATAL_ERROR( "Cannot allocate memory" ); }
11c606a6 (kx 2023-04-11 01:18:34 +0300 1661)   bzero( (void *)cmd, PATH_MAX );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1662) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1663)   len = snprintf( &cmd[0], PATH_MAX,
11c606a6 (kx 2023-04-11 01:18:34 +0300 1664)                   "%s/check-requires --root=%s %s > /dev/null 2>&1",
11c606a6 (kx 2023-04-11 01:18:34 +0300 1665)                   selfdir, root, pkglog_fname );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1666)   if( len == 0 || len == PATH_MAX - 1 )
11c606a6 (kx 2023-04-11 01:18:34 +0300 1667)   {
11c606a6 (kx 2023-04-11 01:18:34 +0300 1668)     FATAL_ERROR( "Cannot check required packages for '%s-%s' package", pkgname, pkgver );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1669)   }
11c606a6 (kx 2023-04-11 01:18:34 +0300 1670)   p = sys_exec_command( cmd );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1671)   rc = sys_wait_command( p, (char *)NULL, PATH_MAX );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1672) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1673)   free( cmd );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1674) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1675)   if( rc != 0 )
11c606a6 (kx 2023-04-11 01:18:34 +0300 1676)   {
11c606a6 (kx 2023-04-11 01:18:34 +0300 1677)     if( install_mode != CONSOLE )
11c606a6 (kx 2023-04-11 01:18:34 +0300 1678)     {
11c606a6 (kx 2023-04-11 01:18:34 +0300 1679) #if defined( HAVE_DIALOG )
11c606a6 (kx 2023-04-11 01:18:34 +0300 1680)       info_pkg_box( "Install:", pkgname, pkgver, strprio( priority, 0 ),
11c606a6 (kx 2023-04-11 01:18:34 +0300 1681)                     "\nPackage requires other packages to be installed.\n", 5, 0, 0 );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1682) #else
11c606a6 (kx 2023-04-11 01:18:34 +0300 1683)       fprintf( stdout, "\nPackage '%s-%s' requires other packages to be installed.\n\n", pkgname, pkgver );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1684) #endif
11c606a6 (kx 2023-04-11 01:18:34 +0300 1685)     }
11c606a6 (kx 2023-04-11 01:18:34 +0300 1686)     else
11c606a6 (kx 2023-04-11 01:18:34 +0300 1687)     {
11c606a6 (kx 2023-04-11 01:18:34 +0300 1688)       fprintf( stdout, "\nPackage '%s-%s' requires other packages to be installed.\n\n", pkgname, pkgver );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1689)     }
11c606a6 (kx 2023-04-11 01:18:34 +0300 1690) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1691)     if( tmpdir ) { _rm_tmpdir( (const char *)tmpdir ); free( tmpdir ); }
11c606a6 (kx 2023-04-11 01:18:34 +0300 1692)     free_resources();
11c606a6 (kx 2023-04-11 01:18:34 +0300 1693)     exit( rc );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1694)   }
11c606a6 (kx 2023-04-11 01:18:34 +0300 1695) }
11c606a6 (kx 2023-04-11 01:18:34 +0300 1696) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1697) /********************************************************
11c606a6 (kx 2023-04-11 01:18:34 +0300 1698)   Read .FILELIST and .RESTORELINKS functions used for
11c606a6 (kx 2023-04-11 01:18:34 +0300 1699)   roolback in case postinstall errors:
11c606a6 (kx 2023-04-11 01:18:34 +0300 1700)  */
11c606a6 (kx 2023-04-11 01:18:34 +0300 1701) static int __cmp_list_items( const void *a, const void *b )
11c606a6 (kx 2023-04-11 01:18:34 +0300 1702) {
11c606a6 (kx 2023-04-11 01:18:34 +0300 1703)   if( a && b )
11c606a6 (kx 2023-04-11 01:18:34 +0300 1704)     return strcmp( (const char *)a, (const char *)b );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1705)   else if( a )
11c606a6 (kx 2023-04-11 01:18:34 +0300 1706)     return 1;
11c606a6 (kx 2023-04-11 01:18:34 +0300 1707)   else
11c606a6 (kx 2023-04-11 01:18:34 +0300 1708)     return -1;
11c606a6 (kx 2023-04-11 01:18:34 +0300 1709) }
11c606a6 (kx 2023-04-11 01:18:34 +0300 1710) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1711) static void __free_list( void *data, void *user_data )
11c606a6 (kx 2023-04-11 01:18:34 +0300 1712) {
11c606a6 (kx 2023-04-11 01:18:34 +0300 1713)   if( data ) { free( data ); }
11c606a6 (kx 2023-04-11 01:18:34 +0300 1714) }
11c606a6 (kx 2023-04-11 01:18:34 +0300 1715) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1716) static void free_list( struct dlist *list )
11c606a6 (kx 2023-04-11 01:18:34 +0300 1717) {
11c606a6 (kx 2023-04-11 01:18:34 +0300 1718)   if( list ) { dlist_free( list, __free_list ); }
11c606a6 (kx 2023-04-11 01:18:34 +0300 1719) }
11c606a6 (kx 2023-04-11 01:18:34 +0300 1720) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1721) ////////////////////////////////////////////////////
11c606a6 (kx 2023-04-11 01:18:34 +0300 1722) //static void __print_list( void *data, void *user_data )
11c606a6 (kx 2023-04-11 01:18:34 +0300 1723) //{
11c606a6 (kx 2023-04-11 01:18:34 +0300 1724) //  int *counter = (int *)user_data;
11c606a6 (kx 2023-04-11 01:18:34 +0300 1725) //
11c606a6 (kx 2023-04-11 01:18:34 +0300 1726) //  if( counter ) { fprintf( stdout, "item[%.5d]: %s\n", *counter, (char *)data ); ++(*counter); }
11c606a6 (kx 2023-04-11 01:18:34 +0300 1727) //  else          { fprintf( stdout, "item: %s\n", (char *)data ); }
11c606a6 (kx 2023-04-11 01:18:34 +0300 1728) //}
11c606a6 (kx 2023-04-11 01:18:34 +0300 1729) //
11c606a6 (kx 2023-04-11 01:18:34 +0300 1730) //static void print_list( struct dlist *list )
11c606a6 (kx 2023-04-11 01:18:34 +0300 1731) //{
11c606a6 (kx 2023-04-11 01:18:34 +0300 1732) //  int cnt = 0;
11c606a6 (kx 2023-04-11 01:18:34 +0300 1733) //  if( list ) { dlist_foreach( list, __print_list, (void *)&cnt ); }
11c606a6 (kx 2023-04-11 01:18:34 +0300 1734) //}
11c606a6 (kx 2023-04-11 01:18:34 +0300 1735) ////////////////////////////////////////////////////
11c606a6 (kx 2023-04-11 01:18:34 +0300 1736) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1737) static void read_filelist( void )
11c606a6 (kx 2023-04-11 01:18:34 +0300 1738) {
11c606a6 (kx 2023-04-11 01:18:34 +0300 1739)   struct stat st;
11c606a6 (kx 2023-04-11 01:18:34 +0300 1740)   FILE  *fp = NULL;
11c606a6 (kx 2023-04-11 01:18:34 +0300 1741) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1742)   char *ln   = NULL;
11c606a6 (kx 2023-04-11 01:18:34 +0300 1743)   char *line = NULL, *tmp = NULL;
11c606a6 (kx 2023-04-11 01:18:34 +0300 1744) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1745)   tmp = (char *)malloc( (size_t)PATH_MAX );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1746)   if( !tmp ) { FATAL_ERROR( "Cannot allocate memory" ); }
11c606a6 (kx 2023-04-11 01:18:34 +0300 1747)   bzero( (void *)tmp, PATH_MAX );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1748) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1749)   (void)sprintf( &tmp[0], "%s/.FILELIST", tmpdir );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1750)   bzero( (void *)&st, sizeof( struct stat ) );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1751)   if( (stat( (const char *)&tmp[0], &st ) == -1) )
11c606a6 (kx 2023-04-11 01:18:34 +0300 1752)   {
11c606a6 (kx 2023-04-11 01:18:34 +0300 1753)     FATAL_ERROR( "Cannot get .FILELIST from '%s' file", basename( (char *)pkg_fname ) );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1754)   }
11c606a6 (kx 2023-04-11 01:18:34 +0300 1755) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1756)   fp = fopen( (const char *)&tmp[0], "r" );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1757)   if( !fp )
11c606a6 (kx 2023-04-11 01:18:34 +0300 1758)   {
11c606a6 (kx 2023-04-11 01:18:34 +0300 1759)     FATAL_ERROR( "Cannot open .FILELIST file" );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1760)   }
11c606a6 (kx 2023-04-11 01:18:34 +0300 1761) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1762)   line = (char *)malloc( (size_t)PATH_MAX );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1763)   if( !line ) { FATAL_ERROR( "Cannot allocate memory" ); }
11c606a6 (kx 2023-04-11 01:18:34 +0300 1764)   bzero( (void *)line, PATH_MAX );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1765) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1766)   while( (ln = fgets( line, PATH_MAX, fp )) )
11c606a6 (kx 2023-04-11 01:18:34 +0300 1767)   {
11c606a6 (kx 2023-04-11 01:18:34 +0300 1768)     ln[strlen(ln) - 1] = '\0'; /* replace new-line symbol      */
11c606a6 (kx 2023-04-11 01:18:34 +0300 1769)     skip_eol_spaces( ln );     /* remove spaces at end-of-line */
11c606a6 (kx 2023-04-11 01:18:34 +0300 1770) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1771)     if( *(ln + strlen(ln) - 1) == '/' )
11c606a6 (kx 2023-04-11 01:18:34 +0300 1772)     {
11c606a6 (kx 2023-04-11 01:18:34 +0300 1773)       *(ln + strlen(ln) - 1) = '\0';
11c606a6 (kx 2023-04-11 01:18:34 +0300 1774)       (void)sprintf( &tmp[0], "%s%s", (const char *)root, (const char *)ln );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1775)       dirs = dlist_append( dirs, xstrdup( (const char *)&tmp[0] ) );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1776)     }
11c606a6 (kx 2023-04-11 01:18:34 +0300 1777)     else
11c606a6 (kx 2023-04-11 01:18:34 +0300 1778)     {
11c606a6 (kx 2023-04-11 01:18:34 +0300 1779)       (void)sprintf( &tmp[0], "%s%s", (const char *)root, (const char *)ln );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1780)       files = dlist_append( files, xstrdup( (const char *)&tmp[0] ) );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1781)     }
11c606a6 (kx 2023-04-11 01:18:34 +0300 1782) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1783)   } /* End of while( file list entry ) */
11c606a6 (kx 2023-04-11 01:18:34 +0300 1784) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1785)   fclose( fp );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1786) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1787)   free( line );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1788)   free( tmp );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1789) }
11c606a6 (kx 2023-04-11 01:18:34 +0300 1790) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1791) static void read_restorelinks( void )
11c606a6 (kx 2023-04-11 01:18:34 +0300 1792) {
11c606a6 (kx 2023-04-11 01:18:34 +0300 1793)   struct stat st;
11c606a6 (kx 2023-04-11 01:18:34 +0300 1794)   FILE  *fp = NULL;
11c606a6 (kx 2023-04-11 01:18:34 +0300 1795) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1796)   char *ln   = NULL;
11c606a6 (kx 2023-04-11 01:18:34 +0300 1797)   char *line = NULL, *tmp = NULL;
11c606a6 (kx 2023-04-11 01:18:34 +0300 1798) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1799)   tmp = (char *)malloc( (size_t)PATH_MAX );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1800)   if( !tmp ) { FATAL_ERROR( "Cannot allocate memory" ); }
11c606a6 (kx 2023-04-11 01:18:34 +0300 1801)   bzero( (void *)tmp, PATH_MAX );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1802) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1803)   (void)sprintf( &tmp[0], "%s/.RESTORELINKS", tmpdir );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1804)   bzero( (void *)&st, sizeof( struct stat ) );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1805)   if( (stat( (const char *)&tmp[0], &st ) == -1) || (st.st_size < 8) )
11c606a6 (kx 2023-04-11 01:18:34 +0300 1806)   {
11c606a6 (kx 2023-04-11 01:18:34 +0300 1807)     free( tmp );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1808)     return;
11c606a6 (kx 2023-04-11 01:18:34 +0300 1809)   }
11c606a6 (kx 2023-04-11 01:18:34 +0300 1810) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1811)   fp = fopen( (const char *)&tmp[0], "r" );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1812)   if( !fp )
11c606a6 (kx 2023-04-11 01:18:34 +0300 1813)   {
11c606a6 (kx 2023-04-11 01:18:34 +0300 1814)     FATAL_ERROR( "Cannot open .RESTORELINKS file" );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1815)   }
11c606a6 (kx 2023-04-11 01:18:34 +0300 1816) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1817)   line = (char *)malloc( (size_t)PATH_MAX );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1818)   if( !line ) { FATAL_ERROR( "Cannot allocate memory" ); }
11c606a6 (kx 2023-04-11 01:18:34 +0300 1819)   bzero( (void *)line, PATH_MAX );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1820) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1821)   while( (ln = fgets( line, PATH_MAX, fp )) )
11c606a6 (kx 2023-04-11 01:18:34 +0300 1822)   {
11c606a6 (kx 2023-04-11 01:18:34 +0300 1823)     char *match = NULL;
11c606a6 (kx 2023-04-11 01:18:34 +0300 1824) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1825)     ln[strlen(ln) - 1] = '\0'; /* replace new-line symbol      */
11c606a6 (kx 2023-04-11 01:18:34 +0300 1826)     skip_eol_spaces( ln );     /* remove spaces at end-of-line */
11c606a6 (kx 2023-04-11 01:18:34 +0300 1827) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1828)     if( (match = strstr( ln, "; rm -rf " )) )
11c606a6 (kx 2023-04-11 01:18:34 +0300 1829)     {
11c606a6 (kx 2023-04-11 01:18:34 +0300 1830)       char *q = NULL;
11c606a6 (kx 2023-04-11 01:18:34 +0300 1831)       char *p = strstr( ln, "cd" ) + 2;
11c606a6 (kx 2023-04-11 01:18:34 +0300 1832)       char *f = strstr( ln, "; rm -rf" ) + 8;
11c606a6 (kx 2023-04-11 01:18:34 +0300 1833) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1834)       if( !p || !f ) continue;
11c606a6 (kx 2023-04-11 01:18:34 +0300 1835) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1836)       while( (*p == ' ' || *p == '\t') && *p != '\0' ) ++p;
11c606a6 (kx 2023-04-11 01:18:34 +0300 1837)       while( (*f == ' ' || *f == '\t') && *f != '\0' ) ++f;
11c606a6 (kx 2023-04-11 01:18:34 +0300 1838) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1839)       q = p; while( *q != ' ' && *q != '\t' && *q != ';' && *q != '\0' ) ++q; *q = '\0';
11c606a6 (kx 2023-04-11 01:18:34 +0300 1840)       q = f; while( *q != ' ' && *q != '\t' && *q != ';' && *q != '\0' ) ++q; *q = '\0';
11c606a6 (kx 2023-04-11 01:18:34 +0300 1841) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1842)       if( p && f )
11c606a6 (kx 2023-04-11 01:18:34 +0300 1843)       {
11c606a6 (kx 2023-04-11 01:18:34 +0300 1844)         (void)sprintf( &tmp[0], "%s%s/%s", (const char *)root, p, f );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1845)         links = dlist_append( links, xstrdup( (const char *)&tmp[0] ) );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1846)       }
11c606a6 (kx 2023-04-11 01:18:34 +0300 1847)     }
11c606a6 (kx 2023-04-11 01:18:34 +0300 1848)   } /* End of while( restore links entry ) */
11c606a6 (kx 2023-04-11 01:18:34 +0300 1849) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1850)   fclose( fp );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1851) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1852)   free( line );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1853)   free( tmp );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1854) }
11c606a6 (kx 2023-04-11 01:18:34 +0300 1855) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1856) /*
11c606a6 (kx 2023-04-11 01:18:34 +0300 1857)   End of read .FILELIST and .RESTORELINKS functions.
11c606a6 (kx 2023-04-11 01:18:34 +0300 1858)  ********************************************************/
11c606a6 (kx 2023-04-11 01:18:34 +0300 1859) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1860) /********************************************************
11c606a6 (kx 2023-04-11 01:18:34 +0300 1861)   Rollback functions:
11c606a6 (kx 2023-04-11 01:18:34 +0300 1862)  */
11c606a6 (kx 2023-04-11 01:18:34 +0300 1863) static void __remove_link( void *data, void *user_data )
11c606a6 (kx 2023-04-11 01:18:34 +0300 1864) {
11c606a6 (kx 2023-04-11 01:18:34 +0300 1865)   const char *fname = (const char *)data;
11c606a6 (kx 2023-04-11 01:18:34 +0300 1866) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1867)   if( fname )
11c606a6 (kx 2023-04-11 01:18:34 +0300 1868)   {
11c606a6 (kx 2023-04-11 01:18:34 +0300 1869)     (void)unlink( fname );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1870)   }
11c606a6 (kx 2023-04-11 01:18:34 +0300 1871) }
11c606a6 (kx 2023-04-11 01:18:34 +0300 1872) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1873) static void __remove_file( void *data, void *user_data )
11c606a6 (kx 2023-04-11 01:18:34 +0300 1874) {
11c606a6 (kx 2023-04-11 01:18:34 +0300 1875)   const char *fname = (const char *)data;
11c606a6 (kx 2023-04-11 01:18:34 +0300 1876) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1877)   if( fname )
11c606a6 (kx 2023-04-11 01:18:34 +0300 1878)   {
11c606a6 (kx 2023-04-11 01:18:34 +0300 1879)     char *p = rindex( fname, '.' );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1880)     /*
11c606a6 (kx 2023-04-11 01:18:34 +0300 1881)       Если .new файл остался с тем же именем, это значит что до инсталляции
11c606a6 (kx 2023-04-11 01:18:34 +0300 1882)       в системе существовал такой же файл но без расширения .new и при этом
11c606a6 (kx 2023-04-11 01:18:34 +0300 1883)       он отличался от нового. В данном случае надо удалять только файл .new.
11c606a6 (kx 2023-04-11 01:18:34 +0300 1884) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1885)       Если же файл .new не существует, то надо удалять такой же файл но без
11c606a6 (kx 2023-04-11 01:18:34 +0300 1886)       расширения .new .
11c606a6 (kx 2023-04-11 01:18:34 +0300 1887)      */
11c606a6 (kx 2023-04-11 01:18:34 +0300 1888)     if( p && !strncmp( (const char *)p, ".new", 4 ) )
11c606a6 (kx 2023-04-11 01:18:34 +0300 1889)     {
11c606a6 (kx 2023-04-11 01:18:34 +0300 1890)       struct stat st;
11c606a6 (kx 2023-04-11 01:18:34 +0300 1891) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1892)       bzero( (void *)&st, sizeof( struct stat ) );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1893)       if( (stat( fname, &st ) == -1) ) *p = '\0';
11c606a6 (kx 2023-04-11 01:18:34 +0300 1894)     }
11c606a6 (kx 2023-04-11 01:18:34 +0300 1895) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1896)     (void)unlink( fname );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1897)   }
11c606a6 (kx 2023-04-11 01:18:34 +0300 1898) }
11c606a6 (kx 2023-04-11 01:18:34 +0300 1899) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1900) static int is_dir_empty( const char *dirpath )
11c606a6 (kx 2023-04-11 01:18:34 +0300 1901) {
11c606a6 (kx 2023-04-11 01:18:34 +0300 1902)   int ret = 0;
11c606a6 (kx 2023-04-11 01:18:34 +0300 1903) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1904)   DIR    *dir;
11c606a6 (kx 2023-04-11 01:18:34 +0300 1905)   char   *path;
11c606a6 (kx 2023-04-11 01:18:34 +0300 1906)   size_t  len;
11c606a6 (kx 2023-04-11 01:18:34 +0300 1907) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1908)   struct stat    path_sb, entry_sb;
11c606a6 (kx 2023-04-11 01:18:34 +0300 1909)   struct dirent *entry;
11c606a6 (kx 2023-04-11 01:18:34 +0300 1910) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1911)   if( stat( dirpath, &path_sb ) == -1 )   return ret; /* stat returns error code; errno is set */
11c606a6 (kx 2023-04-11 01:18:34 +0300 1912)   if( S_ISDIR(path_sb.st_mode) == 0 )     return ret; /* dirpath is not a directory */
11c606a6 (kx 2023-04-11 01:18:34 +0300 1913)   if( (dir = opendir(dirpath) ) == NULL ) return ret; /* Cannot open direcroty; errno is set */
11c606a6 (kx 2023-04-11 01:18:34 +0300 1914) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1915)   ret = 1;
11c606a6 (kx 2023-04-11 01:18:34 +0300 1916) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1917)   len = strlen( dirpath );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1918)   while( (entry = readdir( dir )) != NULL)
11c606a6 (kx 2023-04-11 01:18:34 +0300 1919)   {
11c606a6 (kx 2023-04-11 01:18:34 +0300 1920)     /* skip entries '.' and '..' */
11c606a6 (kx 2023-04-11 01:18:34 +0300 1921)     if( ! strcmp( entry->d_name, "." ) || ! strcmp( entry->d_name, ".." ) ) continue;
11c606a6 (kx 2023-04-11 01:18:34 +0300 1922) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1923)     /* determinate a full name of an entry */
11c606a6 (kx 2023-04-11 01:18:34 +0300 1924)     path = alloca( len + strlen( entry->d_name ) + 2 );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1925)     strcpy( path, dirpath );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1926)     strcat( path, "/" );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1927)     strcat( path, entry->d_name );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1928) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1929)     if( stat( path, &entry_sb ) == 0 )
11c606a6 (kx 2023-04-11 01:18:34 +0300 1930)     {
11c606a6 (kx 2023-04-11 01:18:34 +0300 1931)       ret = 0;
11c606a6 (kx 2023-04-11 01:18:34 +0300 1932)       break;
11c606a6 (kx 2023-04-11 01:18:34 +0300 1933)     }
11c606a6 (kx 2023-04-11 01:18:34 +0300 1934)     /* else { stat() returns error code; errno is set; and we have to continue the loop } */
11c606a6 (kx 2023-04-11 01:18:34 +0300 1935)   }
11c606a6 (kx 2023-04-11 01:18:34 +0300 1936)   closedir( dir );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1937) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1938)   return ret;
11c606a6 (kx 2023-04-11 01:18:34 +0300 1939) }
11c606a6 (kx 2023-04-11 01:18:34 +0300 1940) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1941) static void __remove_dir( void *data, void *user_data )
11c606a6 (kx 2023-04-11 01:18:34 +0300 1942) {
11c606a6 (kx 2023-04-11 01:18:34 +0300 1943)   const char *dname = (const char *)data;
11c606a6 (kx 2023-04-11 01:18:34 +0300 1944) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1945)   if( dname && is_dir_empty( (const char *)dname ) )
11c606a6 (kx 2023-04-11 01:18:34 +0300 1946)   {
11c606a6 (kx 2023-04-11 01:18:34 +0300 1947)     (void)rmdir( dname );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1948)   }
11c606a6 (kx 2023-04-11 01:18:34 +0300 1949) }
11c606a6 (kx 2023-04-11 01:18:34 +0300 1950) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1951) static void rollback( void )
11c606a6 (kx 2023-04-11 01:18:34 +0300 1952) {
11c606a6 (kx 2023-04-11 01:18:34 +0300 1953)   /* Try to change CWD to the ROOT directory: */
11c606a6 (kx 2023-04-11 01:18:34 +0300 1954)   (void)chdir( (const char *)root );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1955) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1956)   if( links ) { dlist_foreach( links, __remove_link, NULL ); }
11c606a6 (kx 2023-04-11 01:18:34 +0300 1957) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1958)   if( files ) { dlist_foreach( files, __remove_file, NULL ); }
11c606a6 (kx 2023-04-11 01:18:34 +0300 1959) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1960)   if( dirs )
11c606a6 (kx 2023-04-11 01:18:34 +0300 1961)   {
11c606a6 (kx 2023-04-11 01:18:34 +0300 1962)     dirs = dlist_sort( dirs, __cmp_list_items );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1963)     dirs = dlist_reverse( dirs );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1964)     dlist_foreach( dirs, __remove_dir, NULL );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1965)   }
11c606a6 (kx 2023-04-11 01:18:34 +0300 1966) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1967)   /* Try to remove PKGLOG file */
11c606a6 (kx 2023-04-11 01:18:34 +0300 1968)   {
11c606a6 (kx 2023-04-11 01:18:34 +0300 1969)     char *tmp = NULL;
11c606a6 (kx 2023-04-11 01:18:34 +0300 1970) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1971)     tmp = (char *)malloc( PATH_MAX );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1972)     if( tmp )
11c606a6 (kx 2023-04-11 01:18:34 +0300 1973)     {
11c606a6 (kx 2023-04-11 01:18:34 +0300 1974)       const char *fname = basename( (char *)pkglog_fname );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1975) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1976)       bzero( (void *)tmp, PATH_MAX );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1977) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1978)       if( group )
11c606a6 (kx 2023-04-11 01:18:34 +0300 1979)         (void)sprintf( &tmp[0], "%s/%s/%s", pkgs_path, group, fname );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1980)       else
11c606a6 (kx 2023-04-11 01:18:34 +0300 1981)         (void)sprintf( &tmp[0], "%s/%s", pkgs_path, fname );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1982) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1983)       (void)unlink( (const char *)&tmp[0] );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1984) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1985)       if( group )
11c606a6 (kx 2023-04-11 01:18:34 +0300 1986)       {
11c606a6 (kx 2023-04-11 01:18:34 +0300 1987)         const char *dir = (const char *)dirname( (char *)&tmp[0] );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1988)         if( is_dir_empty( dir ) )
11c606a6 (kx 2023-04-11 01:18:34 +0300 1989)         {
11c606a6 (kx 2023-04-11 01:18:34 +0300 1990)           (void)rmdir( dir );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1991)         }
11c606a6 (kx 2023-04-11 01:18:34 +0300 1992)       }
11c606a6 (kx 2023-04-11 01:18:34 +0300 1993)       free( tmp );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1994)     }
11c606a6 (kx 2023-04-11 01:18:34 +0300 1995)   }
11c606a6 (kx 2023-04-11 01:18:34 +0300 1996) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1997)   /* Try to change CWD to the CURRENT directory: */
11c606a6 (kx 2023-04-11 01:18:34 +0300 1998)   (void)chdir( (const char *)curdir );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1999) }
11c606a6 (kx 2023-04-11 01:18:34 +0300 2000) /*
11c606a6 (kx 2023-04-11 01:18:34 +0300 2001)   End of rollback functions.
11c606a6 (kx 2023-04-11 01:18:34 +0300 2002)  ********************************************************/
11c606a6 (kx 2023-04-11 01:18:34 +0300 2003) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 2004) static void read_description( void )
11c606a6 (kx 2023-04-11 01:18:34 +0300 2005) {
11c606a6 (kx 2023-04-11 01:18:34 +0300 2006)   struct stat st;
11c606a6 (kx 2023-04-11 01:18:34 +0300 2007)   FILE  *fp = NULL;
11c606a6 (kx 2023-04-11 01:18:34 +0300 2008) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 2009)   char  *buf = NULL, *tmp = NULL;
11c606a6 (kx 2023-04-11 01:18:34 +0300 2010)   char  *lp  = NULL;
11c606a6 (kx 2023-04-11 01:18:34 +0300 2011)   int    n   = 0;
11c606a6 (kx 2023-04-11 01:18:34 +0300 2012) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 2013)   char *ln   = NULL;
11c606a6 (kx 2023-04-11 01:18:34 +0300 2014)   char *line = NULL;
11c606a6 (kx 2023-04-11 01:18:34 +0300 2015) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 2016)   tmp = (char *)malloc( (size_t)PATH_MAX );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2017)   if( !tmp ) { FATAL_ERROR( "Cannot allocate memory" ); }
11c606a6 (kx 2023-04-11 01:18:34 +0300 2018)   bzero( (void *)tmp, PATH_MAX );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2019) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 2020)   buf = (char *)malloc( (size_t)PATH_MAX );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2021)   if( !buf ) { FATAL_ERROR( "Cannot allocate memory" ); }
11c606a6 (kx 2023-04-11 01:18:34 +0300 2022)   bzero( (void *)buf, PATH_MAX );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2023) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 2024)   (void)sprintf( &tmp[0], "%s/.DESCRIPTION", tmpdir );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2025)   bzero( (void *)&st, sizeof( struct stat ) );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2026)   if( (stat( (const char *)&tmp[0], &st ) == -1) || (st.st_size < 8) )
11c606a6 (kx 2023-04-11 01:18:34 +0300 2027)   {
11c606a6 (kx 2023-04-11 01:18:34 +0300 2028)     free( tmp );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2029)     return;
11c606a6 (kx 2023-04-11 01:18:34 +0300 2030)   }
11c606a6 (kx 2023-04-11 01:18:34 +0300 2031) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 2032)   fp = fopen( (const char *)&tmp[0], "r" );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2033)   if( !fp )
11c606a6 (kx 2023-04-11 01:18:34 +0300 2034)   {
11c606a6 (kx 2023-04-11 01:18:34 +0300 2035)     FATAL_ERROR( "Cannot open .DESCRIPTION file" );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2036)   }
11c606a6 (kx 2023-04-11 01:18:34 +0300 2037) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 2038)   (void)sprintf( (char *)&buf[0], "%s:", pkgname );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2039) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 2040)   line = (char *)malloc( (size_t)PATH_MAX );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2041)   if( !line ) { FATAL_ERROR( "Cannot allocate memory" ); }
11c606a6 (kx 2023-04-11 01:18:34 +0300 2042)   bzero( (void *)line, PATH_MAX );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2043) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 2044)   lp = (char *)&tmp[0];
11c606a6 (kx 2023-04-11 01:18:34 +0300 2045)   bzero( (void *)tmp, PATH_MAX );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2046)   (void)sprintf( (char *)&tmp[0], "\n" );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2047)   ++lp;
11c606a6 (kx 2023-04-11 01:18:34 +0300 2048) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 2049)   while( (ln = fgets( line, PATH_MAX, fp )) && n < DESCRIPTION_NUMBER_OF_LINES )
11c606a6 (kx 2023-04-11 01:18:34 +0300 2050)   {
11c606a6 (kx 2023-04-11 01:18:34 +0300 2051)     char *match = NULL;
11c606a6 (kx 2023-04-11 01:18:34 +0300 2052) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 2053)     ln[strlen(ln) - 1] = '\0'; /* replace new-line symbol */
11c606a6 (kx 2023-04-11 01:18:34 +0300 2054) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 2055)     if( (match = strstr( (const char *)ln, (const char *)buf )) && match == ln ) /* at start of line only */
11c606a6 (kx 2023-04-11 01:18:34 +0300 2056)     {
11c606a6 (kx 2023-04-11 01:18:34 +0300 2057)       int mlen   = strlen( match ), plen = strlen( buf );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2058)       int length = ( mlen > plen )  ? (mlen - plen - 1) : 0 ;
11c606a6 (kx 2023-04-11 01:18:34 +0300 2059) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 2060)       if( length > DESCRIPTION_LENGTH_OF_LINE )
11c606a6 (kx 2023-04-11 01:18:34 +0300 2061)       {
11c606a6 (kx 2023-04-11 01:18:34 +0300 2062)         /* WARNING( "Package DESCRIPTION contains lines with length greater than %d characters", DESCRIPTION_LENGTH_OF_LINE ); */
11c606a6 (kx 2023-04-11 01:18:34 +0300 2063)         match[plen + 1 + DESCRIPTION_LENGTH_OF_LINE] = '\0'; /* truncating description line  */
11c606a6 (kx 2023-04-11 01:18:34 +0300 2064)         skip_eol_spaces( match );                            /* remove spaces at end-of-line */
11c606a6 (kx 2023-04-11 01:18:34 +0300 2065)       }
11c606a6 (kx 2023-04-11 01:18:34 +0300 2066) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 2067)       match += plen + 1;
11c606a6 (kx 2023-04-11 01:18:34 +0300 2068)       if( match[0] != '\0' ) { (void)sprintf( lp, " %s\n", match ); lp += strlen( match ) + 2; }
11c606a6 (kx 2023-04-11 01:18:34 +0300 2069)       else                   { (void)sprintf( lp, "\n" ); ++lp; }
11c606a6 (kx 2023-04-11 01:18:34 +0300 2070)       ++n;
11c606a6 (kx 2023-04-11 01:18:34 +0300 2071)     }
11c606a6 (kx 2023-04-11 01:18:34 +0300 2072)   } /* End of while( ln = fgets() ) */
11c606a6 (kx 2023-04-11 01:18:34 +0300 2073) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 2074)   fclose( fp );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2075) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 2076)   (void)sprintf( lp, " Uncompressed Size: %s\n", uncompressed_size );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2077)   lp += strlen( uncompressed_size ) + 21;
11c606a6 (kx 2023-04-11 01:18:34 +0300 2078)   (void)sprintf( lp, "   Compressed Size: %s\n", compressed_size );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2079)   lp += strlen( compressed_size ) + 21;
11c606a6 (kx 2023-04-11 01:18:34 +0300 2080) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 2081)   description = xstrdup( (const char *)&tmp[0] );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2082) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 2083)   free( buf );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2084)   free( line );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2085)   free( tmp );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2086) }
11c606a6 (kx 2023-04-11 01:18:34 +0300 2087) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 2088) static int ask_for_install( void )
11c606a6 (kx 2023-04-11 01:18:34 +0300 2089) {
11c606a6 (kx 2023-04-11 01:18:34 +0300 2090)   int ret = 0; /* continue installation */
11c606a6 (kx 2023-04-11 01:18:34 +0300 2091) #if defined( HAVE_DIALOG )
11c606a6 (kx 2023-04-11 01:18:34 +0300 2092)   /******************************************************
11c606a6 (kx 2023-04-11 01:18:34 +0300 2093)     Ask for install dialog shown only in MENUDIALOG mode
11c606a6 (kx 2023-04-11 01:18:34 +0300 2094)     when priority != REQUIRED or --always-ask=yes:
11c606a6 (kx 2023-04-11 01:18:34 +0300 2095)    */
11c606a6 (kx 2023-04-11 01:18:34 +0300 2096)   if( (install_mode == MENUDIALOG) && (((priority == REQUIRED) && ask) || (priority != REQUIRED)) )
11c606a6 (kx 2023-04-11 01:18:34 +0300 2097)   {
11c606a6 (kx 2023-04-11 01:18:34 +0300 2098)     ret =  ask_install_box( "Install:", pkgname, pkgver, strprio( priority, 0 ),
11c606a6 (kx 2023-04-11 01:18:34 +0300 2099)                             description, 18, 0, 0 );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2100)   }
11c606a6 (kx 2023-04-11 01:18:34 +0300 2101) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 2102)   if( ret )
11c606a6 (kx 2023-04-11 01:18:34 +0300 2103)   {
11c606a6 (kx 2023-04-11 01:18:34 +0300 2104)     info_pkg_box( "Install:", pkgname, pkgver, strprio( priority, 0 ),
11c606a6 (kx 2023-04-11 01:18:34 +0300 2105)                   "\nInstallation terminated by user.\n", 5, 0, 0 );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2106)   }
11c606a6 (kx 2023-04-11 01:18:34 +0300 2107) #endif
11c606a6 (kx 2023-04-11 01:18:34 +0300 2108)   return ret;
11c606a6 (kx 2023-04-11 01:18:34 +0300 2109) }
11c606a6 (kx 2023-04-11 01:18:34 +0300 2110) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 2111) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 2112) static void show_install_progress( void )
11c606a6 (kx 2023-04-11 01:18:34 +0300 2113) {
11c606a6 (kx 2023-04-11 01:18:34 +0300 2114)   fprintf( stdout, "\033[2J" ); /* clear screen */
11c606a6 (kx 2023-04-11 01:18:34 +0300 2115) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 2116)   if( install_mode != CONSOLE )
11c606a6 (kx 2023-04-11 01:18:34 +0300 2117)   {
11c606a6 (kx 2023-04-11 01:18:34 +0300 2118) #if defined( HAVE_DIALOG )
11c606a6 (kx 2023-04-11 01:18:34 +0300 2119)     info_pkg_box( "Install:", pkgname, pkgver, strprio( priority, 0 ),
11c606a6 (kx 2023-04-11 01:18:34 +0300 2120)                   description, 16, 0, 0 );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2121) #else
11c606a6 (kx 2023-04-11 01:18:34 +0300 2122)     fprintf( stdout, "\n Install: %s-%s [%s]...\n", pkgname, pkgver, strprio( priority, 0 ));
11c606a6 (kx 2023-04-11 01:18:34 +0300 2123)     /*************************************************
11c606a6 (kx 2023-04-11 01:18:34 +0300 2124)       Ruler: 68 characters + 2 spaces left and right:
11c606a6 (kx 2023-04-11 01:18:34 +0300 2125) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 2126)                       | ----handy-ruler----------------------------------------------------- | */
11c606a6 (kx 2023-04-11 01:18:34 +0300 2127)     fprintf( stdout, "|======================================================================|\n" );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2128)     fprintf( stdout, "%s\n", description );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2129)     fprintf( stdout, "|======================================================================|\n\n" );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2130)     fprintf( stdout, "\n\n\n" ); /* 3 lines up for final message */
11c606a6 (kx 2023-04-11 01:18:34 +0300 2131) #endif
11c606a6 (kx 2023-04-11 01:18:34 +0300 2132)   }
11c606a6 (kx 2023-04-11 01:18:34 +0300 2133)   else
11c606a6 (kx 2023-04-11 01:18:34 +0300 2134)   {
11c606a6 (kx 2023-04-11 01:18:34 +0300 2135)     fprintf( stdout, "\n Install: %s-%s [%s]...\n", pkgname, pkgver, strprio( priority, 0 ));
11c606a6 (kx 2023-04-11 01:18:34 +0300 2136)     /*************************************************
11c606a6 (kx 2023-04-11 01:18:34 +0300 2137)       Ruler: 68 characters + 2 spaces left and right:
11c606a6 (kx 2023-04-11 01:18:34 +0300 2138) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 2139)                       | ----handy-ruler----------------------------------------------------- | */
11c606a6 (kx 2023-04-11 01:18:34 +0300 2140)     fprintf( stdout, "|======================================================================|\n" );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2141)     fprintf( stdout, "%s\n", description );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2142)     fprintf( stdout, "|======================================================================|\n\n" );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2143)     fprintf( stdout, "\n\n\n" ); /* 3 lines up for final message */
11c606a6 (kx 2023-04-11 01:18:34 +0300 2144)   }
11c606a6 (kx 2023-04-11 01:18:34 +0300 2145) }
11c606a6 (kx 2023-04-11 01:18:34 +0300 2146) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 2147) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 2148) static void pre_install_routine( void )
11c606a6 (kx 2023-04-11 01:18:34 +0300 2149) {
11c606a6 (kx 2023-04-11 01:18:34 +0300 2150)   pid_t p = (pid_t) -1;
11c606a6 (kx 2023-04-11 01:18:34 +0300 2151)   int   rc;
11c606a6 (kx 2023-04-11 01:18:34 +0300 2152) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 2153)   int   len = 0;
11c606a6 (kx 2023-04-11 01:18:34 +0300 2154)   char *cmd = NULL;
11c606a6 (kx 2023-04-11 01:18:34 +0300 2155) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 2156)   cmd = (char *)malloc( (size_t)PATH_MAX );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2157)   if( !cmd ) { FATAL_ERROR( "Cannot allocate memory" ); }
11c606a6 (kx 2023-04-11 01:18:34 +0300 2158)   bzero( (void *)cmd, PATH_MAX );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2159) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 2160)   len = snprintf( &cmd[0], PATH_MAX,
11c606a6 (kx 2023-04-11 01:18:34 +0300 2161)                   "cd %s && %s/.INSTALL pre_install %s > /dev/null 2>&1",
11c606a6 (kx 2023-04-11 01:18:34 +0300 2162)                   root, tmpdir, pkgver );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2163)   if( len == 0 || len == PATH_MAX - 1 )
11c606a6 (kx 2023-04-11 01:18:34 +0300 2164)   {
11c606a6 (kx 2023-04-11 01:18:34 +0300 2165)     FATAL_ERROR( "Cannot run pre-install script for '%s-%s' package", pkgname, pkgver );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2166)   }
11c606a6 (kx 2023-04-11 01:18:34 +0300 2167)   p = sys_exec_command( cmd );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2168)   rc = sys_wait_command( p, (char *)NULL, PATH_MAX );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2169) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 2170)   free( cmd );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2171) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 2172)   if( rc != 0 )
11c606a6 (kx 2023-04-11 01:18:34 +0300 2173)   {
11c606a6 (kx 2023-04-11 01:18:34 +0300 2174)     exit_status = 43;
11c606a6 (kx 2023-04-11 01:18:34 +0300 2175) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 2176)     if( install_mode != CONSOLE )
11c606a6 (kx 2023-04-11 01:18:34 +0300 2177)     {
11c606a6 (kx 2023-04-11 01:18:34 +0300 2178) #if defined( HAVE_DIALOG )
11c606a6 (kx 2023-04-11 01:18:34 +0300 2179)       info_pkg_box( "Install:", pkgname, pkgver, strprio( priority, 0 ),
11c606a6 (kx 2023-04-11 01:18:34 +0300 2180)                     "\n\\Z1Pre-install script returned error status.\\Zn\n", 5, 0, 0 );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2181) #else
11c606a6 (kx 2023-04-11 01:18:34 +0300 2182)       fprintf( stdout, "\nPre-install script of '%s-%s' returned error status.\n\n", pkgname, pkgver );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2183) #endif
11c606a6 (kx 2023-04-11 01:18:34 +0300 2184)     }
11c606a6 (kx 2023-04-11 01:18:34 +0300 2185)     else
11c606a6 (kx 2023-04-11 01:18:34 +0300 2186)     {
11c606a6 (kx 2023-04-11 01:18:34 +0300 2187)       fprintf( stdout, "\nPre-install script of '%s-%s' returned error status.\n\n", pkgname, pkgver );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2188)     }
11c606a6 (kx 2023-04-11 01:18:34 +0300 2189) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 2190)     if( tmpdir ) { _rm_tmpdir( (const char *)tmpdir ); free( tmpdir ); }
11c606a6 (kx 2023-04-11 01:18:34 +0300 2191)     free_resources();
11c606a6 (kx 2023-04-11 01:18:34 +0300 2192)     exit( exit_status );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2193)   }
11c606a6 (kx 2023-04-11 01:18:34 +0300 2194) }
11c606a6 (kx 2023-04-11 01:18:34 +0300 2195) 
a745159c (kx 2023-10-23 21:39:58 +0300 2196) static int __nstreams( void )
a745159c (kx 2023-10-23 21:39:58 +0300 2197) {
a745159c (kx 2023-10-23 21:39:58 +0300 2198)   int ret    = 1;
a745159c (kx 2023-10-23 21:39:58 +0300 2199)   int nprocs = get_nprocs();
a745159c (kx 2023-10-23 21:39:58 +0300 2200) 
a745159c (kx 2023-10-23 21:39:58 +0300 2201)   if( nprocs > 4 )
a745159c (kx 2023-10-23 21:39:58 +0300 2202)   {
a745159c (kx 2023-10-23 21:39:58 +0300 2203)     ret = nprocs / 2;
a745159c (kx 2023-10-23 21:39:58 +0300 2204)   }
a745159c (kx 2023-10-23 21:39:58 +0300 2205) 
a745159c (kx 2023-10-23 21:39:58 +0300 2206)   return ret;
a745159c (kx 2023-10-23 21:39:58 +0300 2207) }
a745159c (kx 2023-10-23 21:39:58 +0300 2208) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 2209) static const char *fill_decompressor( char *buffer, char compressor )
11c606a6 (kx 2023-04-11 01:18:34 +0300 2210) {
11c606a6 (kx 2023-04-11 01:18:34 +0300 2211)   switch( compressor )
11c606a6 (kx 2023-04-11 01:18:34 +0300 2212)   {
11c606a6 (kx 2023-04-11 01:18:34 +0300 2213)     case 'J':
a745159c (kx 2023-10-23 21:39:58 +0300 2214)       (void)sprintf( buffer, "xz --threads=%d -dc", __nstreams() );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2215)       break;
11c606a6 (kx 2023-04-11 01:18:34 +0300 2216)     case 'j':
11c606a6 (kx 2023-04-11 01:18:34 +0300 2217)       (void)sprintf( buffer, "bzip2 -dc" );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2218)       break;
11c606a6 (kx 2023-04-11 01:18:34 +0300 2219)     case 'z':
11c606a6 (kx 2023-04-11 01:18:34 +0300 2220)       (void)sprintf( buffer, "gzip -dc" );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2221)       break;
11c606a6 (kx 2023-04-11 01:18:34 +0300 2222)     default:
11c606a6 (kx 2023-04-11 01:18:34 +0300 2223)       (void)sprintf( buffer, "cat -" );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2224)       break;
11c606a6 (kx 2023-04-11 01:18:34 +0300 2225)   }
11c606a6 (kx 2023-04-11 01:18:34 +0300 2226)   return (const char *)buffer;
11c606a6 (kx 2023-04-11 01:18:34 +0300 2227) }
11c606a6 (kx 2023-04-11 01:18:34 +0300 2228) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 2229) static void uncompress_package( void )
11c606a6 (kx 2023-04-11 01:18:34 +0300 2230) {
a745159c (kx 2023-10-23 21:39:58 +0300 2231)   pid_t  p = (pid_t) -1;
a745159c (kx 2023-10-23 21:39:58 +0300 2232)   int   rc = EXIT_SUCCESS;
11c606a6 (kx 2023-04-11 01:18:34 +0300 2233) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 2234)   int   len = 0;
11c606a6 (kx 2023-04-11 01:18:34 +0300 2235)   char *cmd = NULL;
11c606a6 (kx 2023-04-11 01:18:34 +0300 2236) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 2237)   char decompressor[64];
11c606a6 (kx 2023-04-11 01:18:34 +0300 2238) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 2239)   (void)fill_decompressor( (char *)&decompressor[0], uncompress );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2240) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 2241)   cmd = (char *)malloc( (size_t)PATH_MAX );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2242)   if( !cmd ) { FATAL_ERROR( "Cannot allocate memory" ); }
11c606a6 (kx 2023-04-11 01:18:34 +0300 2243)   bzero( (void *)cmd, PATH_MAX );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2244) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 2245)   len = snprintf( &cmd[0], PATH_MAX,
11c606a6 (kx 2023-04-11 01:18:34 +0300 2246)                   "cat %s | %s  | tar -C %s "
11c606a6 (kx 2023-04-11 01:18:34 +0300 2247)                   "--exclude='.DESCRIPTION' "
11c606a6 (kx 2023-04-11 01:18:34 +0300 2248)                   "--exclude='.FILELIST' "
11c606a6 (kx 2023-04-11 01:18:34 +0300 2249)                   "--exclude='.INSTALL' "
11c606a6 (kx 2023-04-11 01:18:34 +0300 2250)                   "--exclude='.PKGINFO' "
11c606a6 (kx 2023-04-11 01:18:34 +0300 2251)                   "--exclude='.REQUIRES' "
11c606a6 (kx 2023-04-11 01:18:34 +0300 2252)                   "--exclude='.RESTORELINKS' "
11c606a6 (kx 2023-04-11 01:18:34 +0300 2253)                   "-xf - > /dev/null 2>&1",
11c606a6 (kx 2023-04-11 01:18:34 +0300 2254)                   pkg_fname, decompressor, root );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2255)   if( len == 0 || len == PATH_MAX - 1 )
11c606a6 (kx 2023-04-11 01:18:34 +0300 2256)   {
11c606a6 (kx 2023-04-11 01:18:34 +0300 2257)     FATAL_ERROR( "Cannot uncompress '%s-%s' package", pkgname, pkgver );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2258)   }
11c606a6 (kx 2023-04-11 01:18:34 +0300 2259)   p = sys_exec_command( cmd );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2260)   rc = sys_wait_command( p, (char *)NULL, PATH_MAX );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2261) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 2262)   free( cmd );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2263) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 2264)   if( rc != 0 )
11c606a6 (kx 2023-04-11 01:18:34 +0300 2265)   {
11c606a6 (kx 2023-04-11 01:18:34 +0300 2266)     exit_status = 44;
11c606a6 (kx 2023-04-11 01:18:34 +0300 2267) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 2268)     if( install_mode != CONSOLE )
11c606a6 (kx 2023-04-11 01:18:34 +0300 2269)     {
11c606a6 (kx 2023-04-11 01:18:34 +0300 2270) #if defined( HAVE_DIALOG )
11c606a6 (kx 2023-04-11 01:18:34 +0300 2271)       info_pkg_box( "Install:", pkgname, pkgver, strprio( priority, 0 ),
11c606a6 (kx 2023-04-11 01:18:34 +0300 2272)                     "\n\\Z1Cannot uncompress package.\\Zn\n", 5, 0, 0 );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2273) #else
11c606a6 (kx 2023-04-11 01:18:34 +0300 2274)       fprintf( stdout, "\nCannot uncompress '%s-%s' package.\n\n", pkgname, pkgver );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2275) #endif
11c606a6 (kx 2023-04-11 01:18:34 +0300 2276)     }
11c606a6 (kx 2023-04-11 01:18:34 +0300 2277)     else
11c606a6 (kx 2023-04-11 01:18:34 +0300 2278)     {
11c606a6 (kx 2023-04-11 01:18:34 +0300 2279)       fprintf( stdout, "\nCannot uncompress '%s-%s' package.\n\n", pkgname, pkgver );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2280)     }
11c606a6 (kx 2023-04-11 01:18:34 +0300 2281) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 2282)     if( tmpdir ) { _rm_tmpdir( (const char *)tmpdir ); free( tmpdir ); }
11c606a6 (kx 2023-04-11 01:18:34 +0300 2283)     free_resources();
11c606a6 (kx 2023-04-11 01:18:34 +0300 2284)     exit( exit_status );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2285)   }
11c606a6 (kx 2023-04-11 01:18:34 +0300 2286) }
11c606a6 (kx 2023-04-11 01:18:34 +0300 2287) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 2288) static void restore_links( void )
11c606a6 (kx 2023-04-11 01:18:34 +0300 2289) {
11c606a6 (kx 2023-04-11 01:18:34 +0300 2290)   struct stat st;
11c606a6 (kx 2023-04-11 01:18:34 +0300 2291)   pid_t  p = (pid_t) -1;
11c606a6 (kx 2023-04-11 01:18:34 +0300 2292)   int    rc;
11c606a6 (kx 2023-04-11 01:18:34 +0300 2293) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 2294)   int   len = 0;
11c606a6 (kx 2023-04-11 01:18:34 +0300 2295)   char *cmd = NULL;
11c606a6 (kx 2023-04-11 01:18:34 +0300 2296) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 2297)   cmd = (char *)malloc( (size_t)PATH_MAX );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2298)   if( !cmd ) { FATAL_ERROR( "Cannot allocate memory" ); }
11c606a6 (kx 2023-04-11 01:18:34 +0300 2299)   bzero( (void *)cmd, PATH_MAX );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2300) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 2301)   (void)sprintf( &cmd[0], "%s/.RESTORELINKS", tmpdir );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2302)   bzero( (void *)&st, sizeof( struct stat ) );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2303)   if( (stat( (const char *)&cmd[0], &st ) == -1) || (st.st_size < 8) )
11c606a6 (kx 2023-04-11 01:18:34 +0300 2304)   {
11c606a6 (kx 2023-04-11 01:18:34 +0300 2305)     free( cmd );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2306)     return;
11c606a6 (kx 2023-04-11 01:18:34 +0300 2307)   }
11c606a6 (kx 2023-04-11 01:18:34 +0300 2308)   bzero( (void *)cmd, PATH_MAX );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2309) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 2310)   len = snprintf( &cmd[0], PATH_MAX,
11c606a6 (kx 2023-04-11 01:18:34 +0300 2311)                   "cd %s && sh %s/.RESTORELINKS > /dev/null 2>&1",
11c606a6 (kx 2023-04-11 01:18:34 +0300 2312)                   root, tmpdir );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2313)   if( len == 0 || len == PATH_MAX - 1 )
11c606a6 (kx 2023-04-11 01:18:34 +0300 2314)   {
11c606a6 (kx 2023-04-11 01:18:34 +0300 2315)     FATAL_ERROR( "Cannot restore links for '%s-%s' package", pkgname, pkgver );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2316)   }
11c606a6 (kx 2023-04-11 01:18:34 +0300 2317)   p = sys_exec_command( cmd );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2318)   rc = sys_wait_command( p, (char *)NULL, PATH_MAX );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2319) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 2320)   free( cmd );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2321) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 2322)   if( rc != 0 )
11c606a6 (kx 2023-04-11 01:18:34 +0300 2323)   {
11c606a6 (kx 2023-04-11 01:18:34 +0300 2324)     rollback();
11c606a6 (kx 2023-04-11 01:18:34 +0300 2325) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 2326)     exit_status = 45;
11c606a6 (kx 2023-04-11 01:18:34 +0300 2327) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 2328)     if( install_mode != CONSOLE )
11c606a6 (kx 2023-04-11 01:18:34 +0300 2329)     {
11c606a6 (kx 2023-04-11 01:18:34 +0300 2330) #if defined( HAVE_DIALOG )
11c606a6 (kx 2023-04-11 01:18:34 +0300 2331)       info_pkg_box( "Install:", pkgname, pkgver, strprio( priority, 0 ),
11c606a6 (kx 2023-04-11 01:18:34 +0300 2332)                     "\n\\Z1Restore-links script returned error status.\\Zn\n", 5, 0, 0 );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2333) #else
11c606a6 (kx 2023-04-11 01:18:34 +0300 2334)       fprintf( stdout, "\nRestore-links script of '%s-%s' returned error status.\n\n", pkgname, pkgver );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2335) #endif
11c606a6 (kx 2023-04-11 01:18:34 +0300 2336)     }
11c606a6 (kx 2023-04-11 01:18:34 +0300 2337)     else
11c606a6 (kx 2023-04-11 01:18:34 +0300 2338)     {
11c606a6 (kx 2023-04-11 01:18:34 +0300 2339)       fprintf( stdout, "\nRestore-links script of '%s-%s' returned error status.\n\n", pkgname, pkgver );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2340)     }
11c606a6 (kx 2023-04-11 01:18:34 +0300 2341) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 2342)     if( tmpdir ) { _rm_tmpdir( (const char *)tmpdir ); free( tmpdir ); }
11c606a6 (kx 2023-04-11 01:18:34 +0300 2343)     free_resources();
11c606a6 (kx 2023-04-11 01:18:34 +0300 2344)     exit( exit_status );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2345)   }
11c606a6 (kx 2023-04-11 01:18:34 +0300 2346) }
11c606a6 (kx 2023-04-11 01:18:34 +0300 2347) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 2348) static void post_install_routine( void )
11c606a6 (kx 2023-04-11 01:18:34 +0300 2349) {
11c606a6 (kx 2023-04-11 01:18:34 +0300 2350)   pid_t p = (pid_t) -1;
11c606a6 (kx 2023-04-11 01:18:34 +0300 2351)   int   rc;
11c606a6 (kx 2023-04-11 01:18:34 +0300 2352) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 2353)   int   len = 0;
11c606a6 (kx 2023-04-11 01:18:34 +0300 2354)   char *cmd = NULL;
11c606a6 (kx 2023-04-11 01:18:34 +0300 2355) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 2356)   cmd = (char *)malloc( (size_t)PATH_MAX );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2357)   if( !cmd ) { FATAL_ERROR( "Cannot allocate memory" ); }
11c606a6 (kx 2023-04-11 01:18:34 +0300 2358)   bzero( (void *)cmd, PATH_MAX );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2359) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 2360)   len = snprintf( &cmd[0], PATH_MAX,
11c606a6 (kx 2023-04-11 01:18:34 +0300 2361)                   "cd %s && %s/.INSTALL post_install %s > /dev/null 2>&1",
11c606a6 (kx 2023-04-11 01:18:34 +0300 2362)                   root, tmpdir, pkgver );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2363)   if( len == 0 || len == PATH_MAX - 1 )
11c606a6 (kx 2023-04-11 01:18:34 +0300 2364)   {
11c606a6 (kx 2023-04-11 01:18:34 +0300 2365)     FATAL_ERROR( "Cannot run post-install script for '%s-%s' package", pkgname, pkgver );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2366)   }
11c606a6 (kx 2023-04-11 01:18:34 +0300 2367)   p = sys_exec_command( cmd );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2368)   rc = sys_wait_command( p, (char *)NULL, PATH_MAX );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2369) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 2370)   free( cmd );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2371) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 2372)   if( rc != 0 )
11c606a6 (kx 2023-04-11 01:18:34 +0300 2373)   {
11c606a6 (kx 2023-04-11 01:18:34 +0300 2374)     rollback();
11c606a6 (kx 2023-04-11 01:18:34 +0300 2375) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 2376)     exit_status = 46;
11c606a6 (kx 2023-04-11 01:18:34 +0300 2377) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 2378)     if( install_mode != CONSOLE )
11c606a6 (kx 2023-04-11 01:18:34 +0300 2379)     {
11c606a6 (kx 2023-04-11 01:18:34 +0300 2380) #if defined( HAVE_DIALOG )
11c606a6 (kx 2023-04-11 01:18:34 +0300 2381)       info_pkg_box( "Install:", pkgname, pkgver, strprio( priority, 0 ),
11c606a6 (kx 2023-04-11 01:18:34 +0300 2382)                     "\n\\Z1Post-install script returned error status.\\Zn\n", 5, 0, 0 );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2383) #else
11c606a6 (kx 2023-04-11 01:18:34 +0300 2384)       fprintf( stdout, "\nPost-install script of '%s-%s' returned error status.\n\n", pkgname, pkgver );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2385) #endif
11c606a6 (kx 2023-04-11 01:18:34 +0300 2386)     }
11c606a6 (kx 2023-04-11 01:18:34 +0300 2387)     else
11c606a6 (kx 2023-04-11 01:18:34 +0300 2388)     {
11c606a6 (kx 2023-04-11 01:18:34 +0300 2389)       fprintf( stdout, "\nPost-install script of '%s-%s' returned error status.\n\n", pkgname, pkgver );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2390)     }
11c606a6 (kx 2023-04-11 01:18:34 +0300 2391) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 2392)     if( tmpdir ) { _rm_tmpdir( (const char *)tmpdir ); free( tmpdir ); }
11c606a6 (kx 2023-04-11 01:18:34 +0300 2393)     free_resources();
11c606a6 (kx 2023-04-11 01:18:34 +0300 2394)     exit( exit_status );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2395)   }
11c606a6 (kx 2023-04-11 01:18:34 +0300 2396) }
11c606a6 (kx 2023-04-11 01:18:34 +0300 2397) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 2398) static void finalize_installation( void )
11c606a6 (kx 2023-04-11 01:18:34 +0300 2399) {
11c606a6 (kx 2023-04-11 01:18:34 +0300 2400)   pid_t p = (pid_t) -1;
11c606a6 (kx 2023-04-11 01:18:34 +0300 2401)   int   rc;
11c606a6 (kx 2023-04-11 01:18:34 +0300 2402) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 2403)   int   len = 0;
11c606a6 (kx 2023-04-11 01:18:34 +0300 2404)   char *cmd = NULL, *tmp = NULL;
11c606a6 (kx 2023-04-11 01:18:34 +0300 2405) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 2406)   cmd = (char *)malloc( (size_t)PATH_MAX );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2407)   if( !cmd ) { FATAL_ERROR( "Cannot allocate memory" ); }
11c606a6 (kx 2023-04-11 01:18:34 +0300 2408)   bzero( (void *)cmd, PATH_MAX );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2409) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 2410)   tmp = (char *)malloc( (size_t)PATH_MAX );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2411)   if( !tmp ) { FATAL_ERROR( "Cannot allocate memory" ); }
11c606a6 (kx 2023-04-11 01:18:34 +0300 2412)   bzero( (void *)tmp, PATH_MAX );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2413) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 2414)   if( group )
11c606a6 (kx 2023-04-11 01:18:34 +0300 2415)     (void)sprintf( &tmp[0], "%s/%s/", pkgs_path, group );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2416)   else
11c606a6 (kx 2023-04-11 01:18:34 +0300 2417)     (void)sprintf( &tmp[0], "%s/", pkgs_path );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2418) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 2419)   if( _mkdir_p( tmp, S_IRWXU | S_IRWXG | S_IRWXO ) != 0 )
11c606a6 (kx 2023-04-11 01:18:34 +0300 2420)   {
11c606a6 (kx 2023-04-11 01:18:34 +0300 2421)     FATAL_ERROR( "Cannot access '/%s' directory", PACKAGES_PATH );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2422)   }
11c606a6 (kx 2023-04-11 01:18:34 +0300 2423) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 2424)   /****************************************
11c606a6 (kx 2023-04-11 01:18:34 +0300 2425)     Store PKGLOG file into Setup Database:
11c606a6 (kx 2023-04-11 01:18:34 +0300 2426)    */
11c606a6 (kx 2023-04-11 01:18:34 +0300 2427)   len = snprintf( &cmd[0], PATH_MAX,
11c606a6 (kx 2023-04-11 01:18:34 +0300 2428)                   "cp %s %s > /dev/null 2>&1",
11c606a6 (kx 2023-04-11 01:18:34 +0300 2429)                   pkglog_fname, (const char *)&tmp[0] );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2430)   if( len == 0 || len == PATH_MAX - 1 )
11c606a6 (kx 2023-04-11 01:18:34 +0300 2431)   {
11c606a6 (kx 2023-04-11 01:18:34 +0300 2432)     FATAL_ERROR( "Cannot store '%s' pkglog file", basename( (char *)pkglog_fname ) );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2433)   }
11c606a6 (kx 2023-04-11 01:18:34 +0300 2434)   p = sys_exec_command( cmd );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2435)   rc = sys_wait_command( p, (char *)NULL, PATH_MAX );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2436)   if( rc != 0 )
11c606a6 (kx 2023-04-11 01:18:34 +0300 2437)   {
11c606a6 (kx 2023-04-11 01:18:34 +0300 2438)     rollback();
11c606a6 (kx 2023-04-11 01:18:34 +0300 2439) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 2440)     free( cmd );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2441)     free( tmp );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2442) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 2443)     exit_status = 47;
11c606a6 (kx 2023-04-11 01:18:34 +0300 2444) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 2445)     if( install_mode != CONSOLE )
11c606a6 (kx 2023-04-11 01:18:34 +0300 2446)     {
11c606a6 (kx 2023-04-11 01:18:34 +0300 2447) #if defined( HAVE_DIALOG )
11c606a6 (kx 2023-04-11 01:18:34 +0300 2448)       info_pkg_box( "Install:", pkgname, pkgver, strprio( priority, 0 ),
11c606a6 (kx 2023-04-11 01:18:34 +0300 2449)                     "\n\\Z1Cannot store PKGLOG file into Setup Database.\\Zn\n", 5, 0, 0 );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2450) #else
11c606a6 (kx 2023-04-11 01:18:34 +0300 2451)       fprintf( stdout, "\nCannot store '%s' pkglog file into Setup Database.\n\n", basename( (char *)pkglog_fname ) );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2452) #endif
11c606a6 (kx 2023-04-11 01:18:34 +0300 2453)     }
11c606a6 (kx 2023-04-11 01:18:34 +0300 2454)     else
11c606a6 (kx 2023-04-11 01:18:34 +0300 2455)     {
11c606a6 (kx 2023-04-11 01:18:34 +0300 2456)       fprintf( stdout, "\nCannot store '%s' pkglog file into Setup Database.\n\n", basename( (char *)pkglog_fname ) );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2457)     }
11c606a6 (kx 2023-04-11 01:18:34 +0300 2458) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 2459)     if( tmpdir ) { _rm_tmpdir( (const char *)tmpdir ); free( tmpdir ); }
11c606a6 (kx 2023-04-11 01:18:34 +0300 2460)     free_resources();
11c606a6 (kx 2023-04-11 01:18:34 +0300 2461)     exit( exit_status );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2462)   }
11c606a6 (kx 2023-04-11 01:18:34 +0300 2463) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 2464)   /*********************************************
11c606a6 (kx 2023-04-11 01:18:34 +0300 2465)     Increment references in the Setup Database:
11c606a6 (kx 2023-04-11 01:18:34 +0300 2466)    */
a745159c (kx 2023-10-23 21:39:58 +0300 2467)   if( !disable_chrefs )
11c606a6 (kx 2023-04-11 01:18:34 +0300 2468)   {
a745159c (kx 2023-10-23 21:39:58 +0300 2469)     if( group )
a745159c (kx 2023-10-23 21:39:58 +0300 2470)       len = snprintf( &cmd[0], PATH_MAX,
a745159c (kx 2023-10-23 21:39:58 +0300 2471)                       "%s/chrefs --operation=inc --destination=%s %s/%s > /dev/null 2>&1",
a745159c (kx 2023-10-23 21:39:58 +0300 2472)                       selfdir, pkgs_path, group, basename( (char *)pkglog_fname ) );
a745159c (kx 2023-10-23 21:39:58 +0300 2473)     else
a745159c (kx 2023-10-23 21:39:58 +0300 2474)       len = snprintf( &cmd[0], PATH_MAX,
a745159c (kx 2023-10-23 21:39:58 +0300 2475)                       "%s/chrefs --operation=inc --destination=%s %s > /dev/null 2>&1",
a745159c (kx 2023-10-23 21:39:58 +0300 2476)                       selfdir, pkgs_path, basename( (char *)pkglog_fname ) );
a745159c (kx 2023-10-23 21:39:58 +0300 2477)     if( len == 0 || len == PATH_MAX - 1 )
a745159c (kx 2023-10-23 21:39:58 +0300 2478)     {
a745159c (kx 2023-10-23 21:39:58 +0300 2479)       FATAL_ERROR( "Cannot increment '%s-%s' package references", pkgname, pkgver );
a745159c (kx 2023-10-23 21:39:58 +0300 2480)     }
a745159c (kx 2023-10-23 21:39:58 +0300 2481)     p = sys_exec_command( cmd );
a745159c (kx 2023-10-23 21:39:58 +0300 2482)     rc = sys_wait_command( p, (char *)NULL, PATH_MAX );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2483) 
a745159c (kx 2023-10-23 21:39:58 +0300 2484)     free( cmd );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2485) 
a745159c (kx 2023-10-23 21:39:58 +0300 2486)     if( (rc != 0) && !ignore_chrefs_errors )
a745159c (kx 2023-10-23 21:39:58 +0300 2487)     {
a745159c (kx 2023-10-23 21:39:58 +0300 2488)       free( tmp );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2489) 
a745159c (kx 2023-10-23 21:39:58 +0300 2490)       rollback();
11c606a6 (kx 2023-04-11 01:18:34 +0300 2491) 
a745159c (kx 2023-10-23 21:39:58 +0300 2492)       exit_status = 48;
11c606a6 (kx 2023-04-11 01:18:34 +0300 2493) 
a745159c (kx 2023-10-23 21:39:58 +0300 2494)       if( install_mode != CONSOLE )
a745159c (kx 2023-10-23 21:39:58 +0300 2495)       {
11c606a6 (kx 2023-04-11 01:18:34 +0300 2496) #if defined( HAVE_DIALOG )
a745159c (kx 2023-10-23 21:39:58 +0300 2497)         info_pkg_box( "Install:", pkgname, pkgver, strprio( priority, 0 ),
a745159c (kx 2023-10-23 21:39:58 +0300 2498)                       "\n\\Z1Cannot increment package references in Setup Database.\\Zn\n", 5, 0, 0 );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2499) #else
a745159c (kx 2023-10-23 21:39:58 +0300 2500)         fprintf( stdout, "\nCannot increment '%s-%s' package references in Setup Database.\n\n", pkgname, pkgver );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2501) #endif
a745159c (kx 2023-10-23 21:39:58 +0300 2502)       }
a745159c (kx 2023-10-23 21:39:58 +0300 2503)       else
a745159c (kx 2023-10-23 21:39:58 +0300 2504)       {
a745159c (kx 2023-10-23 21:39:58 +0300 2505)         fprintf( stdout, "\nCannot increment '%s-%s' package references in Setup Database.\n\n", pkgname, pkgver );
a745159c (kx 2023-10-23 21:39:58 +0300 2506)       }
11c606a6 (kx 2023-04-11 01:18:34 +0300 2507) 
a745159c (kx 2023-10-23 21:39:58 +0300 2508)       if( tmpdir ) { _rm_tmpdir( (const char *)tmpdir ); free( tmpdir ); }
a745159c (kx 2023-10-23 21:39:58 +0300 2509)       free_resources();
a745159c (kx 2023-10-23 21:39:58 +0300 2510)       exit( exit_status );
a745159c (kx 2023-10-23 21:39:58 +0300 2511)     }
11c606a6 (kx 2023-04-11 01:18:34 +0300 2512)   }
11c606a6 (kx 2023-04-11 01:18:34 +0300 2513) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 2514)   /*************************************************
11c606a6 (kx 2023-04-11 01:18:34 +0300 2515)     Remove backup PKGLOG file from removed-packages
11c606a6 (kx 2023-04-11 01:18:34 +0300 2516)     directory if exists:
11c606a6 (kx 2023-04-11 01:18:34 +0300 2517)    */
11c606a6 (kx 2023-04-11 01:18:34 +0300 2518)   bzero( (void *)tmp, PATH_MAX );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2519)   {
11c606a6 (kx 2023-04-11 01:18:34 +0300 2520)     const char *fname = basename( (char *)pkglog_fname );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2521) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 2522)     if( group )
11c606a6 (kx 2023-04-11 01:18:34 +0300 2523)       (void)sprintf( &tmp[0], "%s/%s/%s", rempkgs_path, group, fname );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2524)     else
11c606a6 (kx 2023-04-11 01:18:34 +0300 2525)       (void)sprintf( &tmp[0], "%s/%s", rempkgs_path, fname );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2526) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 2527)     (void)unlink( (const char *)&tmp[0] );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2528) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 2529)     if( group )
11c606a6 (kx 2023-04-11 01:18:34 +0300 2530)     {
11c606a6 (kx 2023-04-11 01:18:34 +0300 2531)       const char *dir = (const char *)dirname( (char *)&tmp[0] );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2532)       if( is_dir_empty( dir ) )
11c606a6 (kx 2023-04-11 01:18:34 +0300 2533)       {
11c606a6 (kx 2023-04-11 01:18:34 +0300 2534)         (void)rmdir( dir );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2535)       }
11c606a6 (kx 2023-04-11 01:18:34 +0300 2536)     }
11c606a6 (kx 2023-04-11 01:18:34 +0300 2537)   }
11c606a6 (kx 2023-04-11 01:18:34 +0300 2538) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 2539)   free( tmp );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2540) }
11c606a6 (kx 2023-04-11 01:18:34 +0300 2541) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 2542) #if defined( HAVE_GPG2 )
11c606a6 (kx 2023-04-11 01:18:34 +0300 2543) static void verify_gpg_signature( void )
11c606a6 (kx 2023-04-11 01:18:34 +0300 2544) {
11c606a6 (kx 2023-04-11 01:18:34 +0300 2545)   struct stat st;
11c606a6 (kx 2023-04-11 01:18:34 +0300 2546)   pid_t  p = (pid_t) -1;
11c606a6 (kx 2023-04-11 01:18:34 +0300 2547)   int    rc;
11c606a6 (kx 2023-04-11 01:18:34 +0300 2548) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 2549)   int   len = 0;
11c606a6 (kx 2023-04-11 01:18:34 +0300 2550)   char *cmd = NULL;
11c606a6 (kx 2023-04-11 01:18:34 +0300 2551) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 2552)   bzero( (void *)&st, sizeof( struct stat ) );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2553) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 2554)   /******************************************************************
11c606a6 (kx 2023-04-11 01:18:34 +0300 2555)     Do not try to verify signature if '.asc' file is not accessible:
11c606a6 (kx 2023-04-11 01:18:34 +0300 2556)    */
11c606a6 (kx 2023-04-11 01:18:34 +0300 2557)   if( stat( (const char *)asc_fname, &st ) == -1 ) return;
11c606a6 (kx 2023-04-11 01:18:34 +0300 2558) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 2559)   cmd = (char *)malloc( (size_t)PATH_MAX );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2560)   if( !cmd ) { FATAL_ERROR( "Cannot allocate memory" ); }
11c606a6 (kx 2023-04-11 01:18:34 +0300 2561)   bzero( (void *)cmd, PATH_MAX );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2562) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 2563)   len = snprintf( &cmd[0], PATH_MAX,
11c606a6 (kx 2023-04-11 01:18:34 +0300 2564)                   "gpg2 --verify %s %s > /dev/null 2>&1",
11c606a6 (kx 2023-04-11 01:18:34 +0300 2565)                   asc_fname, pkg_fname );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2566)   if( len == 0 || len == PATH_MAX - 1 )
11c606a6 (kx 2023-04-11 01:18:34 +0300 2567)   {
11c606a6 (kx 2023-04-11 01:18:34 +0300 2568)     FATAL_ERROR( "Cannot verify GPG2 signature of '%s-%s' package", pkgname, pkgver );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2569)   }
11c606a6 (kx 2023-04-11 01:18:34 +0300 2570)   p = sys_exec_command( cmd );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2571)   rc = sys_wait_command( p, (char *)NULL, PATH_MAX );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2572) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 2573)   free( cmd );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2574) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 2575)   if( rc != 0 )
11c606a6 (kx 2023-04-11 01:18:34 +0300 2576)   {
11c606a6 (kx 2023-04-11 01:18:34 +0300 2577)     exit_status = 51;
11c606a6 (kx 2023-04-11 01:18:34 +0300 2578) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 2579)     if( install_mode != CONSOLE )
11c606a6 (kx 2023-04-11 01:18:34 +0300 2580)     {
11c606a6 (kx 2023-04-11 01:18:34 +0300 2581) #if defined( HAVE_DIALOG )
11c606a6 (kx 2023-04-11 01:18:34 +0300 2582)       info_pkg_box( "Install:", pkgname, pkgver, strprio( priority, 0 ),
11c606a6 (kx 2023-04-11 01:18:34 +0300 2583)                     "\n\\Z1Cannot verify GPG2 signature of the package.\\Zn\n", 5, 0, 0 );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2584) #else
11c606a6 (kx 2023-04-11 01:18:34 +0300 2585)       fprintf( stdout, "\nGPG2 signature verification of '%s-%s' package returned error status.\n\n", pkgname, pkgver );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2586) #endif
11c606a6 (kx 2023-04-11 01:18:34 +0300 2587)     }
11c606a6 (kx 2023-04-11 01:18:34 +0300 2588)     else
11c606a6 (kx 2023-04-11 01:18:34 +0300 2589)     {
11c606a6 (kx 2023-04-11 01:18:34 +0300 2590)       fprintf( stdout, "\nGPG2 signature verification of '%s-%s' package returned error status.\n\n", pkgname, pkgver );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2591)     }
11c606a6 (kx 2023-04-11 01:18:34 +0300 2592) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 2593)     if( tmpdir ) { _rm_tmpdir( (const char *)tmpdir ); free( tmpdir ); }
11c606a6 (kx 2023-04-11 01:18:34 +0300 2594)     free_resources();
11c606a6 (kx 2023-04-11 01:18:34 +0300 2595)     exit( exit_status );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2596)   }
11c606a6 (kx 2023-04-11 01:18:34 +0300 2597) }
11c606a6 (kx 2023-04-11 01:18:34 +0300 2598) #endif
11c606a6 (kx 2023-04-11 01:18:34 +0300 2599) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 2600) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 2601) static void dialogrc( void )
11c606a6 (kx 2023-04-11 01:18:34 +0300 2602) {
11c606a6 (kx 2023-04-11 01:18:34 +0300 2603)   struct stat st;
11c606a6 (kx 2023-04-11 01:18:34 +0300 2604)   char  *tmp = NULL;
11c606a6 (kx 2023-04-11 01:18:34 +0300 2605) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 2606)   tmp = (char *)malloc( (size_t)PATH_MAX );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2607)   if( !tmp ) { FATAL_ERROR( "Cannot allocate memory" ); }
11c606a6 (kx 2023-04-11 01:18:34 +0300 2608)   bzero( (void *)tmp, PATH_MAX );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2609) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 2610)   /* imagine that the utility is in /sbin directory: */
11c606a6 (kx 2023-04-11 01:18:34 +0300 2611)   (void)sprintf( &tmp[0], "%s/../usr/share/%s/.dialogrc", selfdir, PACKAGE_NAME );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2612)   if( stat( (const char *)&tmp[0], &st ) == -1 )
11c606a6 (kx 2023-04-11 01:18:34 +0300 2613)   {
11c606a6 (kx 2023-04-11 01:18:34 +0300 2614)     /* finaly assume that /usr/sbin is a sbindir: */
11c606a6 (kx 2023-04-11 01:18:34 +0300 2615)     (void)sprintf( &tmp[0], "%s/../../usr/share/%s/.dialogrc", selfdir, PACKAGE_NAME );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2616)   }
11c606a6 (kx 2023-04-11 01:18:34 +0300 2617) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 2618)   setenv( "DIALOGRC", (const char *)&tmp[0], 1 );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2619) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 2620)   free( tmp );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2621) }
11c606a6 (kx 2023-04-11 01:18:34 +0300 2622) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 2623) static char *get_curdir( void )
11c606a6 (kx 2023-04-11 01:18:34 +0300 2624) {
11c606a6 (kx 2023-04-11 01:18:34 +0300 2625)   char *cwd = NULL;
11c606a6 (kx 2023-04-11 01:18:34 +0300 2626) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 2627)   cwd = (char *)malloc( PATH_MAX );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2628)   if( !cwd ) { FATAL_ERROR( "Cannot allocate memory" ); }
11c606a6 (kx 2023-04-11 01:18:34 +0300 2629)   bzero( (void *)cwd, PATH_MAX );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2630) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 2631)   if( getcwd( cwd, (size_t)PATH_MAX ) != NULL )
11c606a6 (kx 2023-04-11 01:18:34 +0300 2632)   {
11c606a6 (kx 2023-04-11 01:18:34 +0300 2633)     char *p = NULL;
11c606a6 (kx 2023-04-11 01:18:34 +0300 2634)     remove_trailing_slash( cwd );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2635)     p = xstrdup( (const char *)cwd );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2636)     free( cwd );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2637)     return p;
11c606a6 (kx 2023-04-11 01:18:34 +0300 2638)   }
11c606a6 (kx 2023-04-11 01:18:34 +0300 2639)   else
11c606a6 (kx 2023-04-11 01:18:34 +0300 2640)   {
11c606a6 (kx 2023-04-11 01:18:34 +0300 2641)     FATAL_ERROR( "Cannot get absolute path to current directory" );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2642)   }
11c606a6 (kx 2023-04-11 01:18:34 +0300 2643) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 2644)   return (char *)NULL;
11c606a6 (kx 2023-04-11 01:18:34 +0300 2645) }
11c606a6 (kx 2023-04-11 01:18:34 +0300 2646) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 2647) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 2648) /*********************************************
11c606a6 (kx 2023-04-11 01:18:34 +0300 2649)   Get directory where this program is placed:
11c606a6 (kx 2023-04-11 01:18:34 +0300 2650)  */
11c606a6 (kx 2023-04-11 01:18:34 +0300 2651) char *get_selfdir( void )
11c606a6 (kx 2023-04-11 01:18:34 +0300 2652) {
11c606a6 (kx 2023-04-11 01:18:34 +0300 2653)   char    *buf = NULL;
11c606a6 (kx 2023-04-11 01:18:34 +0300 2654)   ssize_t  len;
11c606a6 (kx 2023-04-11 01:18:34 +0300 2655) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 2656)   buf = (char *)malloc( PATH_MAX );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2657)   if( !buf )
11c606a6 (kx 2023-04-11 01:18:34 +0300 2658)   {
11c606a6 (kx 2023-04-11 01:18:34 +0300 2659)     FATAL_ERROR( "Cannot allocate memory" );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2660)   }
11c606a6 (kx 2023-04-11 01:18:34 +0300 2661) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 2662)   bzero( (void *)buf, PATH_MAX );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2663)   len = readlink( "/proc/self/exe", buf, (size_t)PATH_MAX );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2664)   if( len > 0 && len < PATH_MAX )
11c606a6 (kx 2023-04-11 01:18:34 +0300 2665)   {
11c606a6 (kx 2023-04-11 01:18:34 +0300 2666)     char *p = xstrdup( (const char *)dirname( buf ) );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2667)     free( buf );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2668)     return p;
11c606a6 (kx 2023-04-11 01:18:34 +0300 2669)   }
11c606a6 (kx 2023-04-11 01:18:34 +0300 2670)   FATAL_ERROR( "Cannot determine self directory. Please mount /proc filesystem" );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2671) }
11c606a6 (kx 2023-04-11 01:18:34 +0300 2672) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 2673) void set_stack_size( void )
11c606a6 (kx 2023-04-11 01:18:34 +0300 2674) {
11c606a6 (kx 2023-04-11 01:18:34 +0300 2675)   const rlim_t   stack_size = 16 * 1024 * 1024; /* min stack size = 16 MB */
11c606a6 (kx 2023-04-11 01:18:34 +0300 2676)   struct rlimit  rl;
11c606a6 (kx 2023-04-11 01:18:34 +0300 2677)   int ret;
11c606a6 (kx 2023-04-11 01:18:34 +0300 2678) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 2679)   ret = getrlimit( RLIMIT_STACK, &rl );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2680)   if( ret == 0 )
11c606a6 (kx 2023-04-11 01:18:34 +0300 2681)   {
11c606a6 (kx 2023-04-11 01:18:34 +0300 2682)     if( rl.rlim_cur < stack_size )
11c606a6 (kx 2023-04-11 01:18:34 +0300 2683)     {
11c606a6 (kx 2023-04-11 01:18:34 +0300 2684)       rl.rlim_cur = stack_size;
11c606a6 (kx 2023-04-11 01:18:34 +0300 2685)       ret = setrlimit( RLIMIT_STACK, &rl );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2686)       if( ret != 0 )
11c606a6 (kx 2023-04-11 01:18:34 +0300 2687)       {
11c606a6 (kx 2023-04-11 01:18:34 +0300 2688)         fprintf(stderr, "setrlimit returned result = %d\n", ret);
11c606a6 (kx 2023-04-11 01:18:34 +0300 2689)         FATAL_ERROR( "Cannot set stack size" );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2690)       }
11c606a6 (kx 2023-04-11 01:18:34 +0300 2691)     }
11c606a6 (kx 2023-04-11 01:18:34 +0300 2692)   }
11c606a6 (kx 2023-04-11 01:18:34 +0300 2693) }
11c606a6 (kx 2023-04-11 01:18:34 +0300 2694) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 2695) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 2696) int main( int argc, char *argv[] )
11c606a6 (kx 2023-04-11 01:18:34 +0300 2697) {
11c606a6 (kx 2023-04-11 01:18:34 +0300 2698)   gid_t  gid;
11c606a6 (kx 2023-04-11 01:18:34 +0300 2699) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 2700)   set_signal_handlers();
11c606a6 (kx 2023-04-11 01:18:34 +0300 2701) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 2702)   gid = getgid();
11c606a6 (kx 2023-04-11 01:18:34 +0300 2703)   setgroups( 1, &gid );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2704) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 2705)   fatal_error_hook = fatal_error_actions;
11c606a6 (kx 2023-04-11 01:18:34 +0300 2706) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 2707)   selfdir = get_selfdir();
11c606a6 (kx 2023-04-11 01:18:34 +0300 2708)   curdir  = get_curdir();
11c606a6 (kx 2023-04-11 01:18:34 +0300 2709)   dialogrc();
11c606a6 (kx 2023-04-11 01:18:34 +0300 2710) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 2711)   errlog = stderr;
11c606a6 (kx 2023-04-11 01:18:34 +0300 2712) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 2713)   program = basename( argv[0] );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2714)   get_args( argc, argv );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2715) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 2716)   /* set_stack_size(); */
11c606a6 (kx 2023-04-11 01:18:34 +0300 2717) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 2718)   tmpdir = _mk_tmpdir();
11c606a6 (kx 2023-04-11 01:18:34 +0300 2719)   if( !tmpdir )
11c606a6 (kx 2023-04-11 01:18:34 +0300 2720)   {
11c606a6 (kx 2023-04-11 01:18:34 +0300 2721)     FATAL_ERROR( "Cannot create temporary directory" );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2722)   }
11c606a6 (kx 2023-04-11 01:18:34 +0300 2723) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 2724) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 2725)   /************************************************************
11c606a6 (kx 2023-04-11 01:18:34 +0300 2726)     Getting Service Files, reading pkginfo, preserving pkglog:
11c606a6 (kx 2023-04-11 01:18:34 +0300 2727)    */
11c606a6 (kx 2023-04-11 01:18:34 +0300 2728)   read_service_files();
11c606a6 (kx 2023-04-11 01:18:34 +0300 2729) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 2730)   /****************************************************
11c606a6 (kx 2023-04-11 01:18:34 +0300 2731)     Checking whether the package is already installed:
11c606a6 (kx 2023-04-11 01:18:34 +0300 2732)    */
11c606a6 (kx 2023-04-11 01:18:34 +0300 2733)   check_package();
11c606a6 (kx 2023-04-11 01:18:34 +0300 2734) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 2735)   if( rqck ) check_requires();
11c606a6 (kx 2023-04-11 01:18:34 +0300 2736) #if defined( HAVE_GPG2 )
11c606a6 (kx 2023-04-11 01:18:34 +0300 2737)   if( gpgck ) verify_gpg_signature();
11c606a6 (kx 2023-04-11 01:18:34 +0300 2738) #endif
11c606a6 (kx 2023-04-11 01:18:34 +0300 2739) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 2740)   read_filelist();
11c606a6 (kx 2023-04-11 01:18:34 +0300 2741)   read_restorelinks();
11c606a6 (kx 2023-04-11 01:18:34 +0300 2742) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 2743)   read_description();
11c606a6 (kx 2023-04-11 01:18:34 +0300 2744) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 2745)   if( ask_for_install() )
11c606a6 (kx 2023-04-11 01:18:34 +0300 2746)   {
11c606a6 (kx 2023-04-11 01:18:34 +0300 2747)     /* Terminate installation: */
11c606a6 (kx 2023-04-11 01:18:34 +0300 2748)     if( tmpdir ) { _rm_tmpdir( (const char *)tmpdir ); free( tmpdir ); }
11c606a6 (kx 2023-04-11 01:18:34 +0300 2749)     free_resources();
11c606a6 (kx 2023-04-11 01:18:34 +0300 2750)     exit( exit_status );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2751)   }
11c606a6 (kx 2023-04-11 01:18:34 +0300 2752) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 2753)   show_install_progress();
11c606a6 (kx 2023-04-11 01:18:34 +0300 2754) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 2755)   /*************
11c606a6 (kx 2023-04-11 01:18:34 +0300 2756)     DO INSTALL:
11c606a6 (kx 2023-04-11 01:18:34 +0300 2757)    */
11c606a6 (kx 2023-04-11 01:18:34 +0300 2758)   pre_install_routine();
11c606a6 (kx 2023-04-11 01:18:34 +0300 2759)   uncompress_package();
11c606a6 (kx 2023-04-11 01:18:34 +0300 2760)   restore_links();
11c606a6 (kx 2023-04-11 01:18:34 +0300 2761)   post_install_routine();
11c606a6 (kx 2023-04-11 01:18:34 +0300 2762)   finalize_installation();
11c606a6 (kx 2023-04-11 01:18:34 +0300 2763) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 2764)   fprintf( stdout, "\033[3A" ); /* move cursor up 3 lines */
11c606a6 (kx 2023-04-11 01:18:34 +0300 2765) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 2766)   if( (install_mode != CONSOLE) && (install_mode == MENUDIALOG) )
11c606a6 (kx 2023-04-11 01:18:34 +0300 2767)   {
11c606a6 (kx 2023-04-11 01:18:34 +0300 2768) #if defined( HAVE_DIALOG )
11c606a6 (kx 2023-04-11 01:18:34 +0300 2769)     info_pkg_box( "Install:", pkgname, pkgver, strprio( priority, 0 ),
11c606a6 (kx 2023-04-11 01:18:34 +0300 2770)                   "\nPackage has been installed.\n", 5, 0, 0 );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2771) #else
11c606a6 (kx 2023-04-11 01:18:34 +0300 2772)     fprintf( stdout, "\nPackage '%s-%s' has been installed.\n\n", pkgname, pkgver );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2773) #endif
11c606a6 (kx 2023-04-11 01:18:34 +0300 2774)   }
11c606a6 (kx 2023-04-11 01:18:34 +0300 2775)   else
11c606a6 (kx 2023-04-11 01:18:34 +0300 2776)   {
11c606a6 (kx 2023-04-11 01:18:34 +0300 2777)     if( (install_mode != INFODIALOG) )
11c606a6 (kx 2023-04-11 01:18:34 +0300 2778)     {
11c606a6 (kx 2023-04-11 01:18:34 +0300 2779)       fprintf( stdout, "\nPackage '%s-%s' has been installed.\n\n", pkgname, pkgver );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2780)     }
11c606a6 (kx 2023-04-11 01:18:34 +0300 2781)   }
11c606a6 (kx 2023-04-11 01:18:34 +0300 2782) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 2783)   setup_log( "Package '%s-%s' has been installed", pkgname, pkgver );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2784) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 2785)   if( tmpdir ) { _rm_tmpdir( (const char *)tmpdir ); free( tmpdir ); }
11c606a6 (kx 2023-04-11 01:18:34 +0300 2786)   free_resources();
11c606a6 (kx 2023-04-11 01:18:34 +0300 2787) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 2788)   exit( exit_status );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2789) }