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 "update-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, *remlog_fname = 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, *rtmpdir = 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, reinstall = 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) static char *installed_version = NULL;
11c606a6 (kx 2023-04-11 01:18:34 +0300  101) static char *installed_group   = NULL;
11c606a6 (kx 2023-04-11 01:18:34 +0300  102) 
11c606a6 (kx 2023-04-11 01:18:34 +0300  103) enum _update_mode {
11c606a6 (kx 2023-04-11 01:18:34 +0300  104)   CONSOLE = 0,
11c606a6 (kx 2023-04-11 01:18:34 +0300  105)   INFODIALOG,
11c606a6 (kx 2023-04-11 01:18:34 +0300  106)   MENUDIALOG
11c606a6 (kx 2023-04-11 01:18:34 +0300  107) } update_mode = CONSOLE;
11c606a6 (kx 2023-04-11 01:18:34 +0300  108) 
11c606a6 (kx 2023-04-11 01:18:34 +0300  109) enum _priority {
11c606a6 (kx 2023-04-11 01:18:34 +0300  110)   REQUIRED = 0, /* synonims: REQUIRED    | required    | REQ | req */
11c606a6 (kx 2023-04-11 01:18:34 +0300  111)   RECOMMENDED,  /* synonims: RECOMMENDED | recommended | REC | rec */
11c606a6 (kx 2023-04-11 01:18:34 +0300  112)   OPTIONAL,     /* synonims: OPTIONAL    | optional    | OPT | opt */
11c606a6 (kx 2023-04-11 01:18:34 +0300  113)   SKIP          /* synonims: SKIP        | skip        | SKP | skp */
11c606a6 (kx 2023-04-11 01:18:34 +0300  114) } priority = REQUIRED;
11c606a6 (kx 2023-04-11 01:18:34 +0300  115) 
11c606a6 (kx 2023-04-11 01:18:34 +0300  116) enum _procedure
11c606a6 (kx 2023-04-11 01:18:34 +0300  117) {
11c606a6 (kx 2023-04-11 01:18:34 +0300  118)   INSTALL = 0, /* 'install' */
11c606a6 (kx 2023-04-11 01:18:34 +0300  119)   UPDATE       /* 'update'  */
11c606a6 (kx 2023-04-11 01:18:34 +0300  120) } procedure = UPDATE;
11c606a6 (kx 2023-04-11 01:18:34 +0300  121) 
11c606a6 (kx 2023-04-11 01:18:34 +0300  122) enum _input_type {
11c606a6 (kx 2023-04-11 01:18:34 +0300  123)   IFMT_PKG = 0,
11c606a6 (kx 2023-04-11 01:18:34 +0300  124)   IFMT_LOG,
11c606a6 (kx 2023-04-11 01:18:34 +0300  125) 
11c606a6 (kx 2023-04-11 01:18:34 +0300  126)   IFMT_UNKNOWN
11c606a6 (kx 2023-04-11 01:18:34 +0300  127) } input_format = IFMT_PKG;
11c606a6 (kx 2023-04-11 01:18:34 +0300  128) 
11c606a6 (kx 2023-04-11 01:18:34 +0300  129) char  uncompress = '\0';
11c606a6 (kx 2023-04-11 01:18:34 +0300  130) 
11c606a6 (kx 2023-04-11 01:18:34 +0300  131) static struct dlist *rdirs  = NULL;
11c606a6 (kx 2023-04-11 01:18:34 +0300  132) static struct dlist *rfiles = NULL;
11c606a6 (kx 2023-04-11 01:18:34 +0300  133) static struct dlist *rlinks = NULL;
11c606a6 (kx 2023-04-11 01:18:34 +0300  134) 
11c606a6 (kx 2023-04-11 01:18:34 +0300  135) static struct dlist *dirs  = NULL;
11c606a6 (kx 2023-04-11 01:18:34 +0300  136) static struct dlist *files = NULL;
11c606a6 (kx 2023-04-11 01:18:34 +0300  137) static struct dlist *links = NULL;
11c606a6 (kx 2023-04-11 01:18:34 +0300  138) 
11c606a6 (kx 2023-04-11 01:18:34 +0300  139) static void free_list( struct dlist *list );
11c606a6 (kx 2023-04-11 01:18:34 +0300  140) 
11c606a6 (kx 2023-04-11 01:18:34 +0300  141) 
11c606a6 (kx 2023-04-11 01:18:34 +0300  142) #define FREE_PKGINFO_VARIABLES() \
11c606a6 (kx 2023-04-11 01:18:34 +0300  143)   if( pkgname )           { free( pkgname );           } pkgname = NULL;            \
11c606a6 (kx 2023-04-11 01:18:34 +0300  144)   if( pkgver )            { free( pkgver );            } pkgver = NULL;             \
11c606a6 (kx 2023-04-11 01:18:34 +0300  145)   if( arch )              { free( arch );              } arch = NULL;               \
11c606a6 (kx 2023-04-11 01:18:34 +0300  146)   if( distroname )        { free( distroname );        } distroname = NULL;         \
11c606a6 (kx 2023-04-11 01:18:34 +0300  147)   if( distrover )         { free( distrover );         } distrover = NULL;          \
11c606a6 (kx 2023-04-11 01:18:34 +0300  148)   if( group )             { free( group );             } group = NULL;              \
11c606a6 (kx 2023-04-11 01:18:34 +0300  149)   if( short_description ) { free( short_description ); } short_description = NULL;  \
11c606a6 (kx 2023-04-11 01:18:34 +0300  150)   if( description )       { free( description );       } description = NULL;        \
11c606a6 (kx 2023-04-11 01:18:34 +0300  151)   if( url )               { free( url );               } url = NULL;                \
11c606a6 (kx 2023-04-11 01:18:34 +0300  152)   if( license )           { free( license );           } license = NULL;            \
11c606a6 (kx 2023-04-11 01:18:34 +0300  153)   if( uncompressed_size ) { free( uncompressed_size ); } uncompressed_size = NULL;  \
11c606a6 (kx 2023-04-11 01:18:34 +0300  154)   if( compressed_size )   { free( compressed_size );   } compressed_size = NULL;    \
11c606a6 (kx 2023-04-11 01:18:34 +0300  155)   if( total_files )       { free( total_files );       } total_files = NULL;        \
11c606a6 (kx 2023-04-11 01:18:34 +0300  156)   if( installed_version ) { free( installed_version ); } installed_version = NULL;  \
11c606a6 (kx 2023-04-11 01:18:34 +0300  157)   if( installed_group )   { free( installed_group );   } installed_group = NULL
11c606a6 (kx 2023-04-11 01:18:34 +0300  158) 
11c606a6 (kx 2023-04-11 01:18:34 +0300  159) void free_resources()
11c606a6 (kx 2023-04-11 01:18:34 +0300  160) {
11c606a6 (kx 2023-04-11 01:18:34 +0300  161)   if( root )          { free( root );          root          = NULL; }
11c606a6 (kx 2023-04-11 01:18:34 +0300  162)   if( pkgs_path )     { free( pkgs_path );     pkgs_path     = NULL; }
11c606a6 (kx 2023-04-11 01:18:34 +0300  163)   if( rempkgs_path )  { free( rempkgs_path );  rempkgs_path  = NULL; }
11c606a6 (kx 2023-04-11 01:18:34 +0300  164)   if( pkg_fname )     { free( pkg_fname );     pkg_fname     = NULL; }
11c606a6 (kx 2023-04-11 01:18:34 +0300  165)   if( asc_fname )     { free( asc_fname );     asc_fname     = NULL; }
11c606a6 (kx 2023-04-11 01:18:34 +0300  166)   if( pkglog_fname )  { free( pkglog_fname );  pkglog_fname  = NULL; }
11c606a6 (kx 2023-04-11 01:18:34 +0300  167)   if( remlog_fname )  { free( remlog_fname );  remlog_fname  = NULL; }
11c606a6 (kx 2023-04-11 01:18:34 +0300  168) 
11c606a6 (kx 2023-04-11 01:18:34 +0300  169)   if( pkglist_fname ) { free( pkglist_fname ); pkglist_fname = NULL; }
11c606a6 (kx 2023-04-11 01:18:34 +0300  170) 
11c606a6 (kx 2023-04-11 01:18:34 +0300  171)   if( rdirs )         { free_list( rdirs );    rdirs         = NULL; }
11c606a6 (kx 2023-04-11 01:18:34 +0300  172)   if( rfiles )        { free_list( rfiles );   rfiles        = NULL; }
11c606a6 (kx 2023-04-11 01:18:34 +0300  173)   if( rlinks )        { free_list( rlinks );   rlinks        = NULL; }
11c606a6 (kx 2023-04-11 01:18:34 +0300  174) 
11c606a6 (kx 2023-04-11 01:18:34 +0300  175)   if( dirs )          { free_list( dirs );     dirs          = NULL; }
11c606a6 (kx 2023-04-11 01:18:34 +0300  176)   if( files )         { free_list( files );    files         = NULL; }
11c606a6 (kx 2023-04-11 01:18:34 +0300  177)   if( links )         { free_list( links );    links         = NULL; }
11c606a6 (kx 2023-04-11 01:18:34 +0300  178) 
11c606a6 (kx 2023-04-11 01:18:34 +0300  179)   if( rtmpdir )       { free( rtmpdir );       rtmpdir       = NULL; }
11c606a6 (kx 2023-04-11 01:18:34 +0300  180)   if( curdir )        { free( curdir );        curdir        = NULL; }
11c606a6 (kx 2023-04-11 01:18:34 +0300  181)   if( log_fname )     { free( log_fname );     log_fname     = NULL; }
11c606a6 (kx 2023-04-11 01:18:34 +0300  182) 
11c606a6 (kx 2023-04-11 01:18:34 +0300  183)   if( selfdir )       { free( selfdir );       selfdir       = NULL; }
11c606a6 (kx 2023-04-11 01:18:34 +0300  184) 
11c606a6 (kx 2023-04-11 01:18:34 +0300  185)   FREE_PKGINFO_VARIABLES();
11c606a6 (kx 2023-04-11 01:18:34 +0300  186) }
11c606a6 (kx 2023-04-11 01:18:34 +0300  187) 
11c606a6 (kx 2023-04-11 01:18:34 +0300  188) void usage()
11c606a6 (kx 2023-04-11 01:18:34 +0300  189) {
11c606a6 (kx 2023-04-11 01:18:34 +0300  190)   free_resources();
11c606a6 (kx 2023-04-11 01:18:34 +0300  191) 
11c606a6 (kx 2023-04-11 01:18:34 +0300  192)   fprintf( stdout, "\n" );
11c606a6 (kx 2023-04-11 01:18:34 +0300  193)   fprintf( stdout, "Usage: %s [options] <package>\n", program );
11c606a6 (kx 2023-04-11 01:18:34 +0300  194)   fprintf( stdout, "\n" );
11c606a6 (kx 2023-04-11 01:18:34 +0300  195)   fprintf( stdout, "Update package.\n" );
11c606a6 (kx 2023-04-11 01:18:34 +0300  196)   fprintf( stdout, "\n" );
11c606a6 (kx 2023-04-11 01:18:34 +0300  197)   fprintf( stdout, "Options:\n" );
11c606a6 (kx 2023-04-11 01:18:34 +0300  198)   fprintf( stdout, "  -h,--help                     Display this information.\n" );
11c606a6 (kx 2023-04-11 01:18:34 +0300  199)   fprintf( stdout, "  -v,--version                  Display the version of %s utility.\n", program );
11c606a6 (kx 2023-04-11 01:18:34 +0300  200)   fprintf( stdout, "  -a,--always-ask               Used with menudialog mode: always ask\n" );
11c606a6 (kx 2023-04-11 01:18:34 +0300  201)   fprintf( stdout, "                                if a package should be updated regardless\n" );
11c606a6 (kx 2023-04-11 01:18:34 +0300  202)   fprintf( stdout, "                                of what the package priority is. Without\n" );
11c606a6 (kx 2023-04-11 01:18:34 +0300  203)   fprintf( stdout, "                                this option, if the priority is equal to\n" );
11c606a6 (kx 2023-04-11 01:18:34 +0300  204)   fprintf( stdout, "                                REQUIRED, the package is updateded without\n" );
11c606a6 (kx 2023-04-11 01:18:34 +0300  205)   fprintf( stdout, "                                asking for confirmation the update.\n" );
11c606a6 (kx 2023-04-11 01:18:34 +0300  206)   fprintf( stdout, "  -c,--check-requires           Check package requires before update.\n" );
11c606a6 (kx 2023-04-11 01:18:34 +0300  207) #if defined( HAVE_GPG2 )
11c606a6 (kx 2023-04-11 01:18:34 +0300  208)   fprintf( stdout, "  -g,--gpg-verify               Verify GPG2 signature. The signature must be\n" );
11c606a6 (kx 2023-04-11 01:18:34 +0300  209)   fprintf( stdout, "                                saved in a file whose name is the same as the\n" );
11c606a6 (kx 2023-04-11 01:18:34 +0300  210)   fprintf( stdout, "                                package file name, but with the extension '.asc'\n" );
11c606a6 (kx 2023-04-11 01:18:34 +0300  211)   fprintf( stdout, "                                and located in the same directory as the package.\n" );
11c606a6 (kx 2023-04-11 01:18:34 +0300  212) #endif
11c606a6 (kx 2023-04-11 01:18:34 +0300  213)   fprintf( stdout, "  --ignore-chrefs-errors        Ignore change references errors (code: 48).\n" );
a745159c (kx 2023-10-23 21:39:58 +0300  214)   fprintf( stdout, "  --disable-chrefs              Do not manage references to the package.\n" );
11c606a6 (kx 2023-04-11 01:18:34 +0300  215) #if defined( HAVE_DIALOG )
11c606a6 (kx 2023-04-11 01:18:34 +0300  216)   fprintf( stdout, "  -i,--info-dialog              Show package description during update\n" );
11c606a6 (kx 2023-04-11 01:18:34 +0300  217)   fprintf( stdout, "                                process using ncurses dialog.\n" );
11c606a6 (kx 2023-04-11 01:18:34 +0300  218)   fprintf( stdout, "  -m,--menu-dialog              Ask for confirmation the update,\n" );
11c606a6 (kx 2023-04-11 01:18:34 +0300  219)   fprintf( stdout, "                                unless the priority is REQUIRED.\n" );
11c606a6 (kx 2023-04-11 01:18:34 +0300  220) #endif
11c606a6 (kx 2023-04-11 01:18:34 +0300  221)   fprintf( stdout, "  -l,--pkglist=<FILENAME>       Specify a different package list file\n" );
11c606a6 (kx 2023-04-11 01:18:34 +0300  222)   fprintf( stdout, "                                to use for read package priority and type\n" );
11c606a6 (kx 2023-04-11 01:18:34 +0300  223)   fprintf( stdout, "                                of install procedure. By default used the\n" );
11c606a6 (kx 2023-04-11 01:18:34 +0300  224)   fprintf( stdout, "                                '.pkglist' file found in the directory\n" );
11c606a6 (kx 2023-04-11 01:18:34 +0300  225)   fprintf( stdout, "                                where source package is placed.\n" );
11c606a6 (kx 2023-04-11 01:18:34 +0300  226)   fprintf( stdout, "  -p,--priority=<required|recommended|optional|skip>\n" );
11c606a6 (kx 2023-04-11 01:18:34 +0300  227)   fprintf( stdout, "                                Provides a priority of package instead of\n" );
11c606a6 (kx 2023-04-11 01:18:34 +0300  228)   fprintf( stdout, "                                the priority defined in the .pkglist file.\n" );
11c606a6 (kx 2023-04-11 01:18:34 +0300  229)   fprintf( stdout, "  --reinstall                   Reinstall even if the package is already\n" );
11c606a6 (kx 2023-04-11 01:18:34 +0300  230)   fprintf( stdout, "                                installed correctly.\n" );
11c606a6 (kx 2023-04-11 01:18:34 +0300  231)   fprintf( stdout, "                                Without this option, the already installed package\n" );
11c606a6 (kx 2023-04-11 01:18:34 +0300  232)   fprintf( stdout, "                                will not be updated. The update procedure will be\n" );
11c606a6 (kx 2023-04-11 01:18:34 +0300  233)   fprintf( stdout, "                                stopped with success return code.\n" );
11c606a6 (kx 2023-04-11 01:18:34 +0300  234)   fprintf( stdout, "  -r,--root=<DIR>               Target rootfs path.\n" );
11c606a6 (kx 2023-04-11 01:18:34 +0300  235)   fprintf( stdout, "\n" );
11c606a6 (kx 2023-04-11 01:18:34 +0300  236)   fprintf( stdout, "Parameter:\n" );
11c606a6 (kx 2023-04-11 01:18:34 +0300  237)   fprintf( stdout, "  <package>                     The PACKAGE tarball.\n" );
11c606a6 (kx 2023-04-11 01:18:34 +0300  238)   fprintf( stdout, "\n" );
11c606a6 (kx 2023-04-11 01:18:34 +0300  239)   fprintf( stdout, "Return codes:\n" );
11c606a6 (kx 2023-04-11 01:18:34 +0300  240)   fprintf( stdout, "  ------+-------------------------------------------------------\n" );
11c606a6 (kx 2023-04-11 01:18:34 +0300  241)   fprintf( stdout, "   code | status\n"  );
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, "     30 | package is not installed\n" );
11c606a6 (kx 2023-04-11 01:18:34 +0300  244)   fprintf( stdout, "    ----+----\n" );
11c606a6 (kx 2023-04-11 01:18:34 +0300  245)   fprintf( stdout, "     41 | update is aborted due to priority=SKIP\n" );
11c606a6 (kx 2023-04-11 01:18:34 +0300  246)   fprintf( stdout, "     42 | .pkglist appointed the 'install' procedure instead\n" );
11c606a6 (kx 2023-04-11 01:18:34 +0300  247)   fprintf( stdout, "     43 | pre-update script returned error status\n" );
11c606a6 (kx 2023-04-11 01:18:34 +0300  248)   fprintf( stdout, "     44 | uncompress process returned error status\n" );
11c606a6 (kx 2023-04-11 01:18:34 +0300  249)   fprintf( stdout, "     45 | restore-links script returned error status\n" );
11c606a6 (kx 2023-04-11 01:18:34 +0300  250)   fprintf( stdout, "     46 | post-update script returned error status\n" );
11c606a6 (kx 2023-04-11 01:18:34 +0300  251)   fprintf( stdout, "     47 | PKGLOG cannot be stored in the Setup Database\n" );
11c606a6 (kx 2023-04-11 01:18:34 +0300  252)   fprintf( stdout, "     48 | references cannot be updated in Setup Database\n" );
11c606a6 (kx 2023-04-11 01:18:34 +0300  253)   fprintf( stdout, "     49 | requires cannot be updated in Setup Database\n" );
11c606a6 (kx 2023-04-11 01:18:34 +0300  254) #if defined( HAVE_GPG2 )
11c606a6 (kx 2023-04-11 01:18:34 +0300  255)   fprintf( stdout, "    ----+----\n" );
11c606a6 (kx 2023-04-11 01:18:34 +0300  256)   fprintf( stdout, "     51 | signature verification returned error status\n" );
11c606a6 (kx 2023-04-11 01:18:34 +0300  257) #endif
11c606a6 (kx 2023-04-11 01:18:34 +0300  258)   fprintf( stdout, "  ------+-------------------------------------------------------\n"  );
11c606a6 (kx 2023-04-11 01:18:34 +0300  259)   fprintf( stdout, "\n" );
11c606a6 (kx 2023-04-11 01:18:34 +0300  260)   fprintf( stdout, "Upon successful completion zero is returned. Other non-zero return\n" );
11c606a6 (kx 2023-04-11 01:18:34 +0300  261)   fprintf( stdout, "codes imply incorrect completion of the update procedure.\n" );
11c606a6 (kx 2023-04-11 01:18:34 +0300  262)   fprintf( stdout, "\n" );
11c606a6 (kx 2023-04-11 01:18:34 +0300  263) 
11c606a6 (kx 2023-04-11 01:18:34 +0300  264)   exit( EXIT_FAILURE );
11c606a6 (kx 2023-04-11 01:18:34 +0300  265) }
11c606a6 (kx 2023-04-11 01:18:34 +0300  266) 
11c606a6 (kx 2023-04-11 01:18:34 +0300  267) void to_lowercase( char *s )
11c606a6 (kx 2023-04-11 01:18:34 +0300  268) {
11c606a6 (kx 2023-04-11 01:18:34 +0300  269)   char *p = s;
11c606a6 (kx 2023-04-11 01:18:34 +0300  270)   while( p && *p ) { int c = *p; *p = tolower( c ); ++p; }
11c606a6 (kx 2023-04-11 01:18:34 +0300  271) }
11c606a6 (kx 2023-04-11 01:18:34 +0300  272) 
11c606a6 (kx 2023-04-11 01:18:34 +0300  273) void to_uppercase( char *s )
11c606a6 (kx 2023-04-11 01:18:34 +0300  274) {
11c606a6 (kx 2023-04-11 01:18:34 +0300  275)   char *p = s;
11c606a6 (kx 2023-04-11 01:18:34 +0300  276)   while( p && *p ) { int c = *p; *p = toupper( c ); ++p; }
11c606a6 (kx 2023-04-11 01:18:34 +0300  277) }
11c606a6 (kx 2023-04-11 01:18:34 +0300  278) 
11c606a6 (kx 2023-04-11 01:18:34 +0300  279) void version()
11c606a6 (kx 2023-04-11 01:18:34 +0300  280) {
11c606a6 (kx 2023-04-11 01:18:34 +0300  281)   char *upper = NULL;
11c606a6 (kx 2023-04-11 01:18:34 +0300  282) 
11c606a6 (kx 2023-04-11 01:18:34 +0300  283)   upper = (char *)alloca( strlen( program ) + 1 );
11c606a6 (kx 2023-04-11 01:18:34 +0300  284) 
11c606a6 (kx 2023-04-11 01:18:34 +0300  285)   strcpy( (char *)upper, (const char *)program );
11c606a6 (kx 2023-04-11 01:18:34 +0300  286)   to_uppercase( upper );
11c606a6 (kx 2023-04-11 01:18:34 +0300  287) 
11c606a6 (kx 2023-04-11 01:18:34 +0300  288)   fprintf( stdout, "%s (%s) %s\n", program, upper, PROGRAM_VERSION );
11c606a6 (kx 2023-04-11 01:18:34 +0300  289) 
11c606a6 (kx 2023-04-11 01:18:34 +0300  290)   fprintf( stdout, "Copyright (C) 2019 Andrey V.Kosteltsev.\n" );
11c606a6 (kx 2023-04-11 01:18:34 +0300  291)   fprintf( stdout, "This is free software.   There is NO warranty; not even\n" );
11c606a6 (kx 2023-04-11 01:18:34 +0300  292)   fprintf( stdout, "for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n" );
11c606a6 (kx 2023-04-11 01:18:34 +0300  293)   fprintf( stdout, "\n" );
11c606a6 (kx 2023-04-11 01:18:34 +0300  294) 
11c606a6 (kx 2023-04-11 01:18:34 +0300  295)   free_resources();
11c606a6 (kx 2023-04-11 01:18:34 +0300  296)   exit( EXIT_SUCCESS );
11c606a6 (kx 2023-04-11 01:18:34 +0300  297) }
11c606a6 (kx 2023-04-11 01:18:34 +0300  298) 
11c606a6 (kx 2023-04-11 01:18:34 +0300  299) 
11c606a6 (kx 2023-04-11 01:18:34 +0300  300) static void remove_trailing_slash( char *dir )
11c606a6 (kx 2023-04-11 01:18:34 +0300  301) {
11c606a6 (kx 2023-04-11 01:18:34 +0300  302)   char *s;
11c606a6 (kx 2023-04-11 01:18:34 +0300  303) 
11c606a6 (kx 2023-04-11 01:18:34 +0300  304)   if( !dir || dir[0] == '\0' ) return;
11c606a6 (kx 2023-04-11 01:18:34 +0300  305) 
11c606a6 (kx 2023-04-11 01:18:34 +0300  306)   s = dir + strlen( dir ) - 1;
11c606a6 (kx 2023-04-11 01:18:34 +0300  307)   while( *s == '/' )
11c606a6 (kx 2023-04-11 01:18:34 +0300  308)   {
11c606a6 (kx 2023-04-11 01:18:34 +0300  309)     *s = '\0'; --s;
11c606a6 (kx 2023-04-11 01:18:34 +0300  310)   }
11c606a6 (kx 2023-04-11 01:18:34 +0300  311) }
11c606a6 (kx 2023-04-11 01:18:34 +0300  312) 
11c606a6 (kx 2023-04-11 01:18:34 +0300  313) 
11c606a6 (kx 2023-04-11 01:18:34 +0300  314) static void bind_asc_extention( char *name )
11c606a6 (kx 2023-04-11 01:18:34 +0300  315) {
11c606a6 (kx 2023-04-11 01:18:34 +0300  316)   char *p = NULL, *q = NULL;
11c606a6 (kx 2023-04-11 01:18:34 +0300  317) 
11c606a6 (kx 2023-04-11 01:18:34 +0300  318)   if( (p = rindex( name, '.' )) && (strlen(p) < 5) )
11c606a6 (kx 2023-04-11 01:18:34 +0300  319)   {
11c606a6 (kx 2023-04-11 01:18:34 +0300  320)     if( !strncmp( p, ".gz",  3 ) ||
11c606a6 (kx 2023-04-11 01:18:34 +0300  321)         !strncmp( p, ".bz2", 4 ) ||
11c606a6 (kx 2023-04-11 01:18:34 +0300  322)         !strncmp( p, ".xz",  3 )   )
11c606a6 (kx 2023-04-11 01:18:34 +0300  323)     {
11c606a6 (kx 2023-04-11 01:18:34 +0300  324)       *p = '\0';
11c606a6 (kx 2023-04-11 01:18:34 +0300  325)       q = rindex( name, '.' );
11c606a6 (kx 2023-04-11 01:18:34 +0300  326)       if( q && (strlen(q) < 5) && !strncmp( q, ".tar", 4 ) )
11c606a6 (kx 2023-04-11 01:18:34 +0300  327)       {
11c606a6 (kx 2023-04-11 01:18:34 +0300  328)         *q = '\0';
11c606a6 (kx 2023-04-11 01:18:34 +0300  329)       }
11c606a6 (kx 2023-04-11 01:18:34 +0300  330)     }
11c606a6 (kx 2023-04-11 01:18:34 +0300  331)     else if( !strncmp( p, ".tar", 4 ) ||
11c606a6 (kx 2023-04-11 01:18:34 +0300  332)              !strncmp( p, ".tbz", 4 ) ||
11c606a6 (kx 2023-04-11 01:18:34 +0300  333)              !strncmp( p, ".tgz", 4 ) ||
11c606a6 (kx 2023-04-11 01:18:34 +0300  334)              !strncmp( p, ".txz", 4 )   )
11c606a6 (kx 2023-04-11 01:18:34 +0300  335)     {
11c606a6 (kx 2023-04-11 01:18:34 +0300  336)       *p = '\0';
11c606a6 (kx 2023-04-11 01:18:34 +0300  337)     }
11c606a6 (kx 2023-04-11 01:18:34 +0300  338)   }
11c606a6 (kx 2023-04-11 01:18:34 +0300  339) 
11c606a6 (kx 2023-04-11 01:18:34 +0300  340)   (void)strcat( name, ".asc" );
11c606a6 (kx 2023-04-11 01:18:34 +0300  341) }
11c606a6 (kx 2023-04-11 01:18:34 +0300  342) 
11c606a6 (kx 2023-04-11 01:18:34 +0300  343) ////////////////////////////////////////////////////
11c606a6 (kx 2023-04-11 01:18:34 +0300  344) //static char *strmode( enum _update_mode mode )
11c606a6 (kx 2023-04-11 01:18:34 +0300  345) //{
11c606a6 (kx 2023-04-11 01:18:34 +0300  346) //  char *p = NULL;
11c606a6 (kx 2023-04-11 01:18:34 +0300  347) //
11c606a6 (kx 2023-04-11 01:18:34 +0300  348) //  switch( mode )
11c606a6 (kx 2023-04-11 01:18:34 +0300  349) //  {
11c606a6 (kx 2023-04-11 01:18:34 +0300  350) //    case CONSOLE:
11c606a6 (kx 2023-04-11 01:18:34 +0300  351) //      p = "CONSOLE";
11c606a6 (kx 2023-04-11 01:18:34 +0300  352) //      break;
11c606a6 (kx 2023-04-11 01:18:34 +0300  353) //    case INFODIALOG:
11c606a6 (kx 2023-04-11 01:18:34 +0300  354) //      p = "INFODIALOG";
11c606a6 (kx 2023-04-11 01:18:34 +0300  355) //      break;
11c606a6 (kx 2023-04-11 01:18:34 +0300  356) //    case MENUDIALOG:
11c606a6 (kx 2023-04-11 01:18:34 +0300  357) //      p = "MENUDIALOG";
11c606a6 (kx 2023-04-11 01:18:34 +0300  358) //      break;
11c606a6 (kx 2023-04-11 01:18:34 +0300  359) //  }
11c606a6 (kx 2023-04-11 01:18:34 +0300  360) //  return p;
11c606a6 (kx 2023-04-11 01:18:34 +0300  361) //}
11c606a6 (kx 2023-04-11 01:18:34 +0300  362) ////////////////////////////////////////////////////
11c606a6 (kx 2023-04-11 01:18:34 +0300  363) 
11c606a6 (kx 2023-04-11 01:18:34 +0300  364) static char *strprio( enum _priority priority, int short_name )
11c606a6 (kx 2023-04-11 01:18:34 +0300  365) {
11c606a6 (kx 2023-04-11 01:18:34 +0300  366)   char *p = NULL;
11c606a6 (kx 2023-04-11 01:18:34 +0300  367) 
11c606a6 (kx 2023-04-11 01:18:34 +0300  368)   switch( priority )
11c606a6 (kx 2023-04-11 01:18:34 +0300  369)   {
11c606a6 (kx 2023-04-11 01:18:34 +0300  370)     case REQUIRED:
11c606a6 (kx 2023-04-11 01:18:34 +0300  371)       p = ( short_name ) ? "REQ" : "required";
11c606a6 (kx 2023-04-11 01:18:34 +0300  372)       break;
11c606a6 (kx 2023-04-11 01:18:34 +0300  373)     case RECOMMENDED:
11c606a6 (kx 2023-04-11 01:18:34 +0300  374)       p = ( short_name ) ? "REC" : "recommended";
11c606a6 (kx 2023-04-11 01:18:34 +0300  375)       break;
11c606a6 (kx 2023-04-11 01:18:34 +0300  376)     case OPTIONAL:
11c606a6 (kx 2023-04-11 01:18:34 +0300  377)       p = ( short_name ) ? "OPT" : "optional";
11c606a6 (kx 2023-04-11 01:18:34 +0300  378)       break;
11c606a6 (kx 2023-04-11 01:18:34 +0300  379)     case SKIP:
11c606a6 (kx 2023-04-11 01:18:34 +0300  380)       p = ( short_name ) ? "SKP" : "skip";
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) static char *strproc( enum _procedure procedure )
11c606a6 (kx 2023-04-11 01:18:34 +0300  387) {
11c606a6 (kx 2023-04-11 01:18:34 +0300  388)   char *p = NULL;
11c606a6 (kx 2023-04-11 01:18:34 +0300  389) 
11c606a6 (kx 2023-04-11 01:18:34 +0300  390)   switch( procedure )
11c606a6 (kx 2023-04-11 01:18:34 +0300  391)   {
11c606a6 (kx 2023-04-11 01:18:34 +0300  392)     case INSTALL:
11c606a6 (kx 2023-04-11 01:18:34 +0300  393)       p = "install";
11c606a6 (kx 2023-04-11 01:18:34 +0300  394)       break;
11c606a6 (kx 2023-04-11 01:18:34 +0300  395)     case UPDATE:
11c606a6 (kx 2023-04-11 01:18:34 +0300  396)       p = "update";
11c606a6 (kx 2023-04-11 01:18:34 +0300  397)       break;
11c606a6 (kx 2023-04-11 01:18:34 +0300  398)   }
11c606a6 (kx 2023-04-11 01:18:34 +0300  399)   return p;
11c606a6 (kx 2023-04-11 01:18:34 +0300  400) }
11c606a6 (kx 2023-04-11 01:18:34 +0300  401) 
11c606a6 (kx 2023-04-11 01:18:34 +0300  402) 
11c606a6 (kx 2023-04-11 01:18:34 +0300  403) static int _mkdir_p( const char *dir, const mode_t mode )
11c606a6 (kx 2023-04-11 01:18:34 +0300  404) {
11c606a6 (kx 2023-04-11 01:18:34 +0300  405)   char  *buf;
11c606a6 (kx 2023-04-11 01:18:34 +0300  406)   char  *p = NULL;
11c606a6 (kx 2023-04-11 01:18:34 +0300  407)   struct stat sb;
11c606a6 (kx 2023-04-11 01:18:34 +0300  408) 
11c606a6 (kx 2023-04-11 01:18:34 +0300  409)   if( !dir ) return -1;
11c606a6 (kx 2023-04-11 01:18:34 +0300  410) 
11c606a6 (kx 2023-04-11 01:18:34 +0300  411)   buf = (char *)alloca( strlen( dir ) + 1 );
11c606a6 (kx 2023-04-11 01:18:34 +0300  412)   strcpy( buf, dir );
11c606a6 (kx 2023-04-11 01:18:34 +0300  413) 
11c606a6 (kx 2023-04-11 01:18:34 +0300  414)   remove_trailing_slash( buf );
11c606a6 (kx 2023-04-11 01:18:34 +0300  415) 
11c606a6 (kx 2023-04-11 01:18:34 +0300  416)   /* check if path exists and is a directory */
11c606a6 (kx 2023-04-11 01:18:34 +0300  417)   if( stat( buf, &sb ) == 0 )
11c606a6 (kx 2023-04-11 01:18:34 +0300  418)   {
11c606a6 (kx 2023-04-11 01:18:34 +0300  419)     if( S_ISDIR(sb.st_mode) )
11c606a6 (kx 2023-04-11 01:18:34 +0300  420)     {
11c606a6 (kx 2023-04-11 01:18:34 +0300  421)       return 0;
11c606a6 (kx 2023-04-11 01:18:34 +0300  422)     }
11c606a6 (kx 2023-04-11 01:18:34 +0300  423)   }
11c606a6 (kx 2023-04-11 01:18:34 +0300  424) 
11c606a6 (kx 2023-04-11 01:18:34 +0300  425)   /* mkdir -p */
11c606a6 (kx 2023-04-11 01:18:34 +0300  426)   for( p = buf + 1; *p; ++p )
11c606a6 (kx 2023-04-11 01:18:34 +0300  427)   {
11c606a6 (kx 2023-04-11 01:18:34 +0300  428)     if( *p == '/' )
11c606a6 (kx 2023-04-11 01:18:34 +0300  429)     {
11c606a6 (kx 2023-04-11 01:18:34 +0300  430)       *p = 0;
11c606a6 (kx 2023-04-11 01:18:34 +0300  431)       /* test path */
11c606a6 (kx 2023-04-11 01:18:34 +0300  432)       if( stat( buf, &sb ) != 0 )
11c606a6 (kx 2023-04-11 01:18:34 +0300  433)       {
11c606a6 (kx 2023-04-11 01:18:34 +0300  434)         /* path does not exist - create directory */
11c606a6 (kx 2023-04-11 01:18:34 +0300  435)         if( mkdir( buf, mode ) < 0 )
11c606a6 (kx 2023-04-11 01:18:34 +0300  436)         {
11c606a6 (kx 2023-04-11 01:18:34 +0300  437)           return -1;
11c606a6 (kx 2023-04-11 01:18:34 +0300  438)         }
11c606a6 (kx 2023-04-11 01:18:34 +0300  439)       } else if( !S_ISDIR(sb.st_mode) )
11c606a6 (kx 2023-04-11 01:18:34 +0300  440)       {
11c606a6 (kx 2023-04-11 01:18:34 +0300  441)         /* not a directory */
11c606a6 (kx 2023-04-11 01:18:34 +0300  442)         return -1;
11c606a6 (kx 2023-04-11 01:18:34 +0300  443)       }
11c606a6 (kx 2023-04-11 01:18:34 +0300  444)       *p = '/';
11c606a6 (kx 2023-04-11 01:18:34 +0300  445)     }
11c606a6 (kx 2023-04-11 01:18:34 +0300  446)   }
11c606a6 (kx 2023-04-11 01:18:34 +0300  447) 
11c606a6 (kx 2023-04-11 01:18:34 +0300  448)   /* test path */
11c606a6 (kx 2023-04-11 01:18:34 +0300  449)   if( stat( buf, &sb ) != 0 )
11c606a6 (kx 2023-04-11 01:18:34 +0300  450)   {
11c606a6 (kx 2023-04-11 01:18:34 +0300  451)     /* path does not exist - create directory */
11c606a6 (kx 2023-04-11 01:18:34 +0300  452)     if( mkdir( buf, mode ) < 0 )
11c606a6 (kx 2023-04-11 01:18:34 +0300  453)     {
11c606a6 (kx 2023-04-11 01:18:34 +0300  454)       return -1;
11c606a6 (kx 2023-04-11 01:18:34 +0300  455)     }
11c606a6 (kx 2023-04-11 01:18:34 +0300  456)   } else if( !S_ISDIR(sb.st_mode) )
11c606a6 (kx 2023-04-11 01:18:34 +0300  457)   {
11c606a6 (kx 2023-04-11 01:18:34 +0300  458)     /* not a directory */
11c606a6 (kx 2023-04-11 01:18:34 +0300  459)     return -1;
11c606a6 (kx 2023-04-11 01:18:34 +0300  460)   }
11c606a6 (kx 2023-04-11 01:18:34 +0300  461) 
11c606a6 (kx 2023-04-11 01:18:34 +0300  462)   return 0;
11c606a6 (kx 2023-04-11 01:18:34 +0300  463) }
11c606a6 (kx 2023-04-11 01:18:34 +0300  464) 
11c606a6 (kx 2023-04-11 01:18:34 +0300  465) static void _rm_tmpdir( const char *dirpath )
11c606a6 (kx 2023-04-11 01:18:34 +0300  466) {
11c606a6 (kx 2023-04-11 01:18:34 +0300  467)   DIR    *dir;
11c606a6 (kx 2023-04-11 01:18:34 +0300  468)   char   *path;
11c606a6 (kx 2023-04-11 01:18:34 +0300  469)   size_t  len;
11c606a6 (kx 2023-04-11 01:18:34 +0300  470) 
11c606a6 (kx 2023-04-11 01:18:34 +0300  471)   struct stat    path_sb, entry_sb;
11c606a6 (kx 2023-04-11 01:18:34 +0300  472)   struct dirent *entry;
11c606a6 (kx 2023-04-11 01:18:34 +0300  473) 
11c606a6 (kx 2023-04-11 01:18:34 +0300  474)   if( stat( dirpath, &path_sb ) == -1 )
11c606a6 (kx 2023-04-11 01:18:34 +0300  475)   {
11c606a6 (kx 2023-04-11 01:18:34 +0300  476)     return; /* stat returns error code; errno is set */
11c606a6 (kx 2023-04-11 01:18:34 +0300  477)   }
11c606a6 (kx 2023-04-11 01:18:34 +0300  478) 
11c606a6 (kx 2023-04-11 01:18:34 +0300  479)   if( S_ISDIR(path_sb.st_mode) == 0 )
11c606a6 (kx 2023-04-11 01:18:34 +0300  480)   {
11c606a6 (kx 2023-04-11 01:18:34 +0300  481)     return; /* dirpath is not a directory */
11c606a6 (kx 2023-04-11 01:18:34 +0300  482)   }
11c606a6 (kx 2023-04-11 01:18:34 +0300  483) 
11c606a6 (kx 2023-04-11 01:18:34 +0300  484)   if( (dir = opendir(dirpath) ) == NULL )
11c606a6 (kx 2023-04-11 01:18:34 +0300  485)   {
11c606a6 (kx 2023-04-11 01:18:34 +0300  486)     return; /* Cannot open direcroty; errno is set */
11c606a6 (kx 2023-04-11 01:18:34 +0300  487)   }
11c606a6 (kx 2023-04-11 01:18:34 +0300  488) 
11c606a6 (kx 2023-04-11 01:18:34 +0300  489)   len = strlen( dirpath );
11c606a6 (kx 2023-04-11 01:18:34 +0300  490) 
11c606a6 (kx 2023-04-11 01:18:34 +0300  491)   while( (entry = readdir( dir )) != NULL)
11c606a6 (kx 2023-04-11 01:18:34 +0300  492)   {
11c606a6 (kx 2023-04-11 01:18:34 +0300  493) 
11c606a6 (kx 2023-04-11 01:18:34 +0300  494)     /* skip entries '.' and '..' */
11c606a6 (kx 2023-04-11 01:18:34 +0300  495)     if( ! strcmp( entry->d_name, "." ) || ! strcmp( entry->d_name, ".." ) ) continue;
11c606a6 (kx 2023-04-11 01:18:34 +0300  496) 
11c606a6 (kx 2023-04-11 01:18:34 +0300  497)     /* determinate a full name of an entry */
11c606a6 (kx 2023-04-11 01:18:34 +0300  498)     path = alloca( len + strlen( entry->d_name ) + 2 );
11c606a6 (kx 2023-04-11 01:18:34 +0300  499)     strcpy( path, dirpath );
11c606a6 (kx 2023-04-11 01:18:34 +0300  500)     strcat( path, "/" );
11c606a6 (kx 2023-04-11 01:18:34 +0300  501)     strcat( path, entry->d_name );
11c606a6 (kx 2023-04-11 01:18:34 +0300  502) 
11c606a6 (kx 2023-04-11 01:18:34 +0300  503)     if( stat( path, &entry_sb ) == 0 )
11c606a6 (kx 2023-04-11 01:18:34 +0300  504)     {
11c606a6 (kx 2023-04-11 01:18:34 +0300  505)       if( S_ISDIR(entry_sb.st_mode) )
11c606a6 (kx 2023-04-11 01:18:34 +0300  506)       {
11c606a6 (kx 2023-04-11 01:18:34 +0300  507)         /* recursively remove a nested directory */
11c606a6 (kx 2023-04-11 01:18:34 +0300  508)         _rm_tmpdir( path );
11c606a6 (kx 2023-04-11 01:18:34 +0300  509)       }
11c606a6 (kx 2023-04-11 01:18:34 +0300  510)       else
11c606a6 (kx 2023-04-11 01:18:34 +0300  511)       {
11c606a6 (kx 2023-04-11 01:18:34 +0300  512)         /* remove a file object */
11c606a6 (kx 2023-04-11 01:18:34 +0300  513)         (void)unlink( path );
11c606a6 (kx 2023-04-11 01:18:34 +0300  514)       }
11c606a6 (kx 2023-04-11 01:18:34 +0300  515)     }
11c606a6 (kx 2023-04-11 01:18:34 +0300  516)     /* else { stat() returns error code; errno is set; and we have to continue the loop } */
11c606a6 (kx 2023-04-11 01:18:34 +0300  517) 
11c606a6 (kx 2023-04-11 01:18:34 +0300  518)   }
11c606a6 (kx 2023-04-11 01:18:34 +0300  519) 
11c606a6 (kx 2023-04-11 01:18:34 +0300  520)   /* remove the devastated directory and close the object of this directory */
11c606a6 (kx 2023-04-11 01:18:34 +0300  521)   (void)rmdir( dirpath );
11c606a6 (kx 2023-04-11 01:18:34 +0300  522) 
11c606a6 (kx 2023-04-11 01:18:34 +0300  523)   closedir( dir );
11c606a6 (kx 2023-04-11 01:18:34 +0300  524) }
11c606a6 (kx 2023-04-11 01:18:34 +0300  525) 
11c606a6 (kx 2023-04-11 01:18:34 +0300  526) static char *_mk_tmpdir( void )
11c606a6 (kx 2023-04-11 01:18:34 +0300  527) {
11c606a6 (kx 2023-04-11 01:18:34 +0300  528)   char   *buf = NULL, *p, *tmp = "/tmp";
11c606a6 (kx 2023-04-11 01:18:34 +0300  529)   size_t  len = 0, size = 0;
11c606a6 (kx 2023-04-11 01:18:34 +0300  530) 
11c606a6 (kx 2023-04-11 01:18:34 +0300  531)   (void)umask( S_IWGRP | S_IWOTH ); /* octal 022 */
11c606a6 (kx 2023-04-11 01:18:34 +0300  532) 
11c606a6 (kx 2023-04-11 01:18:34 +0300  533)   /* Get preferred directory for tmp files */
11c606a6 (kx 2023-04-11 01:18:34 +0300  534)   if( (p = getenv( "TMP" )) != NULL ) {
11c606a6 (kx 2023-04-11 01:18:34 +0300  535)     tmp = p;
11c606a6 (kx 2023-04-11 01:18:34 +0300  536)   }
11c606a6 (kx 2023-04-11 01:18:34 +0300  537)   else if( (p = getenv( "TEMP" )) != NULL ) {
11c606a6 (kx 2023-04-11 01:18:34 +0300  538)     tmp = p;
11c606a6 (kx 2023-04-11 01:18:34 +0300  539)   }
11c606a6 (kx 2023-04-11 01:18:34 +0300  540) 
11c606a6 (kx 2023-04-11 01:18:34 +0300  541)   size = strlen( tmp ) + strlen( DISTRO_NAME ) + strlen( program ) + 12;
11c606a6 (kx 2023-04-11 01:18:34 +0300  542) 
11c606a6 (kx 2023-04-11 01:18:34 +0300  543)   buf = (char *)malloc( size );
11c606a6 (kx 2023-04-11 01:18:34 +0300  544)   if( !buf ) return NULL;
11c606a6 (kx 2023-04-11 01:18:34 +0300  545) 
11c606a6 (kx 2023-04-11 01:18:34 +0300  546)   len = snprintf( buf, size, (const char *)"%s/%s/%s-%.7u", tmp, DISTRO_NAME, program, getpid() );
11c606a6 (kx 2023-04-11 01:18:34 +0300  547)   if( len == 0 || len == size - 1 )
11c606a6 (kx 2023-04-11 01:18:34 +0300  548)   {
11c606a6 (kx 2023-04-11 01:18:34 +0300  549)     free( buf ); return NULL;
11c606a6 (kx 2023-04-11 01:18:34 +0300  550)   }
11c606a6 (kx 2023-04-11 01:18:34 +0300  551) 
11c606a6 (kx 2023-04-11 01:18:34 +0300  552)   _rm_tmpdir( (const char *)&buf[0] );
11c606a6 (kx 2023-04-11 01:18:34 +0300  553) 
11c606a6 (kx 2023-04-11 01:18:34 +0300  554)   if( _mkdir_p( buf, S_IRWXU | S_IRWXG | S_IRWXO ) == 0 )
11c606a6 (kx 2023-04-11 01:18:34 +0300  555)   {
11c606a6 (kx 2023-04-11 01:18:34 +0300  556)     return buf;
11c606a6 (kx 2023-04-11 01:18:34 +0300  557)   }
11c606a6 (kx 2023-04-11 01:18:34 +0300  558) 
11c606a6 (kx 2023-04-11 01:18:34 +0300  559)   free( buf ); return NULL;
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) 
11c606a6 (kx 2023-04-11 01:18:34 +0300  563) void fatal_error_actions( void )
11c606a6 (kx 2023-04-11 01:18:34 +0300  564) {
11c606a6 (kx 2023-04-11 01:18:34 +0300  565)   logmsg( errlog, MSG_NOTICE, "Free resources on FATAL error..." );
11c606a6 (kx 2023-04-11 01:18:34 +0300  566)   if( tmpdir ) { _rm_tmpdir( (const char *)tmpdir ); free( tmpdir ); }
11c606a6 (kx 2023-04-11 01:18:34 +0300  567)   free_resources();
11c606a6 (kx 2023-04-11 01:18:34 +0300  568) }
11c606a6 (kx 2023-04-11 01:18:34 +0300  569) 
11c606a6 (kx 2023-04-11 01:18:34 +0300  570) void sigint( int signum )
11c606a6 (kx 2023-04-11 01:18:34 +0300  571) {
11c606a6 (kx 2023-04-11 01:18:34 +0300  572)   (void)signum;
11c606a6 (kx 2023-04-11 01:18:34 +0300  573) 
11c606a6 (kx 2023-04-11 01:18:34 +0300  574)   if( tmpdir ) { _rm_tmpdir( (const char *)tmpdir ); free( tmpdir ); }
11c606a6 (kx 2023-04-11 01:18:34 +0300  575)   free_resources();
11c606a6 (kx 2023-04-11 01:18:34 +0300  576) }
11c606a6 (kx 2023-04-11 01:18:34 +0300  577) 
11c606a6 (kx 2023-04-11 01:18:34 +0300  578) static void set_signal_handlers()
11c606a6 (kx 2023-04-11 01:18:34 +0300  579) {
11c606a6 (kx 2023-04-11 01:18:34 +0300  580)   struct sigaction  sa;
11c606a6 (kx 2023-04-11 01:18:34 +0300  581)   sigset_t          set;
11c606a6 (kx 2023-04-11 01:18:34 +0300  582) 
11c606a6 (kx 2023-04-11 01:18:34 +0300  583)   memset( &sa, 0, sizeof( sa ) );
11c606a6 (kx 2023-04-11 01:18:34 +0300  584)   sa.sa_handler = sigint;          /* TERM, INT */
11c606a6 (kx 2023-04-11 01:18:34 +0300  585)   sa.sa_flags = SA_RESTART;
11c606a6 (kx 2023-04-11 01:18:34 +0300  586)   sigemptyset( &set );
11c606a6 (kx 2023-04-11 01:18:34 +0300  587)   sigaddset( &set, SIGTERM );
11c606a6 (kx 2023-04-11 01:18:34 +0300  588)   sigaddset( &set, SIGINT );
11c606a6 (kx 2023-04-11 01:18:34 +0300  589)   sa.sa_mask = set;
11c606a6 (kx 2023-04-11 01:18:34 +0300  590)   sigaction( SIGTERM, &sa, NULL );
11c606a6 (kx 2023-04-11 01:18:34 +0300  591)   sigaction( SIGINT, &sa,  NULL );
11c606a6 (kx 2023-04-11 01:18:34 +0300  592) 
11c606a6 (kx 2023-04-11 01:18:34 +0300  593)   memset( &sa, 0, sizeof( sa ) );  /* ignore SIGPIPE */
11c606a6 (kx 2023-04-11 01:18:34 +0300  594)   sa.sa_handler = SIG_IGN;
11c606a6 (kx 2023-04-11 01:18:34 +0300  595)   sa.sa_flags = 0;
11c606a6 (kx 2023-04-11 01:18:34 +0300  596)   sigaction( SIGPIPE, &sa, NULL );
11c606a6 (kx 2023-04-11 01:18:34 +0300  597) 
11c606a6 (kx 2023-04-11 01:18:34 +0300  598)   /* System V fork+wait does not work if SIGCHLD is ignored */
11c606a6 (kx 2023-04-11 01:18:34 +0300  599)   signal( SIGCHLD, SIG_DFL );
11c606a6 (kx 2023-04-11 01:18:34 +0300  600) }
11c606a6 (kx 2023-04-11 01:18:34 +0300  601) 
11c606a6 (kx 2023-04-11 01:18:34 +0300  602) 
11c606a6 (kx 2023-04-11 01:18:34 +0300  603) static enum _input_type check_input_file( char *uncompress, const char *fname )
11c606a6 (kx 2023-04-11 01:18:34 +0300  604) {
11c606a6 (kx 2023-04-11 01:18:34 +0300  605)   struct stat st;
11c606a6 (kx 2023-04-11 01:18:34 +0300  606)   size_t pkglog_size = 0;
11c606a6 (kx 2023-04-11 01:18:34 +0300  607)   unsigned char buf[8];
11c606a6 (kx 2023-04-11 01:18:34 +0300  608)   int rc, fd;
11c606a6 (kx 2023-04-11 01:18:34 +0300  609) 
11c606a6 (kx 2023-04-11 01:18:34 +0300  610)   /* SIGNATURES: https://www.garykessler.net/library/file_sigs.html */
11c606a6 (kx 2023-04-11 01:18:34 +0300  611) 
11c606a6 (kx 2023-04-11 01:18:34 +0300  612)   if( uncompress )
11c606a6 (kx 2023-04-11 01:18:34 +0300  613)   {
11c606a6 (kx 2023-04-11 01:18:34 +0300  614)     *uncompress = '\0';
11c606a6 (kx 2023-04-11 01:18:34 +0300  615)   }
11c606a6 (kx 2023-04-11 01:18:34 +0300  616) 
11c606a6 (kx 2023-04-11 01:18:34 +0300  617)   if( stat( fname, &st ) == -1 )
11c606a6 (kx 2023-04-11 01:18:34 +0300  618)   {
11c606a6 (kx 2023-04-11 01:18:34 +0300  619)     FATAL_ERROR( "Cannot access %s file: %s", basename( (char *)fname ), strerror( errno ) );
11c606a6 (kx 2023-04-11 01:18:34 +0300  620)   }
11c606a6 (kx 2023-04-11 01:18:34 +0300  621) 
11c606a6 (kx 2023-04-11 01:18:34 +0300  622)   pkglog_size = st.st_size;
11c606a6 (kx 2023-04-11 01:18:34 +0300  623) 
11c606a6 (kx 2023-04-11 01:18:34 +0300  624)   if( (fd = open( fname, O_RDONLY )) == -1 )
11c606a6 (kx 2023-04-11 01:18:34 +0300  625)   {
11c606a6 (kx 2023-04-11 01:18:34 +0300  626)     FATAL_ERROR( "Cannot open %s file: %s", basename( (char *)fname ), strerror( errno ) );
11c606a6 (kx 2023-04-11 01:18:34 +0300  627)   }
11c606a6 (kx 2023-04-11 01:18:34 +0300  628) 
11c606a6 (kx 2023-04-11 01:18:34 +0300  629)   rc = (int)read( fd, (void *)&buf[0], 7 );
11c606a6 (kx 2023-04-11 01:18:34 +0300  630)   if( rc != 7 )
11c606a6 (kx 2023-04-11 01:18:34 +0300  631)   {
11c606a6 (kx 2023-04-11 01:18:34 +0300  632)     close( fd ); return IFMT_UNKNOWN;
11c606a6 (kx 2023-04-11 01:18:34 +0300  633)   }
11c606a6 (kx 2023-04-11 01:18:34 +0300  634)   buf[7] = '\0';
11c606a6 (kx 2023-04-11 01:18:34 +0300  635) 
11c606a6 (kx 2023-04-11 01:18:34 +0300  636)   /* TEXT */
11c606a6 (kx 2023-04-11 01:18:34 +0300  637)   if( !strncmp( (const char *)&buf[0], "PACKAGE", 7 ) )
11c606a6 (kx 2023-04-11 01:18:34 +0300  638)   {
11c606a6 (kx 2023-04-11 01:18:34 +0300  639)     close( fd ); return IFMT_LOG;
11c606a6 (kx 2023-04-11 01:18:34 +0300  640)   }
11c606a6 (kx 2023-04-11 01:18:34 +0300  641) 
11c606a6 (kx 2023-04-11 01:18:34 +0300  642)   /* GZ */
11c606a6 (kx 2023-04-11 01:18:34 +0300  643)   if( buf[0] == 0x1F && buf[1] == 0x8B && buf[2] == 0x08 )
11c606a6 (kx 2023-04-11 01:18:34 +0300  644)   {
11c606a6 (kx 2023-04-11 01:18:34 +0300  645)     if( uncompress ) { *uncompress = 'x'; }
11c606a6 (kx 2023-04-11 01:18:34 +0300  646)     close( fd ); return IFMT_PKG;
11c606a6 (kx 2023-04-11 01:18:34 +0300  647)   }
11c606a6 (kx 2023-04-11 01:18:34 +0300  648) 
11c606a6 (kx 2023-04-11 01:18:34 +0300  649)   /* BZ2 */
11c606a6 (kx 2023-04-11 01:18:34 +0300  650)   if( buf[0] == 0x42 && buf[1] == 0x5A && buf[2] == 0x68 )
11c606a6 (kx 2023-04-11 01:18:34 +0300  651)   {
11c606a6 (kx 2023-04-11 01:18:34 +0300  652)     if( uncompress ) { *uncompress = 'j'; }
11c606a6 (kx 2023-04-11 01:18:34 +0300  653)     close( fd ); return IFMT_PKG;
11c606a6 (kx 2023-04-11 01:18:34 +0300  654)   }
11c606a6 (kx 2023-04-11 01:18:34 +0300  655) 
11c606a6 (kx 2023-04-11 01:18:34 +0300  656)   /* XZ */
11c606a6 (kx 2023-04-11 01:18:34 +0300  657)   if( buf[0] == 0xFD && buf[1] == 0x37 && buf[2] == 0x7A &&
11c606a6 (kx 2023-04-11 01:18:34 +0300  658)       buf[3] == 0x58 && buf[4] == 0x5A && buf[5] == 0x00   )
11c606a6 (kx 2023-04-11 01:18:34 +0300  659)   {
11c606a6 (kx 2023-04-11 01:18:34 +0300  660)     if( uncompress ) { *uncompress = 'J'; }
11c606a6 (kx 2023-04-11 01:18:34 +0300  661)     close( fd ); return IFMT_PKG;
11c606a6 (kx 2023-04-11 01:18:34 +0300  662)   }
11c606a6 (kx 2023-04-11 01:18:34 +0300  663) 
11c606a6 (kx 2023-04-11 01:18:34 +0300  664)   if( pkglog_size > 262 )
11c606a6 (kx 2023-04-11 01:18:34 +0300  665)   {
11c606a6 (kx 2023-04-11 01:18:34 +0300  666)     if( lseek( fd, 257, SEEK_SET ) == -1 )
11c606a6 (kx 2023-04-11 01:18:34 +0300  667)     {
11c606a6 (kx 2023-04-11 01:18:34 +0300  668)       FATAL_ERROR( "Cannot check signature of %s file: %s", basename( (char *)fname ), strerror( errno ) );
11c606a6 (kx 2023-04-11 01:18:34 +0300  669)     }
11c606a6 (kx 2023-04-11 01:18:34 +0300  670)     rc = (int)read( fd, &buf[0], 5 );
11c606a6 (kx 2023-04-11 01:18:34 +0300  671)     if( rc != 5 )
11c606a6 (kx 2023-04-11 01:18:34 +0300  672)     {
11c606a6 (kx 2023-04-11 01:18:34 +0300  673)       FATAL_ERROR( "Cannot read signature of %s file", basename( (char *)fname ) );
11c606a6 (kx 2023-04-11 01:18:34 +0300  674)     }
11c606a6 (kx 2023-04-11 01:18:34 +0300  675)     /* TAR */
11c606a6 (kx 2023-04-11 01:18:34 +0300  676)     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  677)     {
11c606a6 (kx 2023-04-11 01:18:34 +0300  678)       close( fd ); return IFMT_PKG;
11c606a6 (kx 2023-04-11 01:18:34 +0300  679)     }
11c606a6 (kx 2023-04-11 01:18:34 +0300  680)   }
11c606a6 (kx 2023-04-11 01:18:34 +0300  681) 
11c606a6 (kx 2023-04-11 01:18:34 +0300  682)   close( fd ); return IFMT_UNKNOWN;
11c606a6 (kx 2023-04-11 01:18:34 +0300  683) }
11c606a6 (kx 2023-04-11 01:18:34 +0300  684) 
11c606a6 (kx 2023-04-11 01:18:34 +0300  685) 
11c606a6 (kx 2023-04-11 01:18:34 +0300  686) void get_args( int argc, char *argv[] )
11c606a6 (kx 2023-04-11 01:18:34 +0300  687) {
11c606a6 (kx 2023-04-11 01:18:34 +0300  688) #if defined( HAVE_GPG2 )
11c606a6 (kx 2023-04-11 01:18:34 +0300  689) #if defined( HAVE_DIALOG )
11c606a6 (kx 2023-04-11 01:18:34 +0300  690)   const char* short_options = "hvacgiml:p:r:";
11c606a6 (kx 2023-04-11 01:18:34 +0300  691) #else
11c606a6 (kx 2023-04-11 01:18:34 +0300  692)   const char* short_options = "hvacgl:p:r:";
11c606a6 (kx 2023-04-11 01:18:34 +0300  693) #endif
11c606a6 (kx 2023-04-11 01:18:34 +0300  694) #else
11c606a6 (kx 2023-04-11 01:18:34 +0300  695) #if defined( HAVE_DIALOG )
11c606a6 (kx 2023-04-11 01:18:34 +0300  696)   const char* short_options = "hvaciml:p:r:";
11c606a6 (kx 2023-04-11 01:18:34 +0300  697) #else
11c606a6 (kx 2023-04-11 01:18:34 +0300  698)   const char* short_options = "hvacl:p:r:";
11c606a6 (kx 2023-04-11 01:18:34 +0300  699) #endif
11c606a6 (kx 2023-04-11 01:18:34 +0300  700) #endif
11c606a6 (kx 2023-04-11 01:18:34 +0300  701) 
11c606a6 (kx 2023-04-11 01:18:34 +0300  702) #define REINSTALL             812
11c606a6 (kx 2023-04-11 01:18:34 +0300  703) #define IGNORE_CHREFS_ERRORS  872
a745159c (kx 2023-10-23 21:39:58 +0300  704) #define DISABLE_CHREFS        873
11c606a6 (kx 2023-04-11 01:18:34 +0300  705) 
11c606a6 (kx 2023-04-11 01:18:34 +0300  706)   const struct option long_options[] =
11c606a6 (kx 2023-04-11 01:18:34 +0300  707)   {
11c606a6 (kx 2023-04-11 01:18:34 +0300  708)     { "help",                  no_argument,       NULL, 'h' },
11c606a6 (kx 2023-04-11 01:18:34 +0300  709)     { "version",               no_argument,       NULL, 'v' },
11c606a6 (kx 2023-04-11 01:18:34 +0300  710)     { "always-ask",            no_argument,       NULL, 'a' },
11c606a6 (kx 2023-04-11 01:18:34 +0300  711)     { "check-requires",        no_argument,       NULL, 'c' },
11c606a6 (kx 2023-04-11 01:18:34 +0300  712) #if defined( HAVE_GPG2 )
11c606a6 (kx 2023-04-11 01:18:34 +0300  713)     { "gpg-verify",            no_argument,       NULL, 'g' },
11c606a6 (kx 2023-04-11 01:18:34 +0300  714) #endif
11c606a6 (kx 2023-04-11 01:18:34 +0300  715)     { "ignore-chrefs-errors",  no_argument,       NULL, IGNORE_CHREFS_ERRORS },
a745159c (kx 2023-10-23 21:39:58 +0300  716)     { "disable-chrefs",        no_argument,       NULL, DISABLE_CHREFS },
11c606a6 (kx 2023-04-11 01:18:34 +0300  717) #if defined( HAVE_DIALOG )
11c606a6 (kx 2023-04-11 01:18:34 +0300  718)     { "info-dialog",           no_argument,       NULL, 'i' },
11c606a6 (kx 2023-04-11 01:18:34 +0300  719)     { "menu-dialog",           no_argument,       NULL, 'm' },
11c606a6 (kx 2023-04-11 01:18:34 +0300  720) #endif
11c606a6 (kx 2023-04-11 01:18:34 +0300  721)     { "pkglist",               required_argument, NULL, 'l' },
11c606a6 (kx 2023-04-11 01:18:34 +0300  722)     { "priority",              required_argument, NULL, 'p' },
11c606a6 (kx 2023-04-11 01:18:34 +0300  723)     { "reinstall",             no_argument,       NULL, REINSTALL },
11c606a6 (kx 2023-04-11 01:18:34 +0300  724)     { "root",                  required_argument, NULL, 'r' },
11c606a6 (kx 2023-04-11 01:18:34 +0300  725)     { NULL,                    0,                 NULL,  0  }
11c606a6 (kx 2023-04-11 01:18:34 +0300  726)   };
11c606a6 (kx 2023-04-11 01:18:34 +0300  727) 
11c606a6 (kx 2023-04-11 01:18:34 +0300  728)   int ret;
11c606a6 (kx 2023-04-11 01:18:34 +0300  729)   int option_index = 0;
11c606a6 (kx 2023-04-11 01:18:34 +0300  730) 
11c606a6 (kx 2023-04-11 01:18:34 +0300  731)   while( (ret = getopt_long( argc, argv, short_options, long_options, &option_index )) != -1 )
11c606a6 (kx 2023-04-11 01:18:34 +0300  732)   {
11c606a6 (kx 2023-04-11 01:18:34 +0300  733)     switch( ret )
11c606a6 (kx 2023-04-11 01:18:34 +0300  734)     {
11c606a6 (kx 2023-04-11 01:18:34 +0300  735)       case 'h':
11c606a6 (kx 2023-04-11 01:18:34 +0300  736)       {
11c606a6 (kx 2023-04-11 01:18:34 +0300  737)         usage();
11c606a6 (kx 2023-04-11 01:18:34 +0300  738)         break;
11c606a6 (kx 2023-04-11 01:18:34 +0300  739)       }
11c606a6 (kx 2023-04-11 01:18:34 +0300  740)       case 'v':
11c606a6 (kx 2023-04-11 01:18:34 +0300  741)       {
11c606a6 (kx 2023-04-11 01:18:34 +0300  742)         version();
11c606a6 (kx 2023-04-11 01:18:34 +0300  743)         break;
11c606a6 (kx 2023-04-11 01:18:34 +0300  744)       }
11c606a6 (kx 2023-04-11 01:18:34 +0300  745)       case 'a':
11c606a6 (kx 2023-04-11 01:18:34 +0300  746)       {
11c606a6 (kx 2023-04-11 01:18:34 +0300  747)         ask = 1;
11c606a6 (kx 2023-04-11 01:18:34 +0300  748)         break;
11c606a6 (kx 2023-04-11 01:18:34 +0300  749)       }
11c606a6 (kx 2023-04-11 01:18:34 +0300  750)       case 'c':
11c606a6 (kx 2023-04-11 01:18:34 +0300  751)       {
11c606a6 (kx 2023-04-11 01:18:34 +0300  752)         rqck = 1;
11c606a6 (kx 2023-04-11 01:18:34 +0300  753)         break;
11c606a6 (kx 2023-04-11 01:18:34 +0300  754)       }
11c606a6 (kx 2023-04-11 01:18:34 +0300  755) #if defined( HAVE_GPG2 )
11c606a6 (kx 2023-04-11 01:18:34 +0300  756)       case 'g':
11c606a6 (kx 2023-04-11 01:18:34 +0300  757)       {
11c606a6 (kx 2023-04-11 01:18:34 +0300  758)         gpgck = 1;
11c606a6 (kx 2023-04-11 01:18:34 +0300  759)         break;
11c606a6 (kx 2023-04-11 01:18:34 +0300  760)       }
11c606a6 (kx 2023-04-11 01:18:34 +0300  761) #endif
11c606a6 (kx 2023-04-11 01:18:34 +0300  762) 
11c606a6 (kx 2023-04-11 01:18:34 +0300  763) #if defined( HAVE_DIALOG )
11c606a6 (kx 2023-04-11 01:18:34 +0300  764)       case 'i':
11c606a6 (kx 2023-04-11 01:18:34 +0300  765)       {
11c606a6 (kx 2023-04-11 01:18:34 +0300  766)         update_mode = INFODIALOG;
11c606a6 (kx 2023-04-11 01:18:34 +0300  767)         break;
11c606a6 (kx 2023-04-11 01:18:34 +0300  768)       }
11c606a6 (kx 2023-04-11 01:18:34 +0300  769)       case 'm':
11c606a6 (kx 2023-04-11 01:18:34 +0300  770)       {
11c606a6 (kx 2023-04-11 01:18:34 +0300  771)         update_mode = MENUDIALOG;
11c606a6 (kx 2023-04-11 01:18:34 +0300  772)         break;
11c606a6 (kx 2023-04-11 01:18:34 +0300  773)       }
11c606a6 (kx 2023-04-11 01:18:34 +0300  774) #endif
11c606a6 (kx 2023-04-11 01:18:34 +0300  775) 
11c606a6 (kx 2023-04-11 01:18:34 +0300  776)       case REINSTALL:
11c606a6 (kx 2023-04-11 01:18:34 +0300  777)       {
11c606a6 (kx 2023-04-11 01:18:34 +0300  778)         reinstall = 1;
11c606a6 (kx 2023-04-11 01:18:34 +0300  779)         break;
11c606a6 (kx 2023-04-11 01:18:34 +0300  780)       }
11c606a6 (kx 2023-04-11 01:18:34 +0300  781)       case IGNORE_CHREFS_ERRORS:
11c606a6 (kx 2023-04-11 01:18:34 +0300  782)       {
11c606a6 (kx 2023-04-11 01:18:34 +0300  783)         ignore_chrefs_errors = 1;
11c606a6 (kx 2023-04-11 01:18:34 +0300  784)         break;
11c606a6 (kx 2023-04-11 01:18:34 +0300  785)       }
a745159c (kx 2023-10-23 21:39:58 +0300  786)       case DISABLE_CHREFS:
a745159c (kx 2023-10-23 21:39:58 +0300  787)       {
a745159c (kx 2023-10-23 21:39:58 +0300  788)         disable_chrefs = 1;
a745159c (kx 2023-10-23 21:39:58 +0300  789)         break;
a745159c (kx 2023-10-23 21:39:58 +0300  790)       }
11c606a6 (kx 2023-04-11 01:18:34 +0300  791) 
11c606a6 (kx 2023-04-11 01:18:34 +0300  792)       case 'p':
11c606a6 (kx 2023-04-11 01:18:34 +0300  793)       {
11c606a6 (kx 2023-04-11 01:18:34 +0300  794)         if( optarg != NULL )
11c606a6 (kx 2023-04-11 01:18:34 +0300  795)         {
11c606a6 (kx 2023-04-11 01:18:34 +0300  796)           char *match = NULL;
11c606a6 (kx 2023-04-11 01:18:34 +0300  797) 
11c606a6 (kx 2023-04-11 01:18:34 +0300  798)           if( strlen( (const char *)optarg ) > 2 )
11c606a6 (kx 2023-04-11 01:18:34 +0300  799)           {
11c606a6 (kx 2023-04-11 01:18:34 +0300  800)             to_lowercase( optarg );
11c606a6 (kx 2023-04-11 01:18:34 +0300  801)             if( (match = strstr( optarg, "req" )) && match == optarg ) {
11c606a6 (kx 2023-04-11 01:18:34 +0300  802)               priority = REQUIRED;
11c606a6 (kx 2023-04-11 01:18:34 +0300  803)             }
11c606a6 (kx 2023-04-11 01:18:34 +0300  804)             else if( (match = strstr( optarg, "rec" )) && match == optarg ) {
11c606a6 (kx 2023-04-11 01:18:34 +0300  805)               priority = RECOMMENDED;
11c606a6 (kx 2023-04-11 01:18:34 +0300  806)             }
11c606a6 (kx 2023-04-11 01:18:34 +0300  807) 
11c606a6 (kx 2023-04-11 01:18:34 +0300  808)             else if( (match = strstr( optarg, "opt" )) && match == optarg ) {
11c606a6 (kx 2023-04-11 01:18:34 +0300  809)               priority = OPTIONAL;
11c606a6 (kx 2023-04-11 01:18:34 +0300  810)             }
11c606a6 (kx 2023-04-11 01:18:34 +0300  811)             else if( (match = strstr( optarg, "sk" )) && match == optarg ) {
11c606a6 (kx 2023-04-11 01:18:34 +0300  812)               priority = SKIP;
11c606a6 (kx 2023-04-11 01:18:34 +0300  813)             }
11c606a6 (kx 2023-04-11 01:18:34 +0300  814)             else {
11c606a6 (kx 2023-04-11 01:18:34 +0300  815)               FATAL_ERROR( "Unknown --priority '%s' value", optarg );
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)           else
11c606a6 (kx 2023-04-11 01:18:34 +0300  819)           {
11c606a6 (kx 2023-04-11 01:18:34 +0300  820)             FATAL_ERROR( "Unknown --priority '%s' value", optarg );
11c606a6 (kx 2023-04-11 01:18:34 +0300  821)           }
11c606a6 (kx 2023-04-11 01:18:34 +0300  822)         }
11c606a6 (kx 2023-04-11 01:18:34 +0300  823)         else
11c606a6 (kx 2023-04-11 01:18:34 +0300  824)           /* option is present but without value */
11c606a6 (kx 2023-04-11 01:18:34 +0300  825)           usage();
11c606a6 (kx 2023-04-11 01:18:34 +0300  826)         break;
11c606a6 (kx 2023-04-11 01:18:34 +0300  827)       }
11c606a6 (kx 2023-04-11 01:18:34 +0300  828) 
11c606a6 (kx 2023-04-11 01:18:34 +0300  829)       case 'l':
11c606a6 (kx 2023-04-11 01:18:34 +0300  830)       {
11c606a6 (kx 2023-04-11 01:18:34 +0300  831)         if( optarg != NULL )
11c606a6 (kx 2023-04-11 01:18:34 +0300  832)         {
11c606a6 (kx 2023-04-11 01:18:34 +0300  833)           pkglist_fname = xstrdup( (const char *)optarg );
11c606a6 (kx 2023-04-11 01:18:34 +0300  834)         }
11c606a6 (kx 2023-04-11 01:18:34 +0300  835)         else
11c606a6 (kx 2023-04-11 01:18:34 +0300  836)           /* option is present but without value */
11c606a6 (kx 2023-04-11 01:18:34 +0300  837)           usage();
11c606a6 (kx 2023-04-11 01:18:34 +0300  838)         break;
11c606a6 (kx 2023-04-11 01:18:34 +0300  839)       }
11c606a6 (kx 2023-04-11 01:18:34 +0300  840) 
11c606a6 (kx 2023-04-11 01:18:34 +0300  841)       case 'r':
11c606a6 (kx 2023-04-11 01:18:34 +0300  842)       {
11c606a6 (kx 2023-04-11 01:18:34 +0300  843)         if( optarg != NULL )
11c606a6 (kx 2023-04-11 01:18:34 +0300  844)         {
11c606a6 (kx 2023-04-11 01:18:34 +0300  845)           char cwd[PATH_MAX];
11c606a6 (kx 2023-04-11 01:18:34 +0300  846) 
11c606a6 (kx 2023-04-11 01:18:34 +0300  847)           bzero( (void *)cwd, PATH_MAX );
11c606a6 (kx 2023-04-11 01:18:34 +0300  848)           if( optarg[0] != '/' && curdir )
11c606a6 (kx 2023-04-11 01:18:34 +0300  849)           {
11c606a6 (kx 2023-04-11 01:18:34 +0300  850)             /* skip current directory definition './' at start of argument: */
11c606a6 (kx 2023-04-11 01:18:34 +0300  851)             if( !strncmp( optarg, "./", 2 ) && strncmp( optarg, "..", 2 ) )
11c606a6 (kx 2023-04-11 01:18:34 +0300  852)               (void)sprintf( cwd, "%s/%s", curdir, optarg + 2 );
11c606a6 (kx 2023-04-11 01:18:34 +0300  853)             else if( (strlen( optarg ) == 1) && !strncmp( optarg, ".", 1 ) )
11c606a6 (kx 2023-04-11 01:18:34 +0300  854)               (void)sprintf( cwd, "%s", curdir );
11c606a6 (kx 2023-04-11 01:18:34 +0300  855)             else
11c606a6 (kx 2023-04-11 01:18:34 +0300  856)               (void)sprintf( cwd, "%s/%s", curdir, optarg );
11c606a6 (kx 2023-04-11 01:18:34 +0300  857)             root = xstrdup( (const char *)cwd );
11c606a6 (kx 2023-04-11 01:18:34 +0300  858)           }
11c606a6 (kx 2023-04-11 01:18:34 +0300  859)           else
11c606a6 (kx 2023-04-11 01:18:34 +0300  860)           {
11c606a6 (kx 2023-04-11 01:18:34 +0300  861)             root = xstrdup( (const char *)optarg );
11c606a6 (kx 2023-04-11 01:18:34 +0300  862)           }
11c606a6 (kx 2023-04-11 01:18:34 +0300  863)           remove_trailing_slash( root );
11c606a6 (kx 2023-04-11 01:18:34 +0300  864)         }
11c606a6 (kx 2023-04-11 01:18:34 +0300  865)         else
11c606a6 (kx 2023-04-11 01:18:34 +0300  866)           /* option is present but without value */
11c606a6 (kx 2023-04-11 01:18:34 +0300  867)           usage();
11c606a6 (kx 2023-04-11 01:18:34 +0300  868)         break;
11c606a6 (kx 2023-04-11 01:18:34 +0300  869)       }
11c606a6 (kx 2023-04-11 01:18:34 +0300  870) 
11c606a6 (kx 2023-04-11 01:18:34 +0300  871)       case '?': default:
11c606a6 (kx 2023-04-11 01:18:34 +0300  872)       {
11c606a6 (kx 2023-04-11 01:18:34 +0300  873)         usage();
11c606a6 (kx 2023-04-11 01:18:34 +0300  874)         break;
11c606a6 (kx 2023-04-11 01:18:34 +0300  875)       }
11c606a6 (kx 2023-04-11 01:18:34 +0300  876)     }
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) 
11c606a6 (kx 2023-04-11 01:18:34 +0300  880)   if( optind < argc )
11c606a6 (kx 2023-04-11 01:18:34 +0300  881)   {
11c606a6 (kx 2023-04-11 01:18:34 +0300  882)     struct stat st;
11c606a6 (kx 2023-04-11 01:18:34 +0300  883)     char  *buf = NULL;
11c606a6 (kx 2023-04-11 01:18:34 +0300  884) 
11c606a6 (kx 2023-04-11 01:18:34 +0300  885)     bzero( (void *)&st, sizeof( struct stat ) );
11c606a6 (kx 2023-04-11 01:18:34 +0300  886) 
11c606a6 (kx 2023-04-11 01:18:34 +0300  887)     buf = (char *)malloc( (size_t)PATH_MAX );
11c606a6 (kx 2023-04-11 01:18:34 +0300  888)     if( !buf ) { FATAL_ERROR( "Cannot allocate memory" ); }
11c606a6 (kx 2023-04-11 01:18:34 +0300  889)     bzero( (void *)buf, PATH_MAX );
11c606a6 (kx 2023-04-11 01:18:34 +0300  890) 
11c606a6 (kx 2023-04-11 01:18:34 +0300  891)     /* absolute path to input package: */
11c606a6 (kx 2023-04-11 01:18:34 +0300  892)     if( argv[optind][0] != '/' && curdir )
11c606a6 (kx 2023-04-11 01:18:34 +0300  893)       (void)sprintf( buf, "%s/%s", curdir, (const char *)argv[optind] );
11c606a6 (kx 2023-04-11 01:18:34 +0300  894)     else
11c606a6 (kx 2023-04-11 01:18:34 +0300  895)       (void)strcpy( buf, (const char *)argv[optind] );
11c606a6 (kx 2023-04-11 01:18:34 +0300  896) 
11c606a6 (kx 2023-04-11 01:18:34 +0300  897)     if( stat( (const char *)&buf[0], &st ) == -1 )
11c606a6 (kx 2023-04-11 01:18:34 +0300  898)     {
11c606a6 (kx 2023-04-11 01:18:34 +0300  899)       FATAL_ERROR( "Cannot access '%s' file: %s", buf, strerror( errno ) );
11c606a6 (kx 2023-04-11 01:18:34 +0300  900)     }
11c606a6 (kx 2023-04-11 01:18:34 +0300  901) 
11c606a6 (kx 2023-04-11 01:18:34 +0300  902)     if( S_ISREG(st.st_mode) )
11c606a6 (kx 2023-04-11 01:18:34 +0300  903)     {
11c606a6 (kx 2023-04-11 01:18:34 +0300  904)       pkg_fname = xstrdup( (const char *)&buf[0] );
11c606a6 (kx 2023-04-11 01:18:34 +0300  905)       bind_asc_extention( buf );
11c606a6 (kx 2023-04-11 01:18:34 +0300  906)       asc_fname = xstrdup( (const char *)&buf[0] );
11c606a6 (kx 2023-04-11 01:18:34 +0300  907)       free( buf );
11c606a6 (kx 2023-04-11 01:18:34 +0300  908)     }
11c606a6 (kx 2023-04-11 01:18:34 +0300  909)     else
11c606a6 (kx 2023-04-11 01:18:34 +0300  910)     {
11c606a6 (kx 2023-04-11 01:18:34 +0300  911)       FATAL_ERROR( "Input package '%s' is not a regular file", (const char *)argv[optind] );
11c606a6 (kx 2023-04-11 01:18:34 +0300  912)     }
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)     usage();
11c606a6 (kx 2023-04-11 01:18:34 +0300  917)   }
11c606a6 (kx 2023-04-11 01:18:34 +0300  918) 
11c606a6 (kx 2023-04-11 01:18:34 +0300  919) 
11c606a6 (kx 2023-04-11 01:18:34 +0300  920)   if( !pkgs_path )
11c606a6 (kx 2023-04-11 01:18:34 +0300  921)   {
11c606a6 (kx 2023-04-11 01:18:34 +0300  922)     struct stat st;
11c606a6 (kx 2023-04-11 01:18:34 +0300  923)     char  *buf = NULL;
11c606a6 (kx 2023-04-11 01:18:34 +0300  924)     int    len;
11c606a6 (kx 2023-04-11 01:18:34 +0300  925) 
11c606a6 (kx 2023-04-11 01:18:34 +0300  926)     bzero( (void *)&st, sizeof( struct stat ) );
11c606a6 (kx 2023-04-11 01:18:34 +0300  927) 
11c606a6 (kx 2023-04-11 01:18:34 +0300  928)     buf = (char *)malloc( (size_t)PATH_MAX );
11c606a6 (kx 2023-04-11 01:18:34 +0300  929)     if( !buf ) { FATAL_ERROR( "Cannot allocate memory" ); }
11c606a6 (kx 2023-04-11 01:18:34 +0300  930)     bzero( (void *)buf, PATH_MAX );
11c606a6 (kx 2023-04-11 01:18:34 +0300  931) 
11c606a6 (kx 2023-04-11 01:18:34 +0300  932)     if( !root )
11c606a6 (kx 2023-04-11 01:18:34 +0300  933)     {
11c606a6 (kx 2023-04-11 01:18:34 +0300  934)       buf[0] = '/'; buf[1] = '\0';
11c606a6 (kx 2023-04-11 01:18:34 +0300  935)       root = xstrdup( (const char *)buf );
11c606a6 (kx 2023-04-11 01:18:34 +0300  936)     }
11c606a6 (kx 2023-04-11 01:18:34 +0300  937)     else
11c606a6 (kx 2023-04-11 01:18:34 +0300  938)     {
11c606a6 (kx 2023-04-11 01:18:34 +0300  939)       len = strlen( root );
11c606a6 (kx 2023-04-11 01:18:34 +0300  940) 
11c606a6 (kx 2023-04-11 01:18:34 +0300  941)       (void)strcpy( buf, (const char *)root );
11c606a6 (kx 2023-04-11 01:18:34 +0300  942)       if( buf[ len - 1 ] != '/' )
11c606a6 (kx 2023-04-11 01:18:34 +0300  943)       {
11c606a6 (kx 2023-04-11 01:18:34 +0300  944)         buf[len] = '/'; buf[len+1] = '\0';
11c606a6 (kx 2023-04-11 01:18:34 +0300  945)         free( root ); root = xstrdup( (const char *)buf );
11c606a6 (kx 2023-04-11 01:18:34 +0300  946)       }
11c606a6 (kx 2023-04-11 01:18:34 +0300  947)     }
11c606a6 (kx 2023-04-11 01:18:34 +0300  948) 
11c606a6 (kx 2023-04-11 01:18:34 +0300  949)     if( stat( (const char *)&buf[0], &st ) == -1 )
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' file or directory: %s", buf, strerror( errno ) );
11c606a6 (kx 2023-04-11 01:18:34 +0300  952)     }
11c606a6 (kx 2023-04-11 01:18:34 +0300  953)     if( !S_ISDIR(st.st_mode) )
11c606a6 (kx 2023-04-11 01:18:34 +0300  954)     {
11c606a6 (kx 2023-04-11 01:18:34 +0300  955)       FATAL_ERROR( "Defined --root '%s' is not a directory", buf );
11c606a6 (kx 2023-04-11 01:18:34 +0300  956)     }
11c606a6 (kx 2023-04-11 01:18:34 +0300  957) 
11c606a6 (kx 2023-04-11 01:18:34 +0300  958)     len = strlen( (const char *)buf );
11c606a6 (kx 2023-04-11 01:18:34 +0300  959) 
11c606a6 (kx 2023-04-11 01:18:34 +0300  960)     (void)strcat( buf, PACKAGES_PATH );
11c606a6 (kx 2023-04-11 01:18:34 +0300  961)     if( _mkdir_p( buf, S_IRWXU | S_IRWXG | S_IRWXO ) != 0 )
11c606a6 (kx 2023-04-11 01:18:34 +0300  962)     {
11c606a6 (kx 2023-04-11 01:18:34 +0300  963)       FATAL_ERROR( "Cannot access '/%s' directory", PACKAGES_PATH );
11c606a6 (kx 2023-04-11 01:18:34 +0300  964)     }
11c606a6 (kx 2023-04-11 01:18:34 +0300  965)     pkgs_path = xstrdup( (const char *)&buf[0] );
11c606a6 (kx 2023-04-11 01:18:34 +0300  966) 
11c606a6 (kx 2023-04-11 01:18:34 +0300  967)     /*********************************************
11c606a6 (kx 2023-04-11 01:18:34 +0300  968)       Create other directories of Setup Database:
11c606a6 (kx 2023-04-11 01:18:34 +0300  969)      */
11c606a6 (kx 2023-04-11 01:18:34 +0300  970)     buf[len] = '\0';
11c606a6 (kx 2023-04-11 01:18:34 +0300  971)     (void)strcat( buf, REMOVED_PKGS_PATH );
11c606a6 (kx 2023-04-11 01:18:34 +0300  972)     if( _mkdir_p( buf, S_IRWXU | S_IRWXG | S_IRWXO ) != 0 )
11c606a6 (kx 2023-04-11 01:18:34 +0300  973)     {
11c606a6 (kx 2023-04-11 01:18:34 +0300  974)       FATAL_ERROR( "Cannot access '/%s' directory", REMOVED_PKGS_PATH );
11c606a6 (kx 2023-04-11 01:18:34 +0300  975)     }
11c606a6 (kx 2023-04-11 01:18:34 +0300  976)     rempkgs_path = xstrdup( (const char *)&buf[0] );
11c606a6 (kx 2023-04-11 01:18:34 +0300  977) 
11c606a6 (kx 2023-04-11 01:18:34 +0300  978)     buf[len] = '\0';
11c606a6 (kx 2023-04-11 01:18:34 +0300  979)     (void)strcat( buf, SETUP_PATH );
11c606a6 (kx 2023-04-11 01:18:34 +0300  980)     if( _mkdir_p( buf, S_IRWXU | S_IRWXG | S_IRWXO ) != 0 )
11c606a6 (kx 2023-04-11 01:18:34 +0300  981)     {
11c606a6 (kx 2023-04-11 01:18:34 +0300  982)       FATAL_ERROR( "Cannot access '/%s' directory", SETUP_PATH );
11c606a6 (kx 2023-04-11 01:18:34 +0300  983)     }
11c606a6 (kx 2023-04-11 01:18:34 +0300  984) 
11c606a6 (kx 2023-04-11 01:18:34 +0300  985)     /*********************************************
11c606a6 (kx 2023-04-11 01:18:34 +0300  986)       Allocate memory for Setup LOG File name:
11c606a6 (kx 2023-04-11 01:18:34 +0300  987)      */
11c606a6 (kx 2023-04-11 01:18:34 +0300  988)     buf[len] = '\0';
11c606a6 (kx 2023-04-11 01:18:34 +0300  989)     (void)strcat( buf, LOG_PATH );
11c606a6 (kx 2023-04-11 01:18:34 +0300  990)     (void)strcat( buf, SETUP_LOG_FILE );
11c606a6 (kx 2023-04-11 01:18:34 +0300  991)     log_fname = xstrdup( (const char *)&buf[0] );
11c606a6 (kx 2023-04-11 01:18:34 +0300  992) 
11c606a6 (kx 2023-04-11 01:18:34 +0300  993)     free( buf );
11c606a6 (kx 2023-04-11 01:18:34 +0300  994) 
11c606a6 (kx 2023-04-11 01:18:34 +0300  995)   } /* End if( !pkgs_path ) */
11c606a6 (kx 2023-04-11 01:18:34 +0300  996) }
11c606a6 (kx 2023-04-11 01:18:34 +0300  997) 
11c606a6 (kx 2023-04-11 01:18:34 +0300  998) static void setup_log( char *format, ... )
11c606a6 (kx 2023-04-11 01:18:34 +0300  999) {
11c606a6 (kx 2023-04-11 01:18:34 +0300 1000)   FILE *fp = NULL;
11c606a6 (kx 2023-04-11 01:18:34 +0300 1001) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1002)   time_t     t = time( NULL );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1003)   struct tm tm = *localtime(&t);
11c606a6 (kx 2023-04-11 01:18:34 +0300 1004) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1005)   va_list argp;
11c606a6 (kx 2023-04-11 01:18:34 +0300 1006) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1007)   if( ! format ) return;
11c606a6 (kx 2023-04-11 01:18:34 +0300 1008) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1009)   fp = fopen( (const char *)log_fname, "a" );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1010)   if( !fp )
11c606a6 (kx 2023-04-11 01:18:34 +0300 1011)   {
11c606a6 (kx 2023-04-11 01:18:34 +0300 1012)     FATAL_ERROR( "Cannot open /%s%s file", LOG_PATH, SETUP_LOG_FILE );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1013)   }
11c606a6 (kx 2023-04-11 01:18:34 +0300 1014) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1015)   fprintf( fp, "[%04d-%02d-%02d %02d:%02d:%02d]: ",
11c606a6 (kx 2023-04-11 01:18:34 +0300 1016)                   tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday,
11c606a6 (kx 2023-04-11 01:18:34 +0300 1017)                                  tm.tm_hour, tm.tm_min, tm.tm_sec );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1018) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1019)   va_start( argp, format );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1020)   vfprintf( fp, format, argp );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1021)   fprintf( fp, "\n" );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1022) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1023)   fflush( fp );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1024)   fclose( fp );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1025) }
11c606a6 (kx 2023-04-11 01:18:34 +0300 1026) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1027) /***********************************************************
11c606a6 (kx 2023-04-11 01:18:34 +0300 1028)   Remove leading spaces and take non-space characters only:
11c606a6 (kx 2023-04-11 01:18:34 +0300 1029)   (Especialy for pkginfo lines)
11c606a6 (kx 2023-04-11 01:18:34 +0300 1030)  */
11c606a6 (kx 2023-04-11 01:18:34 +0300 1031) static char *skip_spaces( char *s )
11c606a6 (kx 2023-04-11 01:18:34 +0300 1032) {
11c606a6 (kx 2023-04-11 01:18:34 +0300 1033)   char *q, *p = (char *)0;
11c606a6 (kx 2023-04-11 01:18:34 +0300 1034) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1035)   if( !s || *s == '\0' ) return p;
11c606a6 (kx 2023-04-11 01:18:34 +0300 1036) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1037)   p = s;
11c606a6 (kx 2023-04-11 01:18:34 +0300 1038) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1039)   while( (*p == ' ' || *p == '\t') && *p != '\0' ) { ++p; } q = p;
11c606a6 (kx 2023-04-11 01:18:34 +0300 1040)   while(  *q != ' ' && *q != '\t'  && *q != '\0' ) { ++q; } *q = '\0';
11c606a6 (kx 2023-04-11 01:18:34 +0300 1041) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1042)   if( *p == '\0' ) return (char *)0;
11c606a6 (kx 2023-04-11 01:18:34 +0300 1043) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1044)   return( xstrdup( (const char *)p ) );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1045) }
11c606a6 (kx 2023-04-11 01:18:34 +0300 1046) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1047) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1048) /*******************************
11c606a6 (kx 2023-04-11 01:18:34 +0300 1049)   remove spaces at end of line:
11c606a6 (kx 2023-04-11 01:18:34 +0300 1050)  */
11c606a6 (kx 2023-04-11 01:18:34 +0300 1051) static void skip_eol_spaces( char *s )
11c606a6 (kx 2023-04-11 01:18:34 +0300 1052) {
11c606a6 (kx 2023-04-11 01:18:34 +0300 1053)   char *p = (char *)0;
11c606a6 (kx 2023-04-11 01:18:34 +0300 1054) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1055)   if( !s || *s == '\0' ) return;
11c606a6 (kx 2023-04-11 01:18:34 +0300 1056) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1057)   p = s + strlen( s ) - 1;
11c606a6 (kx 2023-04-11 01:18:34 +0300 1058)   while( isspace( *p ) ) { *p-- = '\0'; }
11c606a6 (kx 2023-04-11 01:18:34 +0300 1059) }
11c606a6 (kx 2023-04-11 01:18:34 +0300 1060) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1061) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1062) static char *trim( char *s )
11c606a6 (kx 2023-04-11 01:18:34 +0300 1063) {
11c606a6 (kx 2023-04-11 01:18:34 +0300 1064)   char *p = (char *)0;
11c606a6 (kx 2023-04-11 01:18:34 +0300 1065) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1066)   if( !s || *s == '\0' ) return p;
11c606a6 (kx 2023-04-11 01:18:34 +0300 1067) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1068)   p = s + strlen( s ) - 1;
11c606a6 (kx 2023-04-11 01:18:34 +0300 1069)   while( isspace( *p ) ) { *p-- = '\0'; }
11c606a6 (kx 2023-04-11 01:18:34 +0300 1070)   p = s; while( isspace( *p ) ) { ++p; }
11c606a6 (kx 2023-04-11 01:18:34 +0300 1071) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1072)   return( p );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1073) }
11c606a6 (kx 2023-04-11 01:18:34 +0300 1074) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1075) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1076) static char *size_to_string( size_t pkgsize )
11c606a6 (kx 2023-04-11 01:18:34 +0300 1077) {
11c606a6 (kx 2023-04-11 01:18:34 +0300 1078)   int    nd;
11c606a6 (kx 2023-04-11 01:18:34 +0300 1079)   double sz = (double)pkgsize / (double)1024;
11c606a6 (kx 2023-04-11 01:18:34 +0300 1080) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1081)   char  *ret = NULL;
11c606a6 (kx 2023-04-11 01:18:34 +0300 1082)   char  *tmp = NULL;
11c606a6 (kx 2023-04-11 01:18:34 +0300 1083) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1084)   tmp = (char *)malloc( PATH_MAX );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1085)   if( !tmp ) { FATAL_ERROR( "Cannot allocate memory" ); }
11c606a6 (kx 2023-04-11 01:18:34 +0300 1086)   bzero( (void *)tmp, PATH_MAX );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1087) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1088)   if( sz > (double)1048576 )
11c606a6 (kx 2023-04-11 01:18:34 +0300 1089)   {
11c606a6 (kx 2023-04-11 01:18:34 +0300 1090)     sz = sz / (double)1048576;
11c606a6 (kx 2023-04-11 01:18:34 +0300 1091)     /*
11c606a6 (kx 2023-04-11 01:18:34 +0300 1092)       NOTE:
11c606a6 (kx 2023-04-11 01:18:34 +0300 1093)       ----
11c606a6 (kx 2023-04-11 01:18:34 +0300 1094)       Операция округления до одного знака после десятичной точки: sz = round(sz*10.0)/10.0;
11c606a6 (kx 2023-04-11 01:18:34 +0300 1095)       здесь не нужна; можно обойтись вычислением количества цифр, выводимых на печать с помощью
11c606a6 (kx 2023-04-11 01:18:34 +0300 1096)       формата '%.*g':
11c606a6 (kx 2023-04-11 01:18:34 +0300 1097) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1098)       Количество десятичных цифр, необходимое для предстваления целой части числа + 1(одна)
11c606a6 (kx 2023-04-11 01:18:34 +0300 1099)       десятичная цифра после десятичной точки. Формат %.*g не будет выводить дробную часть
11c606a6 (kx 2023-04-11 01:18:34 +0300 1100)       числа, если после округления, до одного знака после десятичной точки, дробная часть
11c606a6 (kx 2023-04-11 01:18:34 +0300 1101)       равна нулю:
11c606a6 (kx 2023-04-11 01:18:34 +0300 1102)      */
11c606a6 (kx 2023-04-11 01:18:34 +0300 1103)     nd = (int)ceil(log10(floor(sz) + 1.0)) + 1;
11c606a6 (kx 2023-04-11 01:18:34 +0300 1104)     (void)sprintf( (char *)&tmp[0], "%.*gG", nd, sz );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1105)   }
11c606a6 (kx 2023-04-11 01:18:34 +0300 1106)   else if( sz > (double)1024 )
11c606a6 (kx 2023-04-11 01:18:34 +0300 1107)   {
11c606a6 (kx 2023-04-11 01:18:34 +0300 1108)     sz = sz / (double)1024;
11c606a6 (kx 2023-04-11 01:18:34 +0300 1109)     nd = (int)ceil(log10(floor(sz) + 1.0)) + 1;
11c606a6 (kx 2023-04-11 01:18:34 +0300 1110)     (void)sprintf( (char *)&tmp[0], "%.*gM", nd, sz );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1111)   }
11c606a6 (kx 2023-04-11 01:18:34 +0300 1112)   else
11c606a6 (kx 2023-04-11 01:18:34 +0300 1113)   {
11c606a6 (kx 2023-04-11 01:18:34 +0300 1114)     nd = (int)ceil(log10(floor(sz) + 1.0)) + 1;
11c606a6 (kx 2023-04-11 01:18:34 +0300 1115)     (void)sprintf( (char *)&tmp[0], "%.*gK", nd, sz );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1116)   }
11c606a6 (kx 2023-04-11 01:18:34 +0300 1117) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1118)   ret = xstrdup( (const char *)&tmp[0] );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1119)   free( tmp );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1120) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1121)   return ret;
11c606a6 (kx 2023-04-11 01:18:34 +0300 1122) }
11c606a6 (kx 2023-04-11 01:18:34 +0300 1123) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1124) static void read_pkginfo( const char *pkginfo_fname )
11c606a6 (kx 2023-04-11 01:18:34 +0300 1125) {
11c606a6 (kx 2023-04-11 01:18:34 +0300 1126)   char *ln      = NULL;
11c606a6 (kx 2023-04-11 01:18:34 +0300 1127)   char *line    = NULL;
11c606a6 (kx 2023-04-11 01:18:34 +0300 1128) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1129)   FILE *pkginfo = NULL;
11c606a6 (kx 2023-04-11 01:18:34 +0300 1130) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1131)   if( pkginfo_fname != NULL )
11c606a6 (kx 2023-04-11 01:18:34 +0300 1132)   {
11c606a6 (kx 2023-04-11 01:18:34 +0300 1133)     pkginfo = fopen( (const char *)pkginfo_fname, "r" );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1134)     if( !pkginfo )
11c606a6 (kx 2023-04-11 01:18:34 +0300 1135)     {
11c606a6 (kx 2023-04-11 01:18:34 +0300 1136)       FATAL_ERROR( "Cannot open %s file", pkginfo_fname );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1137)     }
11c606a6 (kx 2023-04-11 01:18:34 +0300 1138)   }
11c606a6 (kx 2023-04-11 01:18:34 +0300 1139) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1140)   line = (char *)malloc( (size_t)PATH_MAX );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1141)   if( !line )
11c606a6 (kx 2023-04-11 01:18:34 +0300 1142)   {
11c606a6 (kx 2023-04-11 01:18:34 +0300 1143)     FATAL_ERROR( "Cannot allocate memory" );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1144)   }
11c606a6 (kx 2023-04-11 01:18:34 +0300 1145) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1146)   while( (ln = fgets( line, PATH_MAX, pkginfo )) )
11c606a6 (kx 2023-04-11 01:18:34 +0300 1147)   {
11c606a6 (kx 2023-04-11 01:18:34 +0300 1148)     char *match = NULL;
11c606a6 (kx 2023-04-11 01:18:34 +0300 1149) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1150)     ln[strlen(ln) - 1] = '\0'; /* replace new-line symbol      */
11c606a6 (kx 2023-04-11 01:18:34 +0300 1151)     skip_eol_spaces( ln );     /* remove spaces at end-of-line */
11c606a6 (kx 2023-04-11 01:18:34 +0300 1152) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1153)     if( (match = strstr( ln, "pkgname" )) && match == ln ) {
11c606a6 (kx 2023-04-11 01:18:34 +0300 1154)       char *p = index( match, '=' ) + 1;
11c606a6 (kx 2023-04-11 01:18:34 +0300 1155)       if( p != NULL )
11c606a6 (kx 2023-04-11 01:18:34 +0300 1156)       {
11c606a6 (kx 2023-04-11 01:18:34 +0300 1157)         if( pkgname ) { free( pkgname ); }
11c606a6 (kx 2023-04-11 01:18:34 +0300 1158)         pkgname = skip_spaces( p );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1159)       }
11c606a6 (kx 2023-04-11 01:18:34 +0300 1160)     }
11c606a6 (kx 2023-04-11 01:18:34 +0300 1161)     if( (match = strstr( ln, "pkgver" )) && match == ln ) {
11c606a6 (kx 2023-04-11 01:18:34 +0300 1162)       char *p = index( match, '=' ) + 1;
11c606a6 (kx 2023-04-11 01:18:34 +0300 1163)       if( p != NULL )
11c606a6 (kx 2023-04-11 01:18:34 +0300 1164)       {
11c606a6 (kx 2023-04-11 01:18:34 +0300 1165)         if( pkgver ) { free( pkgver ); }
11c606a6 (kx 2023-04-11 01:18:34 +0300 1166)         pkgver = skip_spaces( p );
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, "arch" )) && 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 )
11c606a6 (kx 2023-04-11 01:18:34 +0300 1172)       {
11c606a6 (kx 2023-04-11 01:18:34 +0300 1173)         if( arch ) { free( arch ); }
11c606a6 (kx 2023-04-11 01:18:34 +0300 1174)         arch = skip_spaces( p );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1175)       }
11c606a6 (kx 2023-04-11 01:18:34 +0300 1176)     }
11c606a6 (kx 2023-04-11 01:18:34 +0300 1177)     if( (match = strstr( ln, "distroname" )) && match == ln ) {
11c606a6 (kx 2023-04-11 01:18:34 +0300 1178)       char *p = index( match, '=' ) + 1;
11c606a6 (kx 2023-04-11 01:18:34 +0300 1179)       if( p != NULL )
11c606a6 (kx 2023-04-11 01:18:34 +0300 1180)       {
11c606a6 (kx 2023-04-11 01:18:34 +0300 1181)         if( distroname ) { free( distroname ); }
11c606a6 (kx 2023-04-11 01:18:34 +0300 1182)         distroname = skip_spaces( p );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1183)       }
11c606a6 (kx 2023-04-11 01:18:34 +0300 1184)     }
11c606a6 (kx 2023-04-11 01:18:34 +0300 1185)     if( (match = strstr( ln, "distrover" )) && match == ln ) {
11c606a6 (kx 2023-04-11 01:18:34 +0300 1186)       char *p = index( match, '=' ) + 1;
11c606a6 (kx 2023-04-11 01:18:34 +0300 1187)       if( p != NULL )
11c606a6 (kx 2023-04-11 01:18:34 +0300 1188)       {
11c606a6 (kx 2023-04-11 01:18:34 +0300 1189)         if( distrover ) { free( distrover ); }
11c606a6 (kx 2023-04-11 01:18:34 +0300 1190)         distrover = skip_spaces( p );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1191)       }
11c606a6 (kx 2023-04-11 01:18:34 +0300 1192)     }
11c606a6 (kx 2023-04-11 01:18:34 +0300 1193) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1194)     if( (match = strstr( ln, "group" )) && match == ln ) {
11c606a6 (kx 2023-04-11 01:18:34 +0300 1195)       char *p = index( match, '=' ) + 1;
11c606a6 (kx 2023-04-11 01:18:34 +0300 1196)       if( p != NULL )
11c606a6 (kx 2023-04-11 01:18:34 +0300 1197)       {
11c606a6 (kx 2023-04-11 01:18:34 +0300 1198)         if( group ) { free( group ); }
11c606a6 (kx 2023-04-11 01:18:34 +0300 1199)         group = skip_spaces( p );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1200)       }
11c606a6 (kx 2023-04-11 01:18:34 +0300 1201)     }
11c606a6 (kx 2023-04-11 01:18:34 +0300 1202) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1203)     if( (match = strstr( ln, "short_description" )) && match == ln ) {
11c606a6 (kx 2023-04-11 01:18:34 +0300 1204)       char *p = index( match, '=' ) + 1;
11c606a6 (kx 2023-04-11 01:18:34 +0300 1205)       if( p != NULL )
11c606a6 (kx 2023-04-11 01:18:34 +0300 1206)       {
11c606a6 (kx 2023-04-11 01:18:34 +0300 1207)         char *b =  index( p, '"'),
11c606a6 (kx 2023-04-11 01:18:34 +0300 1208)              *e = rindex( p, '"');
11c606a6 (kx 2023-04-11 01:18:34 +0300 1209)         if( b && e && ( b != e ) )
11c606a6 (kx 2023-04-11 01:18:34 +0300 1210)         {
11c606a6 (kx 2023-04-11 01:18:34 +0300 1211)           p = ++b; *e = '\0';
11c606a6 (kx 2023-04-11 01:18:34 +0300 1212)           if( short_description ) { free( short_description ); }
11c606a6 (kx 2023-04-11 01:18:34 +0300 1213)           short_description = xstrdup( (const char *)p );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1214)         }
11c606a6 (kx 2023-04-11 01:18:34 +0300 1215)       }
11c606a6 (kx 2023-04-11 01:18:34 +0300 1216)     }
11c606a6 (kx 2023-04-11 01:18:34 +0300 1217)     if( (match = strstr( ln, "url" )) && match == ln ) {
11c606a6 (kx 2023-04-11 01:18:34 +0300 1218)       char *p = index( match, '=' ) + 1;
11c606a6 (kx 2023-04-11 01:18:34 +0300 1219)       if( p != NULL )
11c606a6 (kx 2023-04-11 01:18:34 +0300 1220)       {
11c606a6 (kx 2023-04-11 01:18:34 +0300 1221)         if( url ) { free( url ); }
11c606a6 (kx 2023-04-11 01:18:34 +0300 1222)         url = skip_spaces( p );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1223)       }
11c606a6 (kx 2023-04-11 01:18:34 +0300 1224)     }
11c606a6 (kx 2023-04-11 01:18:34 +0300 1225)     if( (match = strstr( ln, "license" )) && match == ln ) {
11c606a6 (kx 2023-04-11 01:18:34 +0300 1226)       char *p = index( match, '=' ) + 1;
11c606a6 (kx 2023-04-11 01:18:34 +0300 1227)       if( p != NULL )
11c606a6 (kx 2023-04-11 01:18:34 +0300 1228)       {
11c606a6 (kx 2023-04-11 01:18:34 +0300 1229)         if( license ) { free( license ); }
11c606a6 (kx 2023-04-11 01:18:34 +0300 1230)         license = skip_spaces( p );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1231)       }
11c606a6 (kx 2023-04-11 01:18:34 +0300 1232)     }
11c606a6 (kx 2023-04-11 01:18:34 +0300 1233) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1234)     if( (match = strstr( ln, "uncompressed_size" )) && match == ln ) {
11c606a6 (kx 2023-04-11 01:18:34 +0300 1235)       char *p = index( match, '=' ) + 1;
11c606a6 (kx 2023-04-11 01:18:34 +0300 1236)       if( p != NULL )
11c606a6 (kx 2023-04-11 01:18:34 +0300 1237)       {
11c606a6 (kx 2023-04-11 01:18:34 +0300 1238)         if( uncompressed_size ) { free( uncompressed_size ); }
11c606a6 (kx 2023-04-11 01:18:34 +0300 1239)         uncompressed_size = skip_spaces( p );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1240)       }
11c606a6 (kx 2023-04-11 01:18:34 +0300 1241)     }
11c606a6 (kx 2023-04-11 01:18:34 +0300 1242)     if( (match = strstr( ln, "total_files" )) && match == ln ) {
11c606a6 (kx 2023-04-11 01:18:34 +0300 1243)       char *p = index( match, '=' ) + 1;
11c606a6 (kx 2023-04-11 01:18:34 +0300 1244)       if( p != NULL )
11c606a6 (kx 2023-04-11 01:18:34 +0300 1245)       {
11c606a6 (kx 2023-04-11 01:18:34 +0300 1246)         if( total_files ) { free( total_files ); }
11c606a6 (kx 2023-04-11 01:18:34 +0300 1247)         total_files = skip_spaces( p );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1248)       }
11c606a6 (kx 2023-04-11 01:18:34 +0300 1249)     }
11c606a6 (kx 2023-04-11 01:18:34 +0300 1250)   }
11c606a6 (kx 2023-04-11 01:18:34 +0300 1251) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1252)   free( line );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1253) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1254)   if( !pkgname || !pkgver || !arch || !distroname || !distrover )
11c606a6 (kx 2023-04-11 01:18:34 +0300 1255)   {
11c606a6 (kx 2023-04-11 01:18:34 +0300 1256)     FATAL_ERROR( "Invalid input .PKGINFO file" );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1257)   }
11c606a6 (kx 2023-04-11 01:18:34 +0300 1258) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1259)   fclose( pkginfo );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1260) }
11c606a6 (kx 2023-04-11 01:18:34 +0300 1261) 
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)   Find functions:
11c606a6 (kx 2023-04-11 01:18:34 +0300 1265)  */
11c606a6 (kx 2023-04-11 01:18:34 +0300 1266) static void _search_pkglog( const char *dirpath, const char *grp )
11c606a6 (kx 2023-04-11 01:18:34 +0300 1267) {
11c606a6 (kx 2023-04-11 01:18:34 +0300 1268)   DIR    *dir;
11c606a6 (kx 2023-04-11 01:18:34 +0300 1269)   char   *path;
11c606a6 (kx 2023-04-11 01:18:34 +0300 1270)   size_t  len;
11c606a6 (kx 2023-04-11 01:18:34 +0300 1271) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1272)   struct stat    path_sb, entry_sb;
11c606a6 (kx 2023-04-11 01:18:34 +0300 1273)   struct dirent *entry;
11c606a6 (kx 2023-04-11 01:18:34 +0300 1274) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1275)   char   *pname = (char *)dirpath + strlen( root ); /* do not remove leading '/' */
11c606a6 (kx 2023-04-11 01:18:34 +0300 1276) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1277)   if( stat( dirpath, &path_sb ) == -1 )
11c606a6 (kx 2023-04-11 01:18:34 +0300 1278)   {
11c606a6 (kx 2023-04-11 01:18:34 +0300 1279)     FATAL_ERROR( "%s: Cannot stat Setup Database or group directory", pname );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1280)   }
11c606a6 (kx 2023-04-11 01:18:34 +0300 1281) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1282)   if( S_ISDIR(path_sb.st_mode) == 0 )
11c606a6 (kx 2023-04-11 01:18:34 +0300 1283)   {
11c606a6 (kx 2023-04-11 01:18:34 +0300 1284)     FATAL_ERROR( "%s: Setup Database or group is not a directory", pname );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1285)   }
11c606a6 (kx 2023-04-11 01:18:34 +0300 1286) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1287)   if( (dir = opendir(dirpath) ) == NULL )
11c606a6 (kx 2023-04-11 01:18:34 +0300 1288)   {
11c606a6 (kx 2023-04-11 01:18:34 +0300 1289)     FATAL_ERROR( "Canot access %s directory: %s", pname, strerror( errno ) );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1290)   }
11c606a6 (kx 2023-04-11 01:18:34 +0300 1291) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1292)   len = strlen( dirpath );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1293) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1294)   while( (entry = readdir( dir )) != NULL)
11c606a6 (kx 2023-04-11 01:18:34 +0300 1295)   {
11c606a6 (kx 2023-04-11 01:18:34 +0300 1296)     /* skip entries '.' and '..' */
11c606a6 (kx 2023-04-11 01:18:34 +0300 1297)     if( ! strcmp( entry->d_name, "." ) || ! strcmp( entry->d_name, ".." ) ) continue;
11c606a6 (kx 2023-04-11 01:18:34 +0300 1298) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1299)     /* determinate a full name of an entry */
11c606a6 (kx 2023-04-11 01:18:34 +0300 1300)     path = alloca( len + strlen( entry->d_name ) + 2 );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1301) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1302)     strcpy( path, dirpath );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1303)     strcat( path, "/" );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1304)     strcat( path, entry->d_name );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1305) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1306)     if( stat( path, &entry_sb ) == 0 )
11c606a6 (kx 2023-04-11 01:18:34 +0300 1307)     {
11c606a6 (kx 2023-04-11 01:18:34 +0300 1308)       if( S_ISREG(entry_sb.st_mode) )
11c606a6 (kx 2023-04-11 01:18:34 +0300 1309)       {
11c606a6 (kx 2023-04-11 01:18:34 +0300 1310)         char *match = NULL, *name  = basename( path );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1311) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1312)         if( (match = strstr( name, pkgname )) && match == name )
11c606a6 (kx 2023-04-11 01:18:34 +0300 1313)         {
11c606a6 (kx 2023-04-11 01:18:34 +0300 1314)           /****************************************************************
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)             мы пропускаем символ '-', разделяющий имя и версию пакета,
11c606a6 (kx 2023-04-11 01:18:34 +0300 1319)             а затем проверяем начальный символ версии:
11c606a6 (kx 2023-04-11 01:18:34 +0300 1320)            */
11c606a6 (kx 2023-04-11 01:18:34 +0300 1321)           if( *(name + strlen( pkgname )) == '-' && isdigit( *(name + strlen( pkgname ) + 1) ) )
11c606a6 (kx 2023-04-11 01:18:34 +0300 1322)           {
11c606a6 (kx 2023-04-11 01:18:34 +0300 1323)             remlog_fname = xstrdup( (const char *)path );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1324)             closedir( dir );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1325)             return;
11c606a6 (kx 2023-04-11 01:18:34 +0300 1326)           }
11c606a6 (kx 2023-04-11 01:18:34 +0300 1327)         }
11c606a6 (kx 2023-04-11 01:18:34 +0300 1328)       }
11c606a6 (kx 2023-04-11 01:18:34 +0300 1329)       if( S_ISDIR(entry_sb.st_mode) && grp == NULL )
11c606a6 (kx 2023-04-11 01:18:34 +0300 1330)       {
11c606a6 (kx 2023-04-11 01:18:34 +0300 1331)         /**************************************************************************
11c606a6 (kx 2023-04-11 01:18:34 +0300 1332)           NOTE:
11c606a6 (kx 2023-04-11 01:18:34 +0300 1333)             In the Setup Database can be only one package with the same pkgname
11c606a6 (kx 2023-04-11 01:18:34 +0300 1334)             but in different groups. For example, the package named 'cairo'
11c606a6 (kx 2023-04-11 01:18:34 +0300 1335)             has two instance: libs/cairo-1.14.6 and xlibs/cairo-1.14.6. During
11c606a6 (kx 2023-04-11 01:18:34 +0300 1336)             system installation the package libs/cairo-1.14.6 installed first
11c606a6 (kx 2023-04-11 01:18:34 +0300 1337)             and then updated by xlibs/cairo-1.14.6 and PKGLOG of libs/cairo-1.14.6
11c606a6 (kx 2023-04-11 01:18:34 +0300 1338)             moved from /var/log/radix/packages to /var/log/radix/removed-packages.
11c606a6 (kx 2023-04-11 01:18:34 +0300 1339) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1340)             So here we have to look for the PKGLOG in all group directories:
11c606a6 (kx 2023-04-11 01:18:34 +0300 1341)          */
11c606a6 (kx 2023-04-11 01:18:34 +0300 1342)         _search_pkglog( (const char *)path, (const char *)entry->d_name );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1343)       }
11c606a6 (kx 2023-04-11 01:18:34 +0300 1344)     }
11c606a6 (kx 2023-04-11 01:18:34 +0300 1345)     /* else { stat() returns error code; errno is set; and we have to continue the loop } */
11c606a6 (kx 2023-04-11 01:18:34 +0300 1346)   }
11c606a6 (kx 2023-04-11 01:18:34 +0300 1347) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1348)   closedir( dir );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1349) }
11c606a6 (kx 2023-04-11 01:18:34 +0300 1350) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1351) static char *find_package( void )
11c606a6 (kx 2023-04-11 01:18:34 +0300 1352) {
11c606a6 (kx 2023-04-11 01:18:34 +0300 1353)   char *ret = NULL;
11c606a6 (kx 2023-04-11 01:18:34 +0300 1354) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1355)   _search_pkglog( (const char *)pkgs_path, NULL );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1356)   if( remlog_fname )
11c606a6 (kx 2023-04-11 01:18:34 +0300 1357)   {
11c606a6 (kx 2023-04-11 01:18:34 +0300 1358)     ret = remlog_fname;
11c606a6 (kx 2023-04-11 01:18:34 +0300 1359)   }
11c606a6 (kx 2023-04-11 01:18:34 +0300 1360) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1361)   return ret;
11c606a6 (kx 2023-04-11 01:18:34 +0300 1362) }
11c606a6 (kx 2023-04-11 01:18:34 +0300 1363) /*
11c606a6 (kx 2023-04-11 01:18:34 +0300 1364)   Enf of Find functions.
11c606a6 (kx 2023-04-11 01:18:34 +0300 1365)  ***********************************************************/
11c606a6 (kx 2023-04-11 01:18:34 +0300 1366) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1367) /***********************************************************
11c606a6 (kx 2023-04-11 01:18:34 +0300 1368)   check_installed_package():
11c606a6 (kx 2023-04-11 01:18:34 +0300 1369)   ---------------------
11c606a6 (kx 2023-04-11 01:18:34 +0300 1370) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1371)     Возвращает:
11c606a6 (kx 2023-04-11 01:18:34 +0300 1372)      -1 если пакет установлен, но его версия меньше
11c606a6 (kx 2023-04-11 01:18:34 +0300 1373)         запрашиваемого,
11c606a6 (kx 2023-04-11 01:18:34 +0300 1374)       0 если версия установленного и запрашиваемого равны,
11c606a6 (kx 2023-04-11 01:18:34 +0300 1375)       1 если пакет установлен, но его версия больше
11c606a6 (kx 2023-04-11 01:18:34 +0300 1376)         запрашиваемого.
11c606a6 (kx 2023-04-11 01:18:34 +0300 1377) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1378)     В случае возврата -1 или 1, устанавливается переменная
11c606a6 (kx 2023-04-11 01:18:34 +0300 1379)     instaled_version, равная версии существующего пакета.
11c606a6 (kx 2023-04-11 01:18:34 +0300 1380) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1381)     Если пакет не установлен, осуществляется выход со статусом 30.
11c606a6 (kx 2023-04-11 01:18:34 +0300 1382)  */
11c606a6 (kx 2023-04-11 01:18:34 +0300 1383) static int check_installed_package( void )
11c606a6 (kx 2023-04-11 01:18:34 +0300 1384) {
11c606a6 (kx 2023-04-11 01:18:34 +0300 1385)   struct stat st;
11c606a6 (kx 2023-04-11 01:18:34 +0300 1386)   char *fname = pkg_fname;
11c606a6 (kx 2023-04-11 01:18:34 +0300 1387) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1388)   enum _input_type  type = IFMT_UNKNOWN;
11c606a6 (kx 2023-04-11 01:18:34 +0300 1389)   char              uncompress = '\0';
11c606a6 (kx 2023-04-11 01:18:34 +0300 1390) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1391)   char *requested_version = NULL;
11c606a6 (kx 2023-04-11 01:18:34 +0300 1392)   char *requested_group   = NULL;
11c606a6 (kx 2023-04-11 01:18:34 +0300 1393) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1394)   int ret = 0;
11c606a6 (kx 2023-04-11 01:18:34 +0300 1395) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1396)   bzero( (void *)&st, sizeof( struct stat ) );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1397) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1398)   if( stat( (const char *)fname, &st ) == -1 )
11c606a6 (kx 2023-04-11 01:18:34 +0300 1399)   {
11c606a6 (kx 2023-04-11 01:18:34 +0300 1400)     FATAL_ERROR( "Cannot access input '%s' file: %s", fname, strerror( errno ) );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1401)   }
11c606a6 (kx 2023-04-11 01:18:34 +0300 1402) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1403)   type = check_input_file( &uncompress, fname );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1404)   if( type != IFMT_PKG )
11c606a6 (kx 2023-04-11 01:18:34 +0300 1405)   {
11c606a6 (kx 2023-04-11 01:18:34 +0300 1406)     FATAL_ERROR( "Unknown format of input '%s' file", fname );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1407)   }
11c606a6 (kx 2023-04-11 01:18:34 +0300 1408) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1409)   if( S_ISREG(st.st_mode) )
11c606a6 (kx 2023-04-11 01:18:34 +0300 1410)   {
11c606a6 (kx 2023-04-11 01:18:34 +0300 1411)     pid_t p = (pid_t) -1;
11c606a6 (kx 2023-04-11 01:18:34 +0300 1412)     int   rc;
11c606a6 (kx 2023-04-11 01:18:34 +0300 1413) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1414)     int   len = 0;
11c606a6 (kx 2023-04-11 01:18:34 +0300 1415)     char *tmp= NULL, *cmd = NULL;
11c606a6 (kx 2023-04-11 01:18:34 +0300 1416) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1417)     tmp = (char *)malloc( (size_t)PATH_MAX );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1418)     if( !tmp ) { FATAL_ERROR( "Cannot allocate memory" ); }
11c606a6 (kx 2023-04-11 01:18:34 +0300 1419)     bzero( (void *)tmp, PATH_MAX );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1420) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1421)     (void)sprintf( &tmp[0], "%s", tmpdir );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1422)     if( _mkdir_p( tmp, S_IRWXU | S_IRWXG | S_IRWXO ) != 0 )
11c606a6 (kx 2023-04-11 01:18:34 +0300 1423)     {
11c606a6 (kx 2023-04-11 01:18:34 +0300 1424)       FATAL_ERROR( "Cannot get PKGINFO from '%s' file", basename( (char *)fname ) );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1425)     }
11c606a6 (kx 2023-04-11 01:18:34 +0300 1426) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1427)     cmd = (char *)malloc( (size_t)PATH_MAX );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1428)     if( !cmd ) { FATAL_ERROR( "Cannot allocate memory" ); }
11c606a6 (kx 2023-04-11 01:18:34 +0300 1429)     bzero( (void *)cmd, PATH_MAX );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1430) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1431)     len = snprintf( &cmd[0], PATH_MAX,
11c606a6 (kx 2023-04-11 01:18:34 +0300 1432)                     "%s/pkginfo -d %s -o pkginfo %s > /dev/null 2>&1",
11c606a6 (kx 2023-04-11 01:18:34 +0300 1433)                     selfdir, tmp, fname );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1434)     if( len == 0 || len == PATH_MAX - 1 )
11c606a6 (kx 2023-04-11 01:18:34 +0300 1435)     {
11c606a6 (kx 2023-04-11 01:18:34 +0300 1436)       FATAL_ERROR( "Cannot get PKGINFO from %s file", basename( (char *)fname ) );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1437)     }
11c606a6 (kx 2023-04-11 01:18:34 +0300 1438)     p = sys_exec_command( cmd );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1439)     rc = sys_wait_command( p, (char *)NULL, PATH_MAX );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1440)     if( rc != 0 )
11c606a6 (kx 2023-04-11 01:18:34 +0300 1441)     {
11c606a6 (kx 2023-04-11 01:18:34 +0300 1442)       FATAL_ERROR( "Cannot get PKGINFO from '%s' file", basename( (char *)fname ) );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1443)     }
11c606a6 (kx 2023-04-11 01:18:34 +0300 1444) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1445)     (void)strcat( tmp, "/.PKGINFO" );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1446)     read_pkginfo( (const char *)&tmp[0] );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1447)     (void)unlink( (const char *)&tmp[0] ); /* :remove unnecessary .PKGINFO file */
11c606a6 (kx 2023-04-11 01:18:34 +0300 1448)     *(strstr( tmp, "/.PKGINFO" )) = '\0';  /* :restore 'tmpdir' in tmp[] buffer */
11c606a6 (kx 2023-04-11 01:18:34 +0300 1449) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1450)     requested_version = xstrdup( (const char *)pkgver );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1451)     requested_group   = ( group ) ? xstrdup( (const char *)group ) : NULL;
11c606a6 (kx 2023-04-11 01:18:34 +0300 1452) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1453)     fname = NULL;
11c606a6 (kx 2023-04-11 01:18:34 +0300 1454)     fname = find_package();
11c606a6 (kx 2023-04-11 01:18:34 +0300 1455)     if( !fname )
11c606a6 (kx 2023-04-11 01:18:34 +0300 1456)     {
11c606a6 (kx 2023-04-11 01:18:34 +0300 1457)       if( update_mode != CONSOLE )
11c606a6 (kx 2023-04-11 01:18:34 +0300 1458)       {
11c606a6 (kx 2023-04-11 01:18:34 +0300 1459) #if defined( HAVE_DIALOG )
11c606a6 (kx 2023-04-11 01:18:34 +0300 1460)         info_pkg_box( "Update:", basename( pkg_fname ), NULL, NULL,
11c606a6 (kx 2023-04-11 01:18:34 +0300 1461)                       "\nPackage is not installed.\n", 5, 0, 0 );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1462) #else
11c606a6 (kx 2023-04-11 01:18:34 +0300 1463)         fprintf( stdout, "\nPackage '%s' is not installed.\n\n", basename( pkg_fname ) );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1464) #endif
11c606a6 (kx 2023-04-11 01:18:34 +0300 1465)       }
11c606a6 (kx 2023-04-11 01:18:34 +0300 1466)       else
11c606a6 (kx 2023-04-11 01:18:34 +0300 1467)       {
11c606a6 (kx 2023-04-11 01:18:34 +0300 1468)         fprintf( stdout, "Specified package '%s' is not installed.\n\n", basename( pkg_fname ) );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1469)       }
11c606a6 (kx 2023-04-11 01:18:34 +0300 1470) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1471)       exit_status = 30; /* Package is not installed: install */
11c606a6 (kx 2023-04-11 01:18:34 +0300 1472) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1473)       if( tmpdir ) { _rm_tmpdir( (const char *)tmpdir ); free( tmpdir ); }
11c606a6 (kx 2023-04-11 01:18:34 +0300 1474)       free_resources();
11c606a6 (kx 2023-04-11 01:18:34 +0300 1475) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1476)       exit( exit_status );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1477)     }
11c606a6 (kx 2023-04-11 01:18:34 +0300 1478) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1479)     free( cmd );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1480)     free( tmp );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1481)   }
11c606a6 (kx 2023-04-11 01:18:34 +0300 1482)   else
11c606a6 (kx 2023-04-11 01:18:34 +0300 1483)   {
11c606a6 (kx 2023-04-11 01:18:34 +0300 1484)     FATAL_ERROR( "Input %s file is not a regular file", basename( (char *)fname ) );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1485)   }
11c606a6 (kx 2023-04-11 01:18:34 +0300 1486) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1487) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1488)   /* Now fname is a name of installed PKGLOG file; check fname again: */
11c606a6 (kx 2023-04-11 01:18:34 +0300 1489)   if( stat( (const char *)fname, &st ) == -1 )
11c606a6 (kx 2023-04-11 01:18:34 +0300 1490)   {
11c606a6 (kx 2023-04-11 01:18:34 +0300 1491)     FATAL_ERROR( "Cannot access input '%s' file: %s", fname, strerror( errno ) );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1492)   }
11c606a6 (kx 2023-04-11 01:18:34 +0300 1493) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1494)   type = check_input_file( &uncompress, fname );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1495)   if( type != IFMT_LOG )
11c606a6 (kx 2023-04-11 01:18:34 +0300 1496)   {
11c606a6 (kx 2023-04-11 01:18:34 +0300 1497)     FATAL_ERROR( "Unknown format of input '%s' file", fname );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1498)   }
11c606a6 (kx 2023-04-11 01:18:34 +0300 1499) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1500)   if( S_ISREG(st.st_mode) )
11c606a6 (kx 2023-04-11 01:18:34 +0300 1501)   {
11c606a6 (kx 2023-04-11 01:18:34 +0300 1502)     pid_t p = (pid_t) -1;
11c606a6 (kx 2023-04-11 01:18:34 +0300 1503)     int   rc;
11c606a6 (kx 2023-04-11 01:18:34 +0300 1504) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1505)     int   len = 0;
11c606a6 (kx 2023-04-11 01:18:34 +0300 1506)     char *tmp= NULL, *cmd = NULL;
11c606a6 (kx 2023-04-11 01:18:34 +0300 1507) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1508)     tmp = (char *)malloc( (size_t)PATH_MAX );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1509)     if( !tmp ) { FATAL_ERROR( "Cannot allocate memory" ); }
11c606a6 (kx 2023-04-11 01:18:34 +0300 1510)     bzero( (void *)tmp, PATH_MAX );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1511) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1512)     (void)sprintf( &tmp[0], "%s/to-remove", tmpdir );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1513)     if( _mkdir_p( tmp, S_IRWXU | S_IRWXG | S_IRWXO ) != 0 )
11c606a6 (kx 2023-04-11 01:18:34 +0300 1514)     {
11c606a6 (kx 2023-04-11 01:18:34 +0300 1515)       FATAL_ERROR( "Cannot get PKGINFO from '%s' file", basename( (char *)fname ) );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1516)     }
11c606a6 (kx 2023-04-11 01:18:34 +0300 1517)     rtmpdir = xstrdup( (const char *)&tmp[0] );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1518) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1519)     cmd = (char *)malloc( (size_t)PATH_MAX );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1520)     if( !cmd ) { FATAL_ERROR( "Cannot allocate memory" ); }
11c606a6 (kx 2023-04-11 01:18:34 +0300 1521)     bzero( (void *)cmd, PATH_MAX );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1522) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1523)     len = snprintf( &cmd[0], PATH_MAX,
11c606a6 (kx 2023-04-11 01:18:34 +0300 1524)                     "%s/pkginfo -d %s -o pkginfo,description,restore-links,filelist %s > /dev/null 2>&1",
11c606a6 (kx 2023-04-11 01:18:34 +0300 1525)                     selfdir, tmp, fname );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1526)     if( len == 0 || len == PATH_MAX - 1 )
11c606a6 (kx 2023-04-11 01:18:34 +0300 1527)     {
11c606a6 (kx 2023-04-11 01:18:34 +0300 1528)       FATAL_ERROR( "Cannot get PKGINFO from %s file", basename( (char *)fname ) );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1529)     }
11c606a6 (kx 2023-04-11 01:18:34 +0300 1530)     p = sys_exec_command( cmd );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1531)     rc = sys_wait_command( p, (char *)NULL, PATH_MAX );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1532)     if( rc != 0 )
11c606a6 (kx 2023-04-11 01:18:34 +0300 1533)     {
11c606a6 (kx 2023-04-11 01:18:34 +0300 1534)       FATAL_ERROR( "Cannot get PKGINFO from '%s' file", basename( (char *)fname ) );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1535)     }
11c606a6 (kx 2023-04-11 01:18:34 +0300 1536) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1537)     (void)strcat( tmp, "/.PKGINFO" );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1538)     read_pkginfo( (const char *)&tmp[0] );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1539)     *(strstr( tmp, "/.PKGINFO" )) = '\0'; /* :restore tmpdir in tmp[] buffer */
11c606a6 (kx 2023-04-11 01:18:34 +0300 1540) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1541)     installed_version = xstrdup( (const char *)pkgver );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1542)     installed_group   = ( group ) ? xstrdup( (const char *)group ) : NULL;
11c606a6 (kx 2023-04-11 01:18:34 +0300 1543) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1544)     free( cmd );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1545)     free( tmp );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1546) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1547)     if( requested_group && installed_group )
11c606a6 (kx 2023-04-11 01:18:34 +0300 1548)     {
11c606a6 (kx 2023-04-11 01:18:34 +0300 1549)       if( !(ret = strcmp( (const char *)installed_group, (const char *)requested_group )) )
11c606a6 (kx 2023-04-11 01:18:34 +0300 1550)       {
11c606a6 (kx 2023-04-11 01:18:34 +0300 1551)         ret = cmp_version( (const char *)installed_version, (const char *)requested_version );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1552)       }
11c606a6 (kx 2023-04-11 01:18:34 +0300 1553)     }
11c606a6 (kx 2023-04-11 01:18:34 +0300 1554)     else if( !requested_group && !installed_group )
11c606a6 (kx 2023-04-11 01:18:34 +0300 1555)     {
11c606a6 (kx 2023-04-11 01:18:34 +0300 1556)       ret = cmp_version( (const char *)installed_version, (const char *)requested_version );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1557)     }
11c606a6 (kx 2023-04-11 01:18:34 +0300 1558)     else if( requested_group )
11c606a6 (kx 2023-04-11 01:18:34 +0300 1559)     {
11c606a6 (kx 2023-04-11 01:18:34 +0300 1560)       ret = -1;
11c606a6 (kx 2023-04-11 01:18:34 +0300 1561)     }
11c606a6 (kx 2023-04-11 01:18:34 +0300 1562)     else
11c606a6 (kx 2023-04-11 01:18:34 +0300 1563)     {
11c606a6 (kx 2023-04-11 01:18:34 +0300 1564)       ret = 1;
11c606a6 (kx 2023-04-11 01:18:34 +0300 1565)     }
11c606a6 (kx 2023-04-11 01:18:34 +0300 1566) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1567)     if( requested_version ) { free( requested_version ); }
11c606a6 (kx 2023-04-11 01:18:34 +0300 1568)     if( requested_group )   { free( requested_group );   }
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)     FATAL_ERROR( "Input %s file is not a regular file", basename( (char *)fname ) );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1573)   }
11c606a6 (kx 2023-04-11 01:18:34 +0300 1574) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1575)   return ret;
11c606a6 (kx 2023-04-11 01:18:34 +0300 1576) }
11c606a6 (kx 2023-04-11 01:18:34 +0300 1577) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1578) static int check_installed_pkg_integrity( void )
11c606a6 (kx 2023-04-11 01:18:34 +0300 1579) {
11c606a6 (kx 2023-04-11 01:18:34 +0300 1580)   struct stat st;
11c606a6 (kx 2023-04-11 01:18:34 +0300 1581)   FILE  *fp = NULL;
11c606a6 (kx 2023-04-11 01:18:34 +0300 1582) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1583)   char *ln   = NULL;
11c606a6 (kx 2023-04-11 01:18:34 +0300 1584)   char *line = NULL;
11c606a6 (kx 2023-04-11 01:18:34 +0300 1585) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1586)   char *buf = NULL, *tmp = NULL;
11c606a6 (kx 2023-04-11 01:18:34 +0300 1587) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1588)   int restore_links = 0;
11c606a6 (kx 2023-04-11 01:18:34 +0300 1589)   int ret = 1;
11c606a6 (kx 2023-04-11 01:18:34 +0300 1590) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1591)   buf = (char *)malloc( (size_t)PATH_MAX );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1592)   if( !buf ) { FATAL_ERROR( "Cannot allocate memory" ); }
11c606a6 (kx 2023-04-11 01:18:34 +0300 1593)   bzero( (void *)buf, PATH_MAX );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1594) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1595)   tmp = (char *)malloc( (size_t)PATH_MAX );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1596)   if( !tmp ) { FATAL_ERROR( "Cannot allocate memory" ); }
11c606a6 (kx 2023-04-11 01:18:34 +0300 1597)   bzero( (void *)tmp, PATH_MAX );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1598) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1599)   /* Check if .RESTORELINKS is present */
11c606a6 (kx 2023-04-11 01:18:34 +0300 1600)   (void)sprintf( &tmp[0], "%s/.RESTORELINKS", rtmpdir );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1601)   bzero( (void *)&st, sizeof( struct stat ) );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1602)   if( (stat( (const char *)&tmp[0], &st ) == 0) && (st.st_size > 8) )
11c606a6 (kx 2023-04-11 01:18:34 +0300 1603)   {
11c606a6 (kx 2023-04-11 01:18:34 +0300 1604)     restore_links = 1;
11c606a6 (kx 2023-04-11 01:18:34 +0300 1605)   }
11c606a6 (kx 2023-04-11 01:18:34 +0300 1606) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1607)   (void)sprintf( &tmp[0], "%s/.FILELIST", rtmpdir );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1608)   fp = fopen( (const char *)&tmp[0], "r" );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1609)   if( !fp )
11c606a6 (kx 2023-04-11 01:18:34 +0300 1610)   {
11c606a6 (kx 2023-04-11 01:18:34 +0300 1611)     FATAL_ERROR( "Cannot open .FILELIST file" );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1612)   }
11c606a6 (kx 2023-04-11 01:18:34 +0300 1613) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1614)   line = (char *)malloc( (size_t)PATH_MAX );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1615)   if( !line ) { FATAL_ERROR( "Cannot allocate memory" ); }
11c606a6 (kx 2023-04-11 01:18:34 +0300 1616)   bzero( (void *)line, PATH_MAX );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1617) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1618)   while( (ln = fgets( line, PATH_MAX, fp )) )
11c606a6 (kx 2023-04-11 01:18:34 +0300 1619)   {
11c606a6 (kx 2023-04-11 01:18:34 +0300 1620)     int dir = 0;
11c606a6 (kx 2023-04-11 01:18:34 +0300 1621) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1622)     ln[strlen(ln) - 1] = '\0'; /* replace new-line symbol      */
11c606a6 (kx 2023-04-11 01:18:34 +0300 1623)     skip_eol_spaces( ln );     /* remove spaces at end-of-line */
11c606a6 (kx 2023-04-11 01:18:34 +0300 1624) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1625)     if( *(ln + strlen(ln) - 1) == '/' ) { dir = 1; *(ln + strlen(ln) - 1) = '\0'; }
11c606a6 (kx 2023-04-11 01:18:34 +0300 1626)     else                                { dir = 0; }
11c606a6 (kx 2023-04-11 01:18:34 +0300 1627) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1628)     if( !dir )
11c606a6 (kx 2023-04-11 01:18:34 +0300 1629)     {
11c606a6 (kx 2023-04-11 01:18:34 +0300 1630)       char *p = rindex( ln, '.' );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1631)       if( p && !strncmp( (const char *)p, ".new", 4 ) )
11c606a6 (kx 2023-04-11 01:18:34 +0300 1632)       {
11c606a6 (kx 2023-04-11 01:18:34 +0300 1633)         /**************************
11c606a6 (kx 2023-04-11 01:18:34 +0300 1634)           Do not check .new files:
11c606a6 (kx 2023-04-11 01:18:34 +0300 1635)          */
11c606a6 (kx 2023-04-11 01:18:34 +0300 1636)         *p = '\0';
11c606a6 (kx 2023-04-11 01:18:34 +0300 1637)       }
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)     (void)sprintf( &buf[0], "%s%s", root, ln );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1641)     bzero( (void *)&st, sizeof( struct stat ) );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1642) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1643)     if( lstat( (const char *)&buf[0], &st ) == -1 )
11c606a6 (kx 2023-04-11 01:18:34 +0300 1644)     {
11c606a6 (kx 2023-04-11 01:18:34 +0300 1645)       /* cannot access file list entry */
11c606a6 (kx 2023-04-11 01:18:34 +0300 1646)       ret = 0; continue;
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)     if( dir )
11c606a6 (kx 2023-04-11 01:18:34 +0300 1650)     {
11c606a6 (kx 2023-04-11 01:18:34 +0300 1651)       if( S_ISDIR(st.st_mode) == 0 )
11c606a6 (kx 2023-04-11 01:18:34 +0300 1652)       {
11c606a6 (kx 2023-04-11 01:18:34 +0300 1653)         /* not a directory */
11c606a6 (kx 2023-04-11 01:18:34 +0300 1654)         ret = 0; continue;
11c606a6 (kx 2023-04-11 01:18:34 +0300 1655)       }
11c606a6 (kx 2023-04-11 01:18:34 +0300 1656)     }
11c606a6 (kx 2023-04-11 01:18:34 +0300 1657)     else
11c606a6 (kx 2023-04-11 01:18:34 +0300 1658)     {
11c606a6 (kx 2023-04-11 01:18:34 +0300 1659)       if( S_ISREG(st.st_mode) == 0 )
11c606a6 (kx 2023-04-11 01:18:34 +0300 1660)       {
11c606a6 (kx 2023-04-11 01:18:34 +0300 1661)         /* not a regular file */
11c606a6 (kx 2023-04-11 01:18:34 +0300 1662)         ret = 0; continue;
11c606a6 (kx 2023-04-11 01:18:34 +0300 1663)       }
11c606a6 (kx 2023-04-11 01:18:34 +0300 1664)       if( !restore_links )
11c606a6 (kx 2023-04-11 01:18:34 +0300 1665)       {
11c606a6 (kx 2023-04-11 01:18:34 +0300 1666)         if( S_ISLNK(st.st_mode) == 0 )
11c606a6 (kx 2023-04-11 01:18:34 +0300 1667)         {
11c606a6 (kx 2023-04-11 01:18:34 +0300 1668)           /* not a symbolic link */
11c606a6 (kx 2023-04-11 01:18:34 +0300 1669)           ret = 0; continue;
11c606a6 (kx 2023-04-11 01:18:34 +0300 1670)         }
11c606a6 (kx 2023-04-11 01:18:34 +0300 1671)       }
11c606a6 (kx 2023-04-11 01:18:34 +0300 1672)     }
11c606a6 (kx 2023-04-11 01:18:34 +0300 1673)   } /* End of while( file list entry ) */
11c606a6 (kx 2023-04-11 01:18:34 +0300 1674)   fclose( fp );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1675) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1676) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1677)   (void)sprintf( &tmp[0], "%s/.RESTORELINKS", rtmpdir );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1678)   bzero( (void *)&st, sizeof( struct stat ) );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1679) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1680)   if( stat( (const char *)&tmp[0], &st ) == 0 )
11c606a6 (kx 2023-04-11 01:18:34 +0300 1681)   {
11c606a6 (kx 2023-04-11 01:18:34 +0300 1682)     fp = fopen( (const char *)&tmp[0], "r" );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1683)     if( !fp )
11c606a6 (kx 2023-04-11 01:18:34 +0300 1684)     {
11c606a6 (kx 2023-04-11 01:18:34 +0300 1685)       FATAL_ERROR( "Cannot open .RESTORELINKS file" );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1686)     }
11c606a6 (kx 2023-04-11 01:18:34 +0300 1687) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1688)     while( (ln = fgets( line, PATH_MAX, fp )) )
11c606a6 (kx 2023-04-11 01:18:34 +0300 1689)     {
11c606a6 (kx 2023-04-11 01:18:34 +0300 1690)       char *match = NULL;
11c606a6 (kx 2023-04-11 01:18:34 +0300 1691) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1692)       ln[strlen(ln) - 1] = '\0'; /* replace new-line symbol      */
11c606a6 (kx 2023-04-11 01:18:34 +0300 1693)       skip_eol_spaces( ln );     /* remove spaces at end-of-line */
11c606a6 (kx 2023-04-11 01:18:34 +0300 1694) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1695)       if( (match = strstr( ln, "; rm -rf " )) )
11c606a6 (kx 2023-04-11 01:18:34 +0300 1696)       {
11c606a6 (kx 2023-04-11 01:18:34 +0300 1697)         char *q = NULL;
11c606a6 (kx 2023-04-11 01:18:34 +0300 1698)         char *p = strstr( ln, "cd" ) + 2;
11c606a6 (kx 2023-04-11 01:18:34 +0300 1699)         char *f = strstr( ln, "; rm -rf" ) + 8;
11c606a6 (kx 2023-04-11 01:18:34 +0300 1700) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1701)         if( !p || !f ) continue;
11c606a6 (kx 2023-04-11 01:18:34 +0300 1702) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1703)         while( (*p == ' ' || *p == '\t') && *p != '\0' ) ++p;
11c606a6 (kx 2023-04-11 01:18:34 +0300 1704)         while( (*f == ' ' || *f == '\t') && *f != '\0' ) ++f;
11c606a6 (kx 2023-04-11 01:18:34 +0300 1705) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1706)         q = p; while( *q != ' ' && *q != '\t' && *q != ';' && *q != '\0' ) ++q; *q = '\0';
11c606a6 (kx 2023-04-11 01:18:34 +0300 1707)         q = f; while( *q != ' ' && *q != '\t' && *q != ';' && *q != '\0' ) ++q; *q = '\0';
11c606a6 (kx 2023-04-11 01:18:34 +0300 1708) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1709)         if( p && f )
11c606a6 (kx 2023-04-11 01:18:34 +0300 1710)         {
11c606a6 (kx 2023-04-11 01:18:34 +0300 1711)           (void)sprintf( &buf[0], "%s/%s/%s", root, p, f );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1712)           bzero( (void *)&st, sizeof( struct stat ) );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1713) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1714)           if( lstat( (const char *)&buf[0], &st ) == -1 )
11c606a6 (kx 2023-04-11 01:18:34 +0300 1715)           {
11c606a6 (kx 2023-04-11 01:18:34 +0300 1716)             /* cannot access restore links entry */
11c606a6 (kx 2023-04-11 01:18:34 +0300 1717)             ret = 0; continue;
11c606a6 (kx 2023-04-11 01:18:34 +0300 1718)           }
11c606a6 (kx 2023-04-11 01:18:34 +0300 1719) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1720)           if( S_ISLNK(st.st_mode) == 0 )
11c606a6 (kx 2023-04-11 01:18:34 +0300 1721)           {
11c606a6 (kx 2023-04-11 01:18:34 +0300 1722)             /* not a symbolic link */
11c606a6 (kx 2023-04-11 01:18:34 +0300 1723)             ret = 0; continue;
11c606a6 (kx 2023-04-11 01:18:34 +0300 1724)           }
11c606a6 (kx 2023-04-11 01:18:34 +0300 1725)         }
11c606a6 (kx 2023-04-11 01:18:34 +0300 1726)       }
11c606a6 (kx 2023-04-11 01:18:34 +0300 1727)     } /* End of while( restore links entry ) */
11c606a6 (kx 2023-04-11 01:18:34 +0300 1728)     fclose( fp );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1729)   }
11c606a6 (kx 2023-04-11 01:18:34 +0300 1730) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1731)   free( line );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1732)   free( tmp );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1733)   free( buf );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1734) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1735)   return ret;
11c606a6 (kx 2023-04-11 01:18:34 +0300 1736) }
11c606a6 (kx 2023-04-11 01:18:34 +0300 1737) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1738) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1739) static void read_service_files( void )
11c606a6 (kx 2023-04-11 01:18:34 +0300 1740) {
11c606a6 (kx 2023-04-11 01:18:34 +0300 1741)   struct stat st;
11c606a6 (kx 2023-04-11 01:18:34 +0300 1742)   char *fname = pkg_fname;
11c606a6 (kx 2023-04-11 01:18:34 +0300 1743) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1744)   enum _input_type  type = IFMT_UNKNOWN;
11c606a6 (kx 2023-04-11 01:18:34 +0300 1745) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1746)   bzero( (void *)&st, sizeof( struct stat ) );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1747) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1748)   if( stat( (const char *)fname, &st ) == -1 )
11c606a6 (kx 2023-04-11 01:18:34 +0300 1749)   {
11c606a6 (kx 2023-04-11 01:18:34 +0300 1750)     FATAL_ERROR( "Cannot access input '%s' file: %s", fname, strerror( errno ) );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1751)   }
11c606a6 (kx 2023-04-11 01:18:34 +0300 1752) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1753)   type = check_input_file( &uncompress, fname );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1754)   if( type != IFMT_PKG )
11c606a6 (kx 2023-04-11 01:18:34 +0300 1755)   {
11c606a6 (kx 2023-04-11 01:18:34 +0300 1756)     FATAL_ERROR( "Unknown format of input '%s' file", fname );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1757)   }
11c606a6 (kx 2023-04-11 01:18:34 +0300 1758) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1759)   if( S_ISREG(st.st_mode) )
11c606a6 (kx 2023-04-11 01:18:34 +0300 1760)   {
11c606a6 (kx 2023-04-11 01:18:34 +0300 1761)     pid_t p = (pid_t) -1;
11c606a6 (kx 2023-04-11 01:18:34 +0300 1762)     int   rc;
11c606a6 (kx 2023-04-11 01:18:34 +0300 1763) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1764)     int   len = 0;
11c606a6 (kx 2023-04-11 01:18:34 +0300 1765)     char *tmp= NULL, *cmd = NULL;
11c606a6 (kx 2023-04-11 01:18:34 +0300 1766) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1767)     tmp = (char *)malloc( (size_t)PATH_MAX );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1768)     if( !tmp ) { FATAL_ERROR( "Cannot allocate memory" ); }
11c606a6 (kx 2023-04-11 01:18:34 +0300 1769)     bzero( (void *)tmp, PATH_MAX );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1770) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1771)     (void)sprintf( &tmp[0], "%s", tmpdir );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1772)     if( _mkdir_p( tmp, S_IRWXU | S_IRWXG | S_IRWXO ) != 0 )
11c606a6 (kx 2023-04-11 01:18:34 +0300 1773)     {
11c606a6 (kx 2023-04-11 01:18:34 +0300 1774)       FATAL_ERROR( "Cannot get PKGINFO from '%s' file", basename( (char *)fname ) );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1775)     }
11c606a6 (kx 2023-04-11 01:18:34 +0300 1776) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1777)     cmd = (char *)malloc( (size_t)PATH_MAX );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1778)     if( !cmd ) { FATAL_ERROR( "Cannot allocate memory" ); }
11c606a6 (kx 2023-04-11 01:18:34 +0300 1779)     bzero( (void *)cmd, PATH_MAX );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1780) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1781)     len = snprintf( &cmd[0], PATH_MAX,
11c606a6 (kx 2023-04-11 01:18:34 +0300 1782)                     "%s/pkginfo -d %s"
11c606a6 (kx 2023-04-11 01:18:34 +0300 1783)                     " -o pkginfo,description,requires,restore-links,install-script,filelist"
11c606a6 (kx 2023-04-11 01:18:34 +0300 1784)                     " %s > /dev/null 2>&1",
11c606a6 (kx 2023-04-11 01:18:34 +0300 1785)                     selfdir, tmp, fname );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1786)     if( len == 0 || len == PATH_MAX - 1 )
11c606a6 (kx 2023-04-11 01:18:34 +0300 1787)     {
11c606a6 (kx 2023-04-11 01:18:34 +0300 1788)       FATAL_ERROR( "Cannot get PKGINFO from %s file", basename( (char *)fname ) );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1789)     }
11c606a6 (kx 2023-04-11 01:18:34 +0300 1790)     p = sys_exec_command( cmd );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1791)     rc = sys_wait_command( p, (char *)NULL, PATH_MAX );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1792)     if( rc != 0 )
11c606a6 (kx 2023-04-11 01:18:34 +0300 1793)     {
11c606a6 (kx 2023-04-11 01:18:34 +0300 1794)       FATAL_ERROR( "Cannot get PKGINFO from '%s' file", basename( (char *)fname ) );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1795)     }
11c606a6 (kx 2023-04-11 01:18:34 +0300 1796) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1797)     (void)strcat( tmp, "/.PKGINFO" );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1798)     read_pkginfo( (const char *)&tmp[0] );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1799)     *(strstr( tmp, "/.PKGINFO" )) = '\0'; /* :restore tmpdir in tmp[] buffer */
11c606a6 (kx 2023-04-11 01:18:34 +0300 1800) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1801)     compressed_size = size_to_string( st.st_size );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1802) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1803)     /******************
11c606a6 (kx 2023-04-11 01:18:34 +0300 1804)       Get PKGLOG file:
11c606a6 (kx 2023-04-11 01:18:34 +0300 1805)      */
11c606a6 (kx 2023-04-11 01:18:34 +0300 1806)     len = snprintf( &cmd[0], PATH_MAX,
11c606a6 (kx 2023-04-11 01:18:34 +0300 1807)                     "%s/pkglog -m -d %s %s  > /dev/null 2>&1",
11c606a6 (kx 2023-04-11 01:18:34 +0300 1808)                     selfdir, tmp, tmp );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1809)     if( len == 0 || len == PATH_MAX - 1 )
11c606a6 (kx 2023-04-11 01:18:34 +0300 1810)     {
11c606a6 (kx 2023-04-11 01:18:34 +0300 1811)       FATAL_ERROR( "Cannot get PKGLOG from %s file", basename( (char *)fname ) );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1812)     }
11c606a6 (kx 2023-04-11 01:18:34 +0300 1813)     p = sys_exec_command( cmd );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1814)     rc = sys_wait_command( p, (char *)NULL, PATH_MAX );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1815)     if( rc != 0 )
11c606a6 (kx 2023-04-11 01:18:34 +0300 1816)     {
11c606a6 (kx 2023-04-11 01:18:34 +0300 1817)       FATAL_ERROR( "Cannot get PKGLOG from '%s' file", basename( (char *)fname ) );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1818)     }
11c606a6 (kx 2023-04-11 01:18:34 +0300 1819) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1820)     if( group )
11c606a6 (kx 2023-04-11 01:18:34 +0300 1821)       (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 1822)     else
11c606a6 (kx 2023-04-11 01:18:34 +0300 1823)       (void)sprintf( cmd, "%s/%s-%s-%s-%s-%s", tmp, pkgname, pkgver, arch, distroname, distrover );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1824) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1825)     bzero( (void *)&st, sizeof( struct stat ) );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1826)     if( stat( (const char *)cmd, &st ) == -1 )
11c606a6 (kx 2023-04-11 01:18:34 +0300 1827)     {
11c606a6 (kx 2023-04-11 01:18:34 +0300 1828)       FATAL_ERROR( "Cannot get PKGLOG from '%s' file: %s", basename( (char *)fname ), strerror( errno ) );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1829)     }
11c606a6 (kx 2023-04-11 01:18:34 +0300 1830) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1831)     pkglog_fname = xstrdup( (const char *)cmd );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1832) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1833)     /*************************************
11c606a6 (kx 2023-04-11 01:18:34 +0300 1834)       Attempt to read packages list file:
11c606a6 (kx 2023-04-11 01:18:34 +0300 1835)      */
11c606a6 (kx 2023-04-11 01:18:34 +0300 1836)     {
11c606a6 (kx 2023-04-11 01:18:34 +0300 1837)       if( !pkglist_fname )
11c606a6 (kx 2023-04-11 01:18:34 +0300 1838)       {
11c606a6 (kx 2023-04-11 01:18:34 +0300 1839)         /*****************************************
11c606a6 (kx 2023-04-11 01:18:34 +0300 1840)           Get source packages path if applicable:
11c606a6 (kx 2023-04-11 01:18:34 +0300 1841)          */
11c606a6 (kx 2023-04-11 01:18:34 +0300 1842)         (void)strcpy( cmd, (const char *)fname );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1843)         (void)strcpy( tmp, dirname( cmd ) );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1844) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1845)         if( group && !strcmp( group, basename( tmp ) ) )
11c606a6 (kx 2023-04-11 01:18:34 +0300 1846)           (void)strcpy( cmd, (const char *)dirname( tmp ) );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1847)         else
11c606a6 (kx 2023-04-11 01:18:34 +0300 1848)           (void)strcpy( cmd, (const char *)tmp );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1849) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1850)         /*****************************************
11c606a6 (kx 2023-04-11 01:18:34 +0300 1851)           Save default packages list file name:
11c606a6 (kx 2023-04-11 01:18:34 +0300 1852)          */
11c606a6 (kx 2023-04-11 01:18:34 +0300 1853)         (void)strcat( cmd, "/.pkglist" );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1854)         pkglist_fname = xstrdup( (const char *)cmd );
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)       /**************************
11c606a6 (kx 2023-04-11 01:18:34 +0300 1858)         read .pkglist if exists:
11c606a6 (kx 2023-04-11 01:18:34 +0300 1859)        */
11c606a6 (kx 2023-04-11 01:18:34 +0300 1860)       bzero( (void *)&st, sizeof( struct stat ) );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1861)       if( (stat( (const char *)pkglist_fname, &st ) == 0) && S_ISREG(st.st_mode) )
11c606a6 (kx 2023-04-11 01:18:34 +0300 1862)       {
11c606a6 (kx 2023-04-11 01:18:34 +0300 1863)         char *ln      = NULL;
11c606a6 (kx 2023-04-11 01:18:34 +0300 1864)         char *line    = NULL;
11c606a6 (kx 2023-04-11 01:18:34 +0300 1865) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1866)         FILE *pkglist = NULL;
11c606a6 (kx 2023-04-11 01:18:34 +0300 1867) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1868)         pkglist = fopen( (const char *)pkglist_fname, "r" );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1869)         if( !pkglist )
11c606a6 (kx 2023-04-11 01:18:34 +0300 1870)         {
11c606a6 (kx 2023-04-11 01:18:34 +0300 1871)           FATAL_ERROR( "Cannot open %s file", pkglist_fname );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1872)         }
11c606a6 (kx 2023-04-11 01:18:34 +0300 1873) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1874)         line = (char *)malloc( (size_t)PATH_MAX );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1875)         if( !line )
11c606a6 (kx 2023-04-11 01:18:34 +0300 1876)         {
11c606a6 (kx 2023-04-11 01:18:34 +0300 1877)           FATAL_ERROR( "Cannot allocate memory" );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1878)         }
11c606a6 (kx 2023-04-11 01:18:34 +0300 1879) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1880)         while( (ln = fgets( line, PATH_MAX, pkglist )) )
11c606a6 (kx 2023-04-11 01:18:34 +0300 1881)         {
11c606a6 (kx 2023-04-11 01:18:34 +0300 1882)           char *match = NULL;
11c606a6 (kx 2023-04-11 01:18:34 +0300 1883) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1884)           ln[strlen(ln) - 1] = '\0'; /* replace new-line symbol      */
11c606a6 (kx 2023-04-11 01:18:34 +0300 1885)           skip_eol_spaces( ln );     /* remove spaces at end-of-line */
11c606a6 (kx 2023-04-11 01:18:34 +0300 1886) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1887)           if( (match = strstr( ln, pkgname )) && match == ln )
11c606a6 (kx 2023-04-11 01:18:34 +0300 1888)           {
11c606a6 (kx 2023-04-11 01:18:34 +0300 1889)             char *p = NULL;
11c606a6 (kx 2023-04-11 01:18:34 +0300 1890)             char *name = NULL, *vers = NULL, *desc = NULL, *ball = NULL, *proc = NULL, *prio = NULL;
11c606a6 (kx 2023-04-11 01:18:34 +0300 1891) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1892)             name = ln;
11c606a6 (kx 2023-04-11 01:18:34 +0300 1893)             if( (p = index( (const char *)name, ':' )) ) { *p = '\0'; vers = ++p; name = trim( name ); } else continue;
11c606a6 (kx 2023-04-11 01:18:34 +0300 1894)             if( (p = index( (const char *)vers, ':' )) ) { *p = '\0'; desc = ++p; vers = trim( vers ); } else continue;
11c606a6 (kx 2023-04-11 01:18:34 +0300 1895)             if( (p = index( (const char *)desc, ':' )) ) { *p = '\0'; ball = ++p; desc = trim( desc ); } else continue;
11c606a6 (kx 2023-04-11 01:18:34 +0300 1896)             if( (p = index( (const char *)ball, ':' )) ) { *p = '\0'; proc = ++p; ball = trim( ball ); } else continue;
11c606a6 (kx 2023-04-11 01:18:34 +0300 1897)             if( (p = index( (const char *)proc, ':' )) ) { *p = '\0'; prio = ++p; proc = trim( proc ); } else continue;
11c606a6 (kx 2023-04-11 01:18:34 +0300 1898)             prio = trim( prio );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1899) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1900)             if( name && vers && desc && ball && proc && prio )
11c606a6 (kx 2023-04-11 01:18:34 +0300 1901)             {
11c606a6 (kx 2023-04-11 01:18:34 +0300 1902)               char *grp = index( (const char *)ball, '/' );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1903)               if( grp )
11c606a6 (kx 2023-04-11 01:18:34 +0300 1904)               {
11c606a6 (kx 2023-04-11 01:18:34 +0300 1905)                 *grp = '\0'; grp = ball; grp = trim( grp );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1906)                 if( strcmp( group, grp ) ) continue;
11c606a6 (kx 2023-04-11 01:18:34 +0300 1907)               }
11c606a6 (kx 2023-04-11 01:18:34 +0300 1908) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1909)               /* read priority: */
11c606a6 (kx 2023-04-11 01:18:34 +0300 1910)               if( strlen( (const char*)prio ) > 2 )
11c606a6 (kx 2023-04-11 01:18:34 +0300 1911)               {
11c606a6 (kx 2023-04-11 01:18:34 +0300 1912)                 char *m = NULL;
11c606a6 (kx 2023-04-11 01:18:34 +0300 1913) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1914)                 to_lowercase( prio );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1915)                 if( (m = strstr( prio, "req" )) && m == prio ) {
11c606a6 (kx 2023-04-11 01:18:34 +0300 1916)                   priority = REQUIRED;
11c606a6 (kx 2023-04-11 01:18:34 +0300 1917)                 }
11c606a6 (kx 2023-04-11 01:18:34 +0300 1918)                 else if( (m = strstr( prio, "rec" )) && m == prio ) {
11c606a6 (kx 2023-04-11 01:18:34 +0300 1919)                   priority = RECOMMENDED;
11c606a6 (kx 2023-04-11 01:18:34 +0300 1920)                 }
11c606a6 (kx 2023-04-11 01:18:34 +0300 1921)                 else if( (m = strstr( prio, "opt" )) && m == prio ) {
11c606a6 (kx 2023-04-11 01:18:34 +0300 1922)                   priority = OPTIONAL;
11c606a6 (kx 2023-04-11 01:18:34 +0300 1923)                 }
11c606a6 (kx 2023-04-11 01:18:34 +0300 1924)                 else if( (m = strstr( prio, "sk" )) && m == prio ) {
11c606a6 (kx 2023-04-11 01:18:34 +0300 1925)                   priority = SKIP;
11c606a6 (kx 2023-04-11 01:18:34 +0300 1926)                 }
11c606a6 (kx 2023-04-11 01:18:34 +0300 1927)                 else {
11c606a6 (kx 2023-04-11 01:18:34 +0300 1928)                   priority = REQUIRED;
11c606a6 (kx 2023-04-11 01:18:34 +0300 1929)                 }
11c606a6 (kx 2023-04-11 01:18:34 +0300 1930)               }
11c606a6 (kx 2023-04-11 01:18:34 +0300 1931)               else
11c606a6 (kx 2023-04-11 01:18:34 +0300 1932)               {
11c606a6 (kx 2023-04-11 01:18:34 +0300 1933)                 priority = REQUIRED;
11c606a6 (kx 2023-04-11 01:18:34 +0300 1934)               }
11c606a6 (kx 2023-04-11 01:18:34 +0300 1935) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1936)               /* read procedure: */
11c606a6 (kx 2023-04-11 01:18:34 +0300 1937)               if( strlen( (const char*)proc ) > 5 )
11c606a6 (kx 2023-04-11 01:18:34 +0300 1938)               {
11c606a6 (kx 2023-04-11 01:18:34 +0300 1939)                 char *m = NULL;
11c606a6 (kx 2023-04-11 01:18:34 +0300 1940) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1941)                 to_lowercase( proc );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1942)                 if( (m = strstr( proc, "install" )) && m == proc ) {
11c606a6 (kx 2023-04-11 01:18:34 +0300 1943)                   procedure = INSTALL;
11c606a6 (kx 2023-04-11 01:18:34 +0300 1944)                 }
11c606a6 (kx 2023-04-11 01:18:34 +0300 1945)                 else if( (m = strstr( proc, "update" )) && m == proc ) {
11c606a6 (kx 2023-04-11 01:18:34 +0300 1946)                   procedure = UPDATE;
11c606a6 (kx 2023-04-11 01:18:34 +0300 1947)                 }
11c606a6 (kx 2023-04-11 01:18:34 +0300 1948)                 else {
11c606a6 (kx 2023-04-11 01:18:34 +0300 1949)                   procedure = UPDATE;
11c606a6 (kx 2023-04-11 01:18:34 +0300 1950)                 }
11c606a6 (kx 2023-04-11 01:18:34 +0300 1951)               }
11c606a6 (kx 2023-04-11 01:18:34 +0300 1952)               else
11c606a6 (kx 2023-04-11 01:18:34 +0300 1953)               {
11c606a6 (kx 2023-04-11 01:18:34 +0300 1954)                 procedure = UPDATE;
11c606a6 (kx 2023-04-11 01:18:34 +0300 1955)               }
11c606a6 (kx 2023-04-11 01:18:34 +0300 1956)             }
11c606a6 (kx 2023-04-11 01:18:34 +0300 1957) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1958)           } /* End if( match ) */
11c606a6 (kx 2023-04-11 01:18:34 +0300 1959) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1960)         } /* End of while( ln = fgets() ) */
11c606a6 (kx 2023-04-11 01:18:34 +0300 1961) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1962)         free( line );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1963)         fclose( pkglist );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1964) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1965)       } /* End of reading .pkglist */
11c606a6 (kx 2023-04-11 01:18:34 +0300 1966) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1967)     } /* End of attemption of reading .pkflist file */
11c606a6 (kx 2023-04-11 01:18:34 +0300 1968) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1969)     free( cmd );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1970)     free( tmp );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1971) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1972)     if( priority == SKIP )
11c606a6 (kx 2023-04-11 01:18:34 +0300 1973)     {
11c606a6 (kx 2023-04-11 01:18:34 +0300 1974)       exit_status = 41;
11c606a6 (kx 2023-04-11 01:18:34 +0300 1975) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1976)       if( update_mode != CONSOLE )
11c606a6 (kx 2023-04-11 01:18:34 +0300 1977)       {
11c606a6 (kx 2023-04-11 01:18:34 +0300 1978) #if defined( HAVE_DIALOG )
11c606a6 (kx 2023-04-11 01:18:34 +0300 1979)         char *tmp = NULL;
11c606a6 (kx 2023-04-11 01:18:34 +0300 1980) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1981)         tmp = (char *)malloc( (size_t)PATH_MAX );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1982)         if( !tmp ) { FATAL_ERROR( "Cannot allocate memory" ); }
11c606a6 (kx 2023-04-11 01:18:34 +0300 1983)         bzero( (void *)tmp, PATH_MAX );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1984) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1985)         (void)sprintf( &tmp[0],
11c606a6 (kx 2023-04-11 01:18:34 +0300 1986)                        "\nUpdate procedure is skipped due to specified '%s' priority.\n",
11c606a6 (kx 2023-04-11 01:18:34 +0300 1987)                        strprio( priority, 0 ) );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1988) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1989)         info_pkg_box( "Update:", pkgname, pkgver, strprio( priority, 0 ),
11c606a6 (kx 2023-04-11 01:18:34 +0300 1990)                       (const char *)&tmp[0], 5, 0, 0 );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1991) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 1992)         free( tmp );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1993) #else
11c606a6 (kx 2023-04-11 01:18:34 +0300 1994)         fprintf( stdout,
11c606a6 (kx 2023-04-11 01:18:34 +0300 1995)                  "\nUpdate procedure of package '%s-%s' is skipped due to specified '%s' priority.\n\n",
11c606a6 (kx 2023-04-11 01:18:34 +0300 1996)                  pkgname, pkgver, strprio( priority, 0 ) );
11c606a6 (kx 2023-04-11 01:18:34 +0300 1997) #endif
11c606a6 (kx 2023-04-11 01:18:34 +0300 1998)       }
11c606a6 (kx 2023-04-11 01:18:34 +0300 1999)       else
11c606a6 (kx 2023-04-11 01:18:34 +0300 2000)       {
11c606a6 (kx 2023-04-11 01:18:34 +0300 2001)         fprintf( stdout,
11c606a6 (kx 2023-04-11 01:18:34 +0300 2002)                  "\nUpdate procedure of package '%s-%s' is skipped due to specified '%s' priority.\n\n",
11c606a6 (kx 2023-04-11 01:18:34 +0300 2003)                  pkgname, pkgver, strprio( priority, 0 ) );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2004)       }
11c606a6 (kx 2023-04-11 01:18:34 +0300 2005) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 2006)       if( tmpdir ) { _rm_tmpdir( (const char *)tmpdir ); free( tmpdir ); }
11c606a6 (kx 2023-04-11 01:18:34 +0300 2007)       free_resources();
11c606a6 (kx 2023-04-11 01:18:34 +0300 2008) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 2009)       exit( exit_status );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2010)     }
11c606a6 (kx 2023-04-11 01:18:34 +0300 2011) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 2012)     if( procedure != UPDATE )
11c606a6 (kx 2023-04-11 01:18:34 +0300 2013)     {
11c606a6 (kx 2023-04-11 01:18:34 +0300 2014)       exit_status = 42;
11c606a6 (kx 2023-04-11 01:18:34 +0300 2015) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 2016)       if( update_mode != CONSOLE )
11c606a6 (kx 2023-04-11 01:18:34 +0300 2017)       {
11c606a6 (kx 2023-04-11 01:18:34 +0300 2018) #if defined( HAVE_DIALOG )
11c606a6 (kx 2023-04-11 01:18:34 +0300 2019)         char *tmp = NULL;
11c606a6 (kx 2023-04-11 01:18:34 +0300 2020) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 2021)         tmp = (char *)malloc( (size_t)PATH_MAX );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2022)         if( !tmp ) { FATAL_ERROR( "Cannot allocate memory" ); }
11c606a6 (kx 2023-04-11 01:18:34 +0300 2023)         bzero( (void *)tmp, PATH_MAX );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2024) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 2025)         (void)sprintf( &tmp[0],
11c606a6 (kx 2023-04-11 01:18:34 +0300 2026)                        "\nUpdate is skipped because the '%s' procedure is specified.\n",
11c606a6 (kx 2023-04-11 01:18:34 +0300 2027)                        strproc( procedure ) );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2028) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 2029)         info_pkg_box( "Update:", pkgname, pkgver, strprio( priority, 0 ),
11c606a6 (kx 2023-04-11 01:18:34 +0300 2030)                       (const char *)&tmp[0], 6, 0, 0 );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2031) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 2032)         free( tmp );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2033) #else
11c606a6 (kx 2023-04-11 01:18:34 +0300 2034)         fprintf( stdout,
11c606a6 (kx 2023-04-11 01:18:34 +0300 2035)                  "\nUpdate procedure of package '%s-%s' is skipped because the '%s' procedure is specified.\n\n",
11c606a6 (kx 2023-04-11 01:18:34 +0300 2036)                  pkgname, pkgver, strproc( procedure ) );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2037) #endif
11c606a6 (kx 2023-04-11 01:18:34 +0300 2038)       }
11c606a6 (kx 2023-04-11 01:18:34 +0300 2039)       else
11c606a6 (kx 2023-04-11 01:18:34 +0300 2040)       {
11c606a6 (kx 2023-04-11 01:18:34 +0300 2041)         fprintf( stdout,
11c606a6 (kx 2023-04-11 01:18:34 +0300 2042)                  "\nUpdate procedure of package '%s-%s' is skipped because the '%s' procedure is specified.\n\n",
11c606a6 (kx 2023-04-11 01:18:34 +0300 2043)                  pkgname, pkgver, strproc( procedure ) );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2044)       }
11c606a6 (kx 2023-04-11 01:18:34 +0300 2045) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 2046)       if( tmpdir ) { _rm_tmpdir( (const char *)tmpdir ); free( tmpdir ); }
11c606a6 (kx 2023-04-11 01:18:34 +0300 2047)       free_resources();
11c606a6 (kx 2023-04-11 01:18:34 +0300 2048) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 2049)       exit( exit_status );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2050)     }
11c606a6 (kx 2023-04-11 01:18:34 +0300 2051) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 2052)   }
11c606a6 (kx 2023-04-11 01:18:34 +0300 2053)   else
11c606a6 (kx 2023-04-11 01:18:34 +0300 2054)   {
11c606a6 (kx 2023-04-11 01:18:34 +0300 2055)     FATAL_ERROR( "Input %s file is not a regular file", basename( (char *)fname ) );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2056)   }
11c606a6 (kx 2023-04-11 01:18:34 +0300 2057) }
11c606a6 (kx 2023-04-11 01:18:34 +0300 2058) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 2059) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 2060) static void check_requires( void )
11c606a6 (kx 2023-04-11 01:18:34 +0300 2061) {
11c606a6 (kx 2023-04-11 01:18:34 +0300 2062)   pid_t p = (pid_t) -1;
11c606a6 (kx 2023-04-11 01:18:34 +0300 2063)   int   rc;
11c606a6 (kx 2023-04-11 01:18:34 +0300 2064) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 2065)   int   len = 0;
11c606a6 (kx 2023-04-11 01:18:34 +0300 2066)   char *cmd = NULL;
11c606a6 (kx 2023-04-11 01:18:34 +0300 2067) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 2068)   cmd = (char *)malloc( (size_t)PATH_MAX );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2069)   if( !cmd ) { FATAL_ERROR( "Cannot allocate memory" ); }
11c606a6 (kx 2023-04-11 01:18:34 +0300 2070)   bzero( (void *)cmd, PATH_MAX );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2071) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 2072)   len = snprintf( &cmd[0], PATH_MAX,
11c606a6 (kx 2023-04-11 01:18:34 +0300 2073)                   "%s/check-requires --root=%s %s > /dev/null 2>&1",
11c606a6 (kx 2023-04-11 01:18:34 +0300 2074)                   selfdir, root, pkglog_fname );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2075)   if( len == 0 || len == PATH_MAX - 1 )
11c606a6 (kx 2023-04-11 01:18:34 +0300 2076)   {
11c606a6 (kx 2023-04-11 01:18:34 +0300 2077)     FATAL_ERROR( "Cannot check required packages for '%s-%s' package", pkgname, pkgver );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2078)   }
11c606a6 (kx 2023-04-11 01:18:34 +0300 2079)   p = sys_exec_command( cmd );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2080)   rc = sys_wait_command( p, (char *)NULL, PATH_MAX );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2081) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 2082)   free( cmd );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2083) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 2084)   if( rc != 0 )
11c606a6 (kx 2023-04-11 01:18:34 +0300 2085)   {
11c606a6 (kx 2023-04-11 01:18:34 +0300 2086)     if( update_mode != CONSOLE )
11c606a6 (kx 2023-04-11 01:18:34 +0300 2087)     {
11c606a6 (kx 2023-04-11 01:18:34 +0300 2088) #if defined( HAVE_DIALOG )
11c606a6 (kx 2023-04-11 01:18:34 +0300 2089)       info_pkg_box( "Update:", pkgname, pkgver, strprio( priority, 0 ),
11c606a6 (kx 2023-04-11 01:18:34 +0300 2090)                     "\nPackage requires other packages to be installed.\n", 5, 0, 0 );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2091) #else
11c606a6 (kx 2023-04-11 01:18:34 +0300 2092)       fprintf( stdout, "\nPackage '%s-%s' requires other packages to be installed.\n\n", pkgname, pkgver );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2093) #endif
11c606a6 (kx 2023-04-11 01:18:34 +0300 2094)     }
11c606a6 (kx 2023-04-11 01:18:34 +0300 2095)     else
11c606a6 (kx 2023-04-11 01:18:34 +0300 2096)     {
11c606a6 (kx 2023-04-11 01:18:34 +0300 2097)       fprintf( stdout, "\nPackage '%s-%s' requires other packages to be installed.\n\n", pkgname, pkgver );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2098)     }
11c606a6 (kx 2023-04-11 01:18:34 +0300 2099) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 2100)     if( tmpdir ) { _rm_tmpdir( (const char *)tmpdir ); free( tmpdir ); }
11c606a6 (kx 2023-04-11 01:18:34 +0300 2101)     free_resources();
11c606a6 (kx 2023-04-11 01:18:34 +0300 2102)     exit( rc );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2103)   }
11c606a6 (kx 2023-04-11 01:18:34 +0300 2104) }
11c606a6 (kx 2023-04-11 01:18:34 +0300 2105) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 2106) /********************************************************
11c606a6 (kx 2023-04-11 01:18:34 +0300 2107)   Read .FILELIST and .RESTORELINKS functions used for
11c606a6 (kx 2023-04-11 01:18:34 +0300 2108)   roolback/remove in case post-update errors:
11c606a6 (kx 2023-04-11 01:18:34 +0300 2109)  */
11c606a6 (kx 2023-04-11 01:18:34 +0300 2110) static int __cmp_list_items( const void *a, const void *b )
11c606a6 (kx 2023-04-11 01:18:34 +0300 2111) {
11c606a6 (kx 2023-04-11 01:18:34 +0300 2112)   if( a && b )
11c606a6 (kx 2023-04-11 01:18:34 +0300 2113)     return strcmp( (const char *)a, (const char *)b );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2114)   else if( a )
11c606a6 (kx 2023-04-11 01:18:34 +0300 2115)     return 1;
11c606a6 (kx 2023-04-11 01:18:34 +0300 2116)   else
11c606a6 (kx 2023-04-11 01:18:34 +0300 2117)     return -1;
11c606a6 (kx 2023-04-11 01:18:34 +0300 2118) }
11c606a6 (kx 2023-04-11 01:18:34 +0300 2119) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 2120) static void __free_list( void *data, void *user_data )
11c606a6 (kx 2023-04-11 01:18:34 +0300 2121) {
11c606a6 (kx 2023-04-11 01:18:34 +0300 2122)   if( data ) { free( data ); }
11c606a6 (kx 2023-04-11 01:18:34 +0300 2123) }
11c606a6 (kx 2023-04-11 01:18:34 +0300 2124) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 2125) static void free_list( struct dlist *list )
11c606a6 (kx 2023-04-11 01:18:34 +0300 2126) {
11c606a6 (kx 2023-04-11 01:18:34 +0300 2127)   if( list ) { dlist_free( list, __free_list ); }
11c606a6 (kx 2023-04-11 01:18:34 +0300 2128) }
11c606a6 (kx 2023-04-11 01:18:34 +0300 2129) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 2130) ////////////////////////////////////////////////////
11c606a6 (kx 2023-04-11 01:18:34 +0300 2131) //static void __print_list( void *data, void *user_data )
11c606a6 (kx 2023-04-11 01:18:34 +0300 2132) //{
11c606a6 (kx 2023-04-11 01:18:34 +0300 2133) //  int *counter = (int *)user_data;
11c606a6 (kx 2023-04-11 01:18:34 +0300 2134) //
11c606a6 (kx 2023-04-11 01:18:34 +0300 2135) //  if( counter ) { fprintf( stdout, "item[%.5d]: %s\n", *counter, (char *)data ); ++(*counter); }
11c606a6 (kx 2023-04-11 01:18:34 +0300 2136) //  else          { fprintf( stdout, "item: %s\n", (char *)data ); }
11c606a6 (kx 2023-04-11 01:18:34 +0300 2137) //}
11c606a6 (kx 2023-04-11 01:18:34 +0300 2138) //
11c606a6 (kx 2023-04-11 01:18:34 +0300 2139) //static void print_list( struct dlist *list )
11c606a6 (kx 2023-04-11 01:18:34 +0300 2140) //{
11c606a6 (kx 2023-04-11 01:18:34 +0300 2141) //  int cnt = 0;
11c606a6 (kx 2023-04-11 01:18:34 +0300 2142) //  if( list ) { dlist_foreach( list, __print_list, (void *)&cnt ); }
11c606a6 (kx 2023-04-11 01:18:34 +0300 2143) //}
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) static void read_filelist( void **d, void **f, const char *path )
11c606a6 (kx 2023-04-11 01:18:34 +0300 2147) {
11c606a6 (kx 2023-04-11 01:18:34 +0300 2148)   struct stat st;
11c606a6 (kx 2023-04-11 01:18:34 +0300 2149)   FILE  *fp = NULL;
11c606a6 (kx 2023-04-11 01:18:34 +0300 2150) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 2151)   char *ln   = NULL;
11c606a6 (kx 2023-04-11 01:18:34 +0300 2152)   char *line = NULL, *tmp = NULL;
11c606a6 (kx 2023-04-11 01:18:34 +0300 2153) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 2154)   struct dlist *dirs  = (struct dlist *)(*d);
11c606a6 (kx 2023-04-11 01:18:34 +0300 2155)   struct dlist *files = (struct dlist *)(*f);
11c606a6 (kx 2023-04-11 01:18:34 +0300 2156) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 2157)   if( !dirs || !files || !path ) return;
11c606a6 (kx 2023-04-11 01:18:34 +0300 2158) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 2159)   tmp = (char *)malloc( (size_t)PATH_MAX );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2160)   if( !tmp ) { FATAL_ERROR( "Cannot allocate memory" ); }
11c606a6 (kx 2023-04-11 01:18:34 +0300 2161)   bzero( (void *)tmp, PATH_MAX );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2162) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 2163)   (void)sprintf( &tmp[0], "%s/.FILELIST", path );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2164)   bzero( (void *)&st, sizeof( struct stat ) );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2165)   if( (stat( (const char *)&tmp[0], &st ) == -1) )
11c606a6 (kx 2023-04-11 01:18:34 +0300 2166)   {
11c606a6 (kx 2023-04-11 01:18:34 +0300 2167)     FATAL_ERROR( "Cannot get .FILELIST from '%s' file", basename( (char *)pkglog_fname ) );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2168)   }
11c606a6 (kx 2023-04-11 01:18:34 +0300 2169) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 2170)   fp = fopen( (const char *)&tmp[0], "r" );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2171)   if( !fp )
11c606a6 (kx 2023-04-11 01:18:34 +0300 2172)   {
11c606a6 (kx 2023-04-11 01:18:34 +0300 2173)     FATAL_ERROR( "Cannot open .FILELIST file" );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2174)   }
11c606a6 (kx 2023-04-11 01:18:34 +0300 2175) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 2176)   line = (char *)malloc( (size_t)PATH_MAX );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2177)   if( !line ) { FATAL_ERROR( "Cannot allocate memory" ); }
11c606a6 (kx 2023-04-11 01:18:34 +0300 2178)   bzero( (void *)line, PATH_MAX );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2179) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 2180)   while( (ln = fgets( line, PATH_MAX, fp )) )
11c606a6 (kx 2023-04-11 01:18:34 +0300 2181)   {
11c606a6 (kx 2023-04-11 01:18:34 +0300 2182)     ln[strlen(ln) - 1] = '\0'; /* replace new-line symbol      */
11c606a6 (kx 2023-04-11 01:18:34 +0300 2183)     skip_eol_spaces( ln );     /* remove spaces at end-of-line */
11c606a6 (kx 2023-04-11 01:18:34 +0300 2184) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 2185)     if( *(ln + strlen(ln) - 1) == '/' )
11c606a6 (kx 2023-04-11 01:18:34 +0300 2186)     {
11c606a6 (kx 2023-04-11 01:18:34 +0300 2187)       *(ln + strlen(ln) - 1) = '\0';
11c606a6 (kx 2023-04-11 01:18:34 +0300 2188)       (void)sprintf( &tmp[0], "%s%s", (const char *)root, (const char *)ln );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2189)       dirs = dlist_append( dirs, xstrdup( (const char *)&tmp[0] ) );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2190)     }
11c606a6 (kx 2023-04-11 01:18:34 +0300 2191)     else
11c606a6 (kx 2023-04-11 01:18:34 +0300 2192)     {
11c606a6 (kx 2023-04-11 01:18:34 +0300 2193)       (void)sprintf( &tmp[0], "%s%s", (const char *)root, (const char *)ln );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2194)       files = dlist_append( files, xstrdup( (const char *)&tmp[0] ) );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2195)     }
11c606a6 (kx 2023-04-11 01:18:34 +0300 2196) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 2197)   } /* End of while( file list entry ) */
11c606a6 (kx 2023-04-11 01:18:34 +0300 2198) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 2199)   fclose( fp );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2200) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 2201)   free( line );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2202)   free( tmp );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2203) }
11c606a6 (kx 2023-04-11 01:18:34 +0300 2204) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 2205) static void read_restorelinks( void **l, const char *path )
11c606a6 (kx 2023-04-11 01:18:34 +0300 2206) {
11c606a6 (kx 2023-04-11 01:18:34 +0300 2207)   struct stat st;
11c606a6 (kx 2023-04-11 01:18:34 +0300 2208)   FILE  *fp = NULL;
11c606a6 (kx 2023-04-11 01:18:34 +0300 2209) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 2210)   char *ln   = NULL;
11c606a6 (kx 2023-04-11 01:18:34 +0300 2211)   char *line = NULL, *tmp = NULL;
11c606a6 (kx 2023-04-11 01:18:34 +0300 2212) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 2213)   struct dlist *links = (struct dlist *)(*l);
11c606a6 (kx 2023-04-11 01:18:34 +0300 2214) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 2215)   if( !links || !path ) return;
11c606a6 (kx 2023-04-11 01:18:34 +0300 2216) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 2217)   tmp = (char *)malloc( (size_t)PATH_MAX );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2218)   if( !tmp ) { FATAL_ERROR( "Cannot allocate memory" ); }
11c606a6 (kx 2023-04-11 01:18:34 +0300 2219)   bzero( (void *)tmp, PATH_MAX );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2220) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 2221)   (void)sprintf( &tmp[0], "%s/.RESTORELINKS", path );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2222)   bzero( (void *)&st, sizeof( struct stat ) );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2223)   if( (stat( (const char *)&tmp[0], &st ) == -1) || (st.st_size < 8) )
11c606a6 (kx 2023-04-11 01:18:34 +0300 2224)   {
11c606a6 (kx 2023-04-11 01:18:34 +0300 2225)     free( tmp );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2226)     return;
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)   fp = fopen( (const char *)&tmp[0], "r" );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2230)   if( !fp )
11c606a6 (kx 2023-04-11 01:18:34 +0300 2231)   {
11c606a6 (kx 2023-04-11 01:18:34 +0300 2232)     FATAL_ERROR( "Cannot open .RESTORELINKS file" );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2233)   }
11c606a6 (kx 2023-04-11 01:18:34 +0300 2234) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 2235)   line = (char *)malloc( (size_t)PATH_MAX );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2236)   if( !line ) { FATAL_ERROR( "Cannot allocate memory" ); }
11c606a6 (kx 2023-04-11 01:18:34 +0300 2237)   bzero( (void *)line, PATH_MAX );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2238) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 2239)   while( (ln = fgets( line, PATH_MAX, fp )) )
11c606a6 (kx 2023-04-11 01:18:34 +0300 2240)   {
11c606a6 (kx 2023-04-11 01:18:34 +0300 2241)     char *match = NULL;
11c606a6 (kx 2023-04-11 01:18:34 +0300 2242) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 2243)     ln[strlen(ln) - 1] = '\0'; /* replace new-line symbol      */
11c606a6 (kx 2023-04-11 01:18:34 +0300 2244)     skip_eol_spaces( ln );     /* remove spaces at end-of-line */
11c606a6 (kx 2023-04-11 01:18:34 +0300 2245) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 2246)     if( (match = strstr( ln, "; rm -rf " )) )
11c606a6 (kx 2023-04-11 01:18:34 +0300 2247)     {
11c606a6 (kx 2023-04-11 01:18:34 +0300 2248)       char *q = NULL;
11c606a6 (kx 2023-04-11 01:18:34 +0300 2249)       char *p = strstr( ln, "cd" ) + 2;
11c606a6 (kx 2023-04-11 01:18:34 +0300 2250)       char *f = strstr( ln, "; rm -rf" ) + 8;
11c606a6 (kx 2023-04-11 01:18:34 +0300 2251) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 2252)       if( !p || !f ) continue;
11c606a6 (kx 2023-04-11 01:18:34 +0300 2253) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 2254)       while( (*p == ' ' || *p == '\t') && *p != '\0' ) ++p;
11c606a6 (kx 2023-04-11 01:18:34 +0300 2255)       while( (*f == ' ' || *f == '\t') && *f != '\0' ) ++f;
11c606a6 (kx 2023-04-11 01:18:34 +0300 2256) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 2257)       q = p; while( *q != ' ' && *q != '\t' && *q != ';' && *q != '\0' ) ++q; *q = '\0';
11c606a6 (kx 2023-04-11 01:18:34 +0300 2258)       q = f; while( *q != ' ' && *q != '\t' && *q != ';' && *q != '\0' ) ++q; *q = '\0';
11c606a6 (kx 2023-04-11 01:18:34 +0300 2259) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 2260)       if( p && f )
11c606a6 (kx 2023-04-11 01:18:34 +0300 2261)       {
11c606a6 (kx 2023-04-11 01:18:34 +0300 2262)         (void)sprintf( &tmp[0], "%s%s/%s", (const char *)root, p, f );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2263)         links = dlist_append( links, xstrdup( (const char *)&tmp[0] ) );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2264)       }
11c606a6 (kx 2023-04-11 01:18:34 +0300 2265)     }
11c606a6 (kx 2023-04-11 01:18:34 +0300 2266)   } /* End of while( restore links entry ) */
11c606a6 (kx 2023-04-11 01:18:34 +0300 2267) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 2268)   fclose( fp );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2269) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 2270)   free( line );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2271)   free( tmp );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2272) }
11c606a6 (kx 2023-04-11 01:18:34 +0300 2273) /*
11c606a6 (kx 2023-04-11 01:18:34 +0300 2274)   End of read .FILELIST and .RESTORELINKS functions.
11c606a6 (kx 2023-04-11 01:18:34 +0300 2275)  ********************************************************/
11c606a6 (kx 2023-04-11 01:18:34 +0300 2276) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 2277) /********************************************************
11c606a6 (kx 2023-04-11 01:18:34 +0300 2278)   Rollback/Remove functions:
11c606a6 (kx 2023-04-11 01:18:34 +0300 2279)  */
11c606a6 (kx 2023-04-11 01:18:34 +0300 2280) static void __remove_link( void *data, void *user_data )
11c606a6 (kx 2023-04-11 01:18:34 +0300 2281) {
11c606a6 (kx 2023-04-11 01:18:34 +0300 2282)   const char *fname = (const char *)data;
11c606a6 (kx 2023-04-11 01:18:34 +0300 2283) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 2284)   if( fname )
11c606a6 (kx 2023-04-11 01:18:34 +0300 2285)   {
11c606a6 (kx 2023-04-11 01:18:34 +0300 2286)     (void)unlink( fname );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2287)   }
11c606a6 (kx 2023-04-11 01:18:34 +0300 2288) }
11c606a6 (kx 2023-04-11 01:18:34 +0300 2289) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 2290) static void __remove_file( void *data, void *user_data )
11c606a6 (kx 2023-04-11 01:18:34 +0300 2291) {
11c606a6 (kx 2023-04-11 01:18:34 +0300 2292)   const char *fname = (const char *)data;
11c606a6 (kx 2023-04-11 01:18:34 +0300 2293) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 2294)   if( fname )
11c606a6 (kx 2023-04-11 01:18:34 +0300 2295)   {
11c606a6 (kx 2023-04-11 01:18:34 +0300 2296)     char *p = rindex( fname, '.' );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2297)     /*
11c606a6 (kx 2023-04-11 01:18:34 +0300 2298)       Если .new файл остался с тем же именем, это значит что до инсталляции
11c606a6 (kx 2023-04-11 01:18:34 +0300 2299)       в системе существовал такой же файл но без расширения .new и при этом
11c606a6 (kx 2023-04-11 01:18:34 +0300 2300)       он отличался от нового. В данном случае надо удалять только файл .new.
11c606a6 (kx 2023-04-11 01:18:34 +0300 2301) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 2302)       Если же файл .new не существует, то надо удалять такой же файл но без
11c606a6 (kx 2023-04-11 01:18:34 +0300 2303)       расширения .new .
11c606a6 (kx 2023-04-11 01:18:34 +0300 2304)      */
11c606a6 (kx 2023-04-11 01:18:34 +0300 2305)     if( p && !strncmp( (const char *)p, ".new", 4 ) )
11c606a6 (kx 2023-04-11 01:18:34 +0300 2306)     {
11c606a6 (kx 2023-04-11 01:18:34 +0300 2307)       struct stat st;
11c606a6 (kx 2023-04-11 01:18:34 +0300 2308) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 2309)       bzero( (void *)&st, sizeof( struct stat ) );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2310)       if( (stat( fname, &st ) == -1) ) *p = '\0';
11c606a6 (kx 2023-04-11 01:18:34 +0300 2311)     }
11c606a6 (kx 2023-04-11 01:18:34 +0300 2312) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 2313)     (void)unlink( fname );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2314)   }
11c606a6 (kx 2023-04-11 01:18:34 +0300 2315) }
11c606a6 (kx 2023-04-11 01:18:34 +0300 2316) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 2317) static int is_dir_empty( const char *dirpath )
11c606a6 (kx 2023-04-11 01:18:34 +0300 2318) {
11c606a6 (kx 2023-04-11 01:18:34 +0300 2319)   int ret = 0;
11c606a6 (kx 2023-04-11 01:18:34 +0300 2320) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 2321)   DIR    *dir;
11c606a6 (kx 2023-04-11 01:18:34 +0300 2322)   char   *path;
11c606a6 (kx 2023-04-11 01:18:34 +0300 2323)   size_t  len;
11c606a6 (kx 2023-04-11 01:18:34 +0300 2324) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 2325)   struct stat    path_sb, entry_sb;
11c606a6 (kx 2023-04-11 01:18:34 +0300 2326)   struct dirent *entry;
11c606a6 (kx 2023-04-11 01:18:34 +0300 2327) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 2328)   if( stat( dirpath, &path_sb ) == -1 )   return ret; /* stat returns error code; errno is set */
11c606a6 (kx 2023-04-11 01:18:34 +0300 2329)   if( S_ISDIR(path_sb.st_mode) == 0 )     return ret; /* dirpath is not a directory */
11c606a6 (kx 2023-04-11 01:18:34 +0300 2330)   if( (dir = opendir(dirpath) ) == NULL ) return ret; /* Cannot open direcroty; errno is set */
11c606a6 (kx 2023-04-11 01:18:34 +0300 2331) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 2332)   ret = 1;
11c606a6 (kx 2023-04-11 01:18:34 +0300 2333) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 2334)   len = strlen( dirpath );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2335)   while( (entry = readdir( dir )) != NULL)
11c606a6 (kx 2023-04-11 01:18:34 +0300 2336)   {
11c606a6 (kx 2023-04-11 01:18:34 +0300 2337)     /* skip entries '.' and '..' */
11c606a6 (kx 2023-04-11 01:18:34 +0300 2338)     if( ! strcmp( entry->d_name, "." ) || ! strcmp( entry->d_name, ".." ) ) continue;
11c606a6 (kx 2023-04-11 01:18:34 +0300 2339) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 2340)     /* determinate a full name of an entry */
11c606a6 (kx 2023-04-11 01:18:34 +0300 2341)     path = alloca( len + strlen( entry->d_name ) + 2 );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2342)     strcpy( path, dirpath );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2343)     strcat( path, "/" );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2344)     strcat( path, entry->d_name );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2345) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 2346)     if( stat( path, &entry_sb ) == 0 )
11c606a6 (kx 2023-04-11 01:18:34 +0300 2347)     {
11c606a6 (kx 2023-04-11 01:18:34 +0300 2348)       ret = 0;
11c606a6 (kx 2023-04-11 01:18:34 +0300 2349)       break;
11c606a6 (kx 2023-04-11 01:18:34 +0300 2350)     }
11c606a6 (kx 2023-04-11 01:18:34 +0300 2351)     /* else { stat() returns error code; errno is set; and we have to continue the loop } */
11c606a6 (kx 2023-04-11 01:18:34 +0300 2352)   }
11c606a6 (kx 2023-04-11 01:18:34 +0300 2353)   closedir( dir );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2354) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 2355)   return ret;
11c606a6 (kx 2023-04-11 01:18:34 +0300 2356) }
11c606a6 (kx 2023-04-11 01:18:34 +0300 2357) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 2358) static void __remove_dir( void *data, void *user_data )
11c606a6 (kx 2023-04-11 01:18:34 +0300 2359) {
11c606a6 (kx 2023-04-11 01:18:34 +0300 2360)   const char *dname = (const char *)data;
11c606a6 (kx 2023-04-11 01:18:34 +0300 2361) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 2362)   if( dname && is_dir_empty( (const char *)dname ) )
11c606a6 (kx 2023-04-11 01:18:34 +0300 2363)   {
11c606a6 (kx 2023-04-11 01:18:34 +0300 2364)     (void)rmdir( dname );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2365)   }
11c606a6 (kx 2023-04-11 01:18:34 +0300 2366) }
11c606a6 (kx 2023-04-11 01:18:34 +0300 2367) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 2368) static void rollback( void )
11c606a6 (kx 2023-04-11 01:18:34 +0300 2369) {
11c606a6 (kx 2023-04-11 01:18:34 +0300 2370)   /* Try to change CWD to the ROOT directory: */
11c606a6 (kx 2023-04-11 01:18:34 +0300 2371)   (void)chdir( (const char *)root );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2372) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 2373)   if( links ) { dlist_foreach( links, __remove_link, NULL ); }
11c606a6 (kx 2023-04-11 01:18:34 +0300 2374) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 2375)   if( files ) { dlist_foreach( files, __remove_file, NULL ); }
11c606a6 (kx 2023-04-11 01:18:34 +0300 2376) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 2377)   if( dirs )
11c606a6 (kx 2023-04-11 01:18:34 +0300 2378)   {
11c606a6 (kx 2023-04-11 01:18:34 +0300 2379)     dirs = dlist_sort( dirs, __cmp_list_items );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2380)     dirs = dlist_reverse( dirs );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2381)     dlist_foreach( dirs, __remove_dir, NULL );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2382)   }
11c606a6 (kx 2023-04-11 01:18:34 +0300 2383) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 2384)   /* Try to remove PKGLOG file */
11c606a6 (kx 2023-04-11 01:18:34 +0300 2385)   {
11c606a6 (kx 2023-04-11 01:18:34 +0300 2386)     char *tmp = NULL;
11c606a6 (kx 2023-04-11 01:18:34 +0300 2387) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 2388)     tmp = (char *)malloc( PATH_MAX );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2389)     if( tmp )
11c606a6 (kx 2023-04-11 01:18:34 +0300 2390)     {
11c606a6 (kx 2023-04-11 01:18:34 +0300 2391)       const char *fname = basename( (char *)pkglog_fname );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2392) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 2393)       bzero( (void *)tmp, PATH_MAX );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2394) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 2395)       if( group )
11c606a6 (kx 2023-04-11 01:18:34 +0300 2396)         (void)sprintf( &tmp[0], "%s/%s/%s", pkgs_path, group, fname );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2397)       else
11c606a6 (kx 2023-04-11 01:18:34 +0300 2398)         (void)sprintf( &tmp[0], "%s/%s", pkgs_path, fname );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2399) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 2400)       (void)unlink( (const char *)&tmp[0] );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2401) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 2402)       if( group )
11c606a6 (kx 2023-04-11 01:18:34 +0300 2403)       {
11c606a6 (kx 2023-04-11 01:18:34 +0300 2404)         const char *dir = (const char *)dirname( (char *)&tmp[0] );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2405)         if( is_dir_empty( dir ) )
11c606a6 (kx 2023-04-11 01:18:34 +0300 2406)         {
11c606a6 (kx 2023-04-11 01:18:34 +0300 2407)           (void)rmdir( dir );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2408)         }
11c606a6 (kx 2023-04-11 01:18:34 +0300 2409)       }
11c606a6 (kx 2023-04-11 01:18:34 +0300 2410)       free( tmp );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2411)     }
11c606a6 (kx 2023-04-11 01:18:34 +0300 2412)   }
11c606a6 (kx 2023-04-11 01:18:34 +0300 2413) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 2414)   /* Try to change CWD to the CURRENT directory: */
11c606a6 (kx 2023-04-11 01:18:34 +0300 2415)   (void)chdir( (const char *)curdir );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2416) }
11c606a6 (kx 2023-04-11 01:18:34 +0300 2417) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 2418) static void remove_package( void )
11c606a6 (kx 2023-04-11 01:18:34 +0300 2419) {
11c606a6 (kx 2023-04-11 01:18:34 +0300 2420)   /* Try to change CWD to the ROOT directory: */
11c606a6 (kx 2023-04-11 01:18:34 +0300 2421)   (void)chdir( (const char *)root );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2422) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 2423)   if( rlinks ) { dlist_foreach( rlinks, __remove_link, NULL ); }
11c606a6 (kx 2023-04-11 01:18:34 +0300 2424) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 2425)   if( rfiles ) { dlist_foreach( rfiles, __remove_file, NULL ); }
11c606a6 (kx 2023-04-11 01:18:34 +0300 2426) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 2427)   if( rdirs )
11c606a6 (kx 2023-04-11 01:18:34 +0300 2428)   {
11c606a6 (kx 2023-04-11 01:18:34 +0300 2429)     rdirs = dlist_sort( rdirs, __cmp_list_items );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2430)     rdirs = dlist_reverse( rdirs );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2431)     dlist_foreach( rdirs, __remove_dir, NULL );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2432)   }
11c606a6 (kx 2023-04-11 01:18:34 +0300 2433) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 2434)   /* Try to change CWD to the CURRENT directory: */
11c606a6 (kx 2023-04-11 01:18:34 +0300 2435)   (void)chdir( (const char *)curdir );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2436) }
11c606a6 (kx 2023-04-11 01:18:34 +0300 2437) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 2438) static void finalize_removal( void )
11c606a6 (kx 2023-04-11 01:18:34 +0300 2439) {
11c606a6 (kx 2023-04-11 01:18:34 +0300 2440)   pid_t p = (pid_t) -1;
11c606a6 (kx 2023-04-11 01:18:34 +0300 2441)   int   rc;
11c606a6 (kx 2023-04-11 01:18:34 +0300 2442) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 2443)   int   len = 0;
11c606a6 (kx 2023-04-11 01:18:34 +0300 2444)   char *cmd = NULL, *tmp = NULL;
11c606a6 (kx 2023-04-11 01:18:34 +0300 2445) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 2446)   cmd = (char *)malloc( (size_t)PATH_MAX );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2447)   if( !cmd ) { FATAL_ERROR( "Cannot allocate memory" ); }
11c606a6 (kx 2023-04-11 01:18:34 +0300 2448)   bzero( (void *)cmd, PATH_MAX );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2449) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 2450)   tmp = (char *)malloc( (size_t)PATH_MAX );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2451)   if( !tmp ) { FATAL_ERROR( "Cannot allocate memory" ); }
11c606a6 (kx 2023-04-11 01:18:34 +0300 2452)   bzero( (void *)tmp, PATH_MAX );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2453) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 2454)   /*********************************************
11c606a6 (kx 2023-04-11 01:18:34 +0300 2455)     Decrement references in the Setup Database:
11c606a6 (kx 2023-04-11 01:18:34 +0300 2456)    */
a745159c (kx 2023-10-23 21:39:58 +0300 2457)   if( !disable_chrefs )
11c606a6 (kx 2023-04-11 01:18:34 +0300 2458)   {
a745159c (kx 2023-10-23 21:39:58 +0300 2459)     if( installed_group )
a745159c (kx 2023-10-23 21:39:58 +0300 2460)       len = snprintf( &cmd[0], PATH_MAX,
a745159c (kx 2023-10-23 21:39:58 +0300 2461)                       "%s/chrefs --operation=dec --destination=%s %s/%s > /dev/null 2>&1",
a745159c (kx 2023-10-23 21:39:58 +0300 2462)                       selfdir, pkgs_path, installed_group, basename( (char *)remlog_fname ) );
a745159c (kx 2023-10-23 21:39:58 +0300 2463)     else
a745159c (kx 2023-10-23 21:39:58 +0300 2464)       len = snprintf( &cmd[0], PATH_MAX,
a745159c (kx 2023-10-23 21:39:58 +0300 2465)                       "%s/chrefs --operation=dec --destination=%s %s > /dev/null 2>&1",
a745159c (kx 2023-10-23 21:39:58 +0300 2466)                       selfdir, pkgs_path, basename( (char *)remlog_fname ) );
a745159c (kx 2023-10-23 21:39:58 +0300 2467)     if( len == 0 || len == PATH_MAX - 1 )
a745159c (kx 2023-10-23 21:39:58 +0300 2468)     {
a745159c (kx 2023-10-23 21:39:58 +0300 2469)       FATAL_ERROR( "Cannot decrement '%s-%s' package references", pkgname, pkgver );
a745159c (kx 2023-10-23 21:39:58 +0300 2470)     }
a745159c (kx 2023-10-23 21:39:58 +0300 2471)     p = sys_exec_command( cmd );
a745159c (kx 2023-10-23 21:39:58 +0300 2472)     rc = sys_wait_command( p, (char *)NULL, PATH_MAX );
a745159c (kx 2023-10-23 21:39:58 +0300 2473)     if( (rc != 0) && !ignore_chrefs_errors )
a745159c (kx 2023-10-23 21:39:58 +0300 2474)     {
a745159c (kx 2023-10-23 21:39:58 +0300 2475)       free( cmd );
a745159c (kx 2023-10-23 21:39:58 +0300 2476)       free( tmp );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2477) 
a745159c (kx 2023-10-23 21:39:58 +0300 2478)       exit_status = 48;
11c606a6 (kx 2023-04-11 01:18:34 +0300 2479) 
a745159c (kx 2023-10-23 21:39:58 +0300 2480)       if( update_mode != CONSOLE )
a745159c (kx 2023-10-23 21:39:58 +0300 2481)       {
11c606a6 (kx 2023-04-11 01:18:34 +0300 2482) #if defined( HAVE_DIALOG )
a745159c (kx 2023-10-23 21:39:58 +0300 2483)         info_pkg_box( "Update:", pkgname, pkgver, NULL,
a745159c (kx 2023-10-23 21:39:58 +0300 2484)                       "\n\\Z1Cannot decrement package references in Setup Database.\\Zn\n", 5, 0, 0 );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2485) #else
a745159c (kx 2023-10-23 21:39:58 +0300 2486)         fprintf( stdout, "\nCannot decrement '%s-%s' package references in Setup Database.\n\n", pkgname, pkgver );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2487) #endif
a745159c (kx 2023-10-23 21:39:58 +0300 2488)       }
a745159c (kx 2023-10-23 21:39:58 +0300 2489)       else
a745159c (kx 2023-10-23 21:39:58 +0300 2490)       {
a745159c (kx 2023-10-23 21:39:58 +0300 2491)         fprintf( stdout, "\nCannot decrement '%s-%s' package references in Setup Database.\n\n", pkgname, pkgver );
a745159c (kx 2023-10-23 21:39:58 +0300 2492)       }
11c606a6 (kx 2023-04-11 01:18:34 +0300 2493) 
a745159c (kx 2023-10-23 21:39:58 +0300 2494)       if( tmpdir ) { _rm_tmpdir( (const char *)tmpdir ); free( tmpdir ); }
a745159c (kx 2023-10-23 21:39:58 +0300 2495)       free_resources();
a745159c (kx 2023-10-23 21:39:58 +0300 2496)       exit( exit_status );
a745159c (kx 2023-10-23 21:39:58 +0300 2497)     }
11c606a6 (kx 2023-04-11 01:18:34 +0300 2498)   }
11c606a6 (kx 2023-04-11 01:18:34 +0300 2499) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 2500)   /*****************************************************
11c606a6 (kx 2023-04-11 01:18:34 +0300 2501)     Backup PKGLOG file into removed-packages directory:
11c606a6 (kx 2023-04-11 01:18:34 +0300 2502)    */
11c606a6 (kx 2023-04-11 01:18:34 +0300 2503)   bzero( (void *)tmp, PATH_MAX );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2504) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 2505)   if( installed_group )
11c606a6 (kx 2023-04-11 01:18:34 +0300 2506)     (void)sprintf( &tmp[0], "%s/%s/", rempkgs_path, installed_group );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2507)   else
11c606a6 (kx 2023-04-11 01:18:34 +0300 2508)     (void)sprintf( &tmp[0], "%s/", rempkgs_path );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2509) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 2510)   if( _mkdir_p( tmp, S_IRWXU | S_IRWXG | S_IRWXO ) != 0 )
11c606a6 (kx 2023-04-11 01:18:34 +0300 2511)   {
11c606a6 (kx 2023-04-11 01:18:34 +0300 2512)     FATAL_ERROR( "Cannot access '/%s' directory", REMOVED_PKGS_PATH );
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)   bzero( (void *)cmd, PATH_MAX );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2516) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 2517)   len = snprintf( &cmd[0], PATH_MAX,
11c606a6 (kx 2023-04-11 01:18:34 +0300 2518)                   "mv %s %s > /dev/null 2>&1",
11c606a6 (kx 2023-04-11 01:18:34 +0300 2519)                   remlog_fname, (const char *)&tmp[0] );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2520)   if( len == 0 || len == PATH_MAX - 1 )
11c606a6 (kx 2023-04-11 01:18:34 +0300 2521)   {
11c606a6 (kx 2023-04-11 01:18:34 +0300 2522)     FATAL_ERROR( "Cannot backup '%s' pkglog file", basename( (char *)remlog_fname ) );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2523)   }
11c606a6 (kx 2023-04-11 01:18:34 +0300 2524)   p = sys_exec_command( cmd );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2525)   rc = sys_wait_command( p, (char *)NULL, PATH_MAX );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2526) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 2527)   free( cmd );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2528) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 2529)   if( rc != 0 )
11c606a6 (kx 2023-04-11 01:18:34 +0300 2530)   {
11c606a6 (kx 2023-04-11 01:18:34 +0300 2531)     free( tmp );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2532) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 2533)     exit_status = 47;
11c606a6 (kx 2023-04-11 01:18:34 +0300 2534) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 2535)     if( update_mode != CONSOLE )
11c606a6 (kx 2023-04-11 01:18:34 +0300 2536)     {
11c606a6 (kx 2023-04-11 01:18:34 +0300 2537) #if defined( HAVE_DIALOG )
11c606a6 (kx 2023-04-11 01:18:34 +0300 2538)       info_pkg_box( "Update:", pkgname, pkgver, NULL,
11c606a6 (kx 2023-04-11 01:18:34 +0300 2539)                     "\n\\Z1Cannot backup PKGLOG file.\\Zn\n", 5, 0, 0 );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2540) #else
11c606a6 (kx 2023-04-11 01:18:34 +0300 2541)       fprintf( stdout, "\nCannot backup '%s' pkglog file.\n\n", basename( (char *)remlog_fname ) );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2542) #endif
11c606a6 (kx 2023-04-11 01:18:34 +0300 2543)     }
11c606a6 (kx 2023-04-11 01:18:34 +0300 2544)     else
11c606a6 (kx 2023-04-11 01:18:34 +0300 2545)     {
11c606a6 (kx 2023-04-11 01:18:34 +0300 2546)       fprintf( stdout, "\nCannot backup '%s' pkglog file.\n\n", basename( (char *)remlog_fname ) );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2547)     }
11c606a6 (kx 2023-04-11 01:18:34 +0300 2548) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 2549)     if( tmpdir ) { _rm_tmpdir( (const char *)tmpdir ); free( tmpdir ); }
11c606a6 (kx 2023-04-11 01:18:34 +0300 2550)     free_resources();
11c606a6 (kx 2023-04-11 01:18:34 +0300 2551)     exit( exit_status );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2552)   }
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)     Remove group directory if it is empty:
11c606a6 (kx 2023-04-11 01:18:34 +0300 2556)    */
11c606a6 (kx 2023-04-11 01:18:34 +0300 2557)   bzero( (void *)tmp, PATH_MAX );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2558) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 2559)   if( installed_group )
11c606a6 (kx 2023-04-11 01:18:34 +0300 2560)   {
11c606a6 (kx 2023-04-11 01:18:34 +0300 2561)     (void)sprintf( &tmp[0], "%s/%s/", pkgs_path, installed_group );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2562) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 2563)     const char *dir = (const char *)&tmp[0];
11c606a6 (kx 2023-04-11 01:18:34 +0300 2564)     if( is_dir_empty( dir ) )
11c606a6 (kx 2023-04-11 01:18:34 +0300 2565)     {
11c606a6 (kx 2023-04-11 01:18:34 +0300 2566)       (void)rmdir( dir );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2567)     }
11c606a6 (kx 2023-04-11 01:18:34 +0300 2568)   }
11c606a6 (kx 2023-04-11 01:18:34 +0300 2569) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 2570)   free( tmp );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2571) }
11c606a6 (kx 2023-04-11 01:18:34 +0300 2572) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 2573) /*
11c606a6 (kx 2023-04-11 01:18:34 +0300 2574)   End of rollback/remove functions.
11c606a6 (kx 2023-04-11 01:18:34 +0300 2575)  ********************************************************/
11c606a6 (kx 2023-04-11 01:18:34 +0300 2576) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 2577) static void read_description( const char *path, int show_compressed_size )
11c606a6 (kx 2023-04-11 01:18:34 +0300 2578) {
11c606a6 (kx 2023-04-11 01:18:34 +0300 2579)   struct stat st;
11c606a6 (kx 2023-04-11 01:18:34 +0300 2580)   FILE  *fp = NULL;
11c606a6 (kx 2023-04-11 01:18:34 +0300 2581) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 2582)   char  *buf = NULL, *tmp = NULL;
11c606a6 (kx 2023-04-11 01:18:34 +0300 2583)   char  *lp  = NULL;
11c606a6 (kx 2023-04-11 01:18:34 +0300 2584)   int    n   = 0;
11c606a6 (kx 2023-04-11 01:18:34 +0300 2585) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 2586)   char *ln   = NULL;
11c606a6 (kx 2023-04-11 01:18:34 +0300 2587)   char *line = NULL;
11c606a6 (kx 2023-04-11 01:18:34 +0300 2588) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 2589)   if( !path ) return;
11c606a6 (kx 2023-04-11 01:18:34 +0300 2590) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 2591)   tmp = (char *)malloc( (size_t)PATH_MAX );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2592)   if( !tmp ) { FATAL_ERROR( "Cannot allocate memory" ); }
11c606a6 (kx 2023-04-11 01:18:34 +0300 2593)   bzero( (void *)tmp, PATH_MAX );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2594) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 2595)   buf = (char *)malloc( (size_t)PATH_MAX );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2596)   if( !buf ) { FATAL_ERROR( "Cannot allocate memory" ); }
11c606a6 (kx 2023-04-11 01:18:34 +0300 2597)   bzero( (void *)buf, PATH_MAX );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2598) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 2599)   (void)sprintf( &tmp[0], "%s/.DESCRIPTION", path );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2600)   bzero( (void *)&st, sizeof( struct stat ) );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2601)   if( (stat( (const char *)&tmp[0], &st ) == -1) || (st.st_size < 8) )
11c606a6 (kx 2023-04-11 01:18:34 +0300 2602)   {
11c606a6 (kx 2023-04-11 01:18:34 +0300 2603)     free( tmp );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2604)     return;
11c606a6 (kx 2023-04-11 01:18:34 +0300 2605)   }
11c606a6 (kx 2023-04-11 01:18:34 +0300 2606) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 2607)   fp = fopen( (const char *)&tmp[0], "r" );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2608)   if( !fp )
11c606a6 (kx 2023-04-11 01:18:34 +0300 2609)   {
11c606a6 (kx 2023-04-11 01:18:34 +0300 2610)     FATAL_ERROR( "Cannot open .DESCRIPTION file" );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2611)   }
11c606a6 (kx 2023-04-11 01:18:34 +0300 2612) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 2613)   (void)sprintf( (char *)&buf[0], "%s:", pkgname );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2614) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 2615)   line = (char *)malloc( (size_t)PATH_MAX );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2616)   if( !line ) { FATAL_ERROR( "Cannot allocate memory" ); }
11c606a6 (kx 2023-04-11 01:18:34 +0300 2617)   bzero( (void *)line, PATH_MAX );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2618) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 2619)   lp = (char *)&tmp[0];
11c606a6 (kx 2023-04-11 01:18:34 +0300 2620)   bzero( (void *)tmp, PATH_MAX );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2621)   (void)sprintf( (char *)&tmp[0], "\n" );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2622)   ++lp;
11c606a6 (kx 2023-04-11 01:18:34 +0300 2623) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 2624)   while( (ln = fgets( line, PATH_MAX, fp )) && n < DESCRIPTION_NUMBER_OF_LINES )
11c606a6 (kx 2023-04-11 01:18:34 +0300 2625)   {
11c606a6 (kx 2023-04-11 01:18:34 +0300 2626)     char *match = NULL;
11c606a6 (kx 2023-04-11 01:18:34 +0300 2627) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 2628)     ln[strlen(ln) - 1] = '\0'; /* replace new-line symbol */
11c606a6 (kx 2023-04-11 01:18:34 +0300 2629) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 2630)     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 2631)     {
11c606a6 (kx 2023-04-11 01:18:34 +0300 2632)       int mlen   = strlen( match ), plen = strlen( buf );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2633)       int length = ( mlen > plen )  ? (mlen - plen - 1) : 0 ;
11c606a6 (kx 2023-04-11 01:18:34 +0300 2634) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 2635)       if( length > DESCRIPTION_LENGTH_OF_LINE )
11c606a6 (kx 2023-04-11 01:18:34 +0300 2636)       {
11c606a6 (kx 2023-04-11 01:18:34 +0300 2637)         /* WARNING( "Package DESCRIPTION contains lines with length greater than %d characters", DESCRIPTION_LENGTH_OF_LINE ); */
11c606a6 (kx 2023-04-11 01:18:34 +0300 2638)         match[plen + 1 + DESCRIPTION_LENGTH_OF_LINE] = '\0'; /* truncating description line  */
11c606a6 (kx 2023-04-11 01:18:34 +0300 2639)         skip_eol_spaces( match );                            /* remove spaces at end-of-line */
11c606a6 (kx 2023-04-11 01:18:34 +0300 2640)       }
11c606a6 (kx 2023-04-11 01:18:34 +0300 2641) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 2642)       match += plen + 1;
11c606a6 (kx 2023-04-11 01:18:34 +0300 2643)       if( match[0] != '\0' ) { (void)sprintf( lp, " %s\n", match ); lp += strlen( match ) + 2; }
11c606a6 (kx 2023-04-11 01:18:34 +0300 2644)       else                   { (void)sprintf( lp, "\n" ); ++lp; }
11c606a6 (kx 2023-04-11 01:18:34 +0300 2645)       ++n;
11c606a6 (kx 2023-04-11 01:18:34 +0300 2646)     }
11c606a6 (kx 2023-04-11 01:18:34 +0300 2647)   } /* End of while( ln = fgets() ) */
11c606a6 (kx 2023-04-11 01:18:34 +0300 2648) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 2649)   fclose( fp );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2650) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 2651)   (void)sprintf( lp, " Uncompressed Size: %s\n", uncompressed_size );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2652)   lp += strlen( uncompressed_size ) + 21;
11c606a6 (kx 2023-04-11 01:18:34 +0300 2653)   if( show_compressed_size )
11c606a6 (kx 2023-04-11 01:18:34 +0300 2654)   {
11c606a6 (kx 2023-04-11 01:18:34 +0300 2655)     (void)sprintf( lp, "   Compressed Size: %s\n", compressed_size );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2656)     lp += strlen( compressed_size ) + 21;
11c606a6 (kx 2023-04-11 01:18:34 +0300 2657)   }
11c606a6 (kx 2023-04-11 01:18:34 +0300 2658) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 2659)   if( description ) { free( description ); description = NULL; }
11c606a6 (kx 2023-04-11 01:18:34 +0300 2660)   description = xstrdup( (const char *)&tmp[0] );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2661) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 2662)   free( buf );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2663)   free( line );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2664)   free( tmp );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2665) }
11c606a6 (kx 2023-04-11 01:18:34 +0300 2666) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 2667) static int ask_for_update( void )
11c606a6 (kx 2023-04-11 01:18:34 +0300 2668) {
11c606a6 (kx 2023-04-11 01:18:34 +0300 2669)   int ret = 0; /* continue update */
11c606a6 (kx 2023-04-11 01:18:34 +0300 2670) #if defined( HAVE_DIALOG )
11c606a6 (kx 2023-04-11 01:18:34 +0300 2671)   /******************************************************
11c606a6 (kx 2023-04-11 01:18:34 +0300 2672)     Ask for update dialog shown only in MENUDIALOG mode
11c606a6 (kx 2023-04-11 01:18:34 +0300 2673)     when priority != REQUIRED or --always-ask=yes:
11c606a6 (kx 2023-04-11 01:18:34 +0300 2674)    */
11c606a6 (kx 2023-04-11 01:18:34 +0300 2675)   if( (update_mode == MENUDIALOG) && (((priority == REQUIRED) && ask) || (priority != REQUIRED)) )
11c606a6 (kx 2023-04-11 01:18:34 +0300 2676)   {
11c606a6 (kx 2023-04-11 01:18:34 +0300 2677)     ret =  ask_update_box( "Update:", pkgname, pkgver, strprio( priority, 0 ),
11c606a6 (kx 2023-04-11 01:18:34 +0300 2678)                            description, 18, 0, 0 );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2679)   }
11c606a6 (kx 2023-04-11 01:18:34 +0300 2680) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 2681)   if( ret )
11c606a6 (kx 2023-04-11 01:18:34 +0300 2682)   {
11c606a6 (kx 2023-04-11 01:18:34 +0300 2683)     info_pkg_box( "Update:", pkgname, pkgver, strprio( priority, 0 ),
11c606a6 (kx 2023-04-11 01:18:34 +0300 2684)                   "\nUpdate terminated by user.\n", 5, 0, 0 );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2685)   }
11c606a6 (kx 2023-04-11 01:18:34 +0300 2686) #endif
11c606a6 (kx 2023-04-11 01:18:34 +0300 2687)   return ret;
11c606a6 (kx 2023-04-11 01:18:34 +0300 2688) }
11c606a6 (kx 2023-04-11 01:18:34 +0300 2689) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 2690) static int ask_for_reinstall( void )
11c606a6 (kx 2023-04-11 01:18:34 +0300 2691) {
11c606a6 (kx 2023-04-11 01:18:34 +0300 2692)   int ret = 0; /* continue update */
11c606a6 (kx 2023-04-11 01:18:34 +0300 2693) #if defined( HAVE_DIALOG )
11c606a6 (kx 2023-04-11 01:18:34 +0300 2694)   /***************************************************************
11c606a6 (kx 2023-04-11 01:18:34 +0300 2695)     Ask for remove dialog shown only in INFO or MENU DIALOG mode:
11c606a6 (kx 2023-04-11 01:18:34 +0300 2696)    */
11c606a6 (kx 2023-04-11 01:18:34 +0300 2697)   if( update_mode == MENUDIALOG )
11c606a6 (kx 2023-04-11 01:18:34 +0300 2698)   {
11c606a6 (kx 2023-04-11 01:18:34 +0300 2699)     char *msg = NULL;
11c606a6 (kx 2023-04-11 01:18:34 +0300 2700) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 2701)     msg = (char *)malloc( (size_t)PATH_MAX );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2702)     if( !msg ) { FATAL_ERROR( "Cannot allocate memory" ); }
11c606a6 (kx 2023-04-11 01:18:34 +0300 2703)     bzero( (void *)msg, PATH_MAX );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2704) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 2705)     (void)sprintf( &msg[0], "\nThe same version of requested package installed and correct.\n"
11c606a6 (kx 2023-04-11 01:18:34 +0300 2706)                             "\n\\Z1Re-install this vesion?\\Zn\n" );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2707) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 2708)     if( (ret =  ask_reinstall_box( "Update:", pkgname, installed_version, (const char *)&msg[0], 9, 0, 0 )) )
11c606a6 (kx 2023-04-11 01:18:34 +0300 2709)     {
11c606a6 (kx 2023-04-11 01:18:34 +0300 2710)       info_pkg_box( "Update:", pkgname, installed_version, NULL,
11c606a6 (kx 2023-04-11 01:18:34 +0300 2711)                     "\nPackage update terminated by user.\n", 5, 0, 0 );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2712)     }
11c606a6 (kx 2023-04-11 01:18:34 +0300 2713) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 2714)     free( msg );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2715)   }
11c606a6 (kx 2023-04-11 01:18:34 +0300 2716)   else if( update_mode == INFODIALOG )
11c606a6 (kx 2023-04-11 01:18:34 +0300 2717)   {
11c606a6 (kx 2023-04-11 01:18:34 +0300 2718)     if( !reinstall )
11c606a6 (kx 2023-04-11 01:18:34 +0300 2719)     {
11c606a6 (kx 2023-04-11 01:18:34 +0300 2720)       info_pkg_box( "Update:", pkgname, installed_version, NULL,
11c606a6 (kx 2023-04-11 01:18:34 +0300 2721)                     "\nThe same version of requested package installed and correct.\n", 5, 0, 0 );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2722)       ret = 1;
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)   else
11c606a6 (kx 2023-04-11 01:18:34 +0300 2726)   {
11c606a6 (kx 2023-04-11 01:18:34 +0300 2727)     if( !reinstall )
11c606a6 (kx 2023-04-11 01:18:34 +0300 2728)     {
11c606a6 (kx 2023-04-11 01:18:34 +0300 2729)       fprintf( stdout, "\nThe same version of '%s-%s' package is installed and correct.\n\n", pkgname, installed_version );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2730)       ret = 1;
11c606a6 (kx 2023-04-11 01:18:34 +0300 2731)     }
11c606a6 (kx 2023-04-11 01:18:34 +0300 2732)   }
11c606a6 (kx 2023-04-11 01:18:34 +0300 2733) #else
11c606a6 (kx 2023-04-11 01:18:34 +0300 2734)   {
11c606a6 (kx 2023-04-11 01:18:34 +0300 2735)     if( !reinstall )
11c606a6 (kx 2023-04-11 01:18:34 +0300 2736)     {
11c606a6 (kx 2023-04-11 01:18:34 +0300 2737)       fprintf( stdout, "\nThe same version of '%s-%s' package is installed and correct.\n\n", pkgname, installed_version );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2738)       ret = 1;
11c606a6 (kx 2023-04-11 01:18:34 +0300 2739)     }
11c606a6 (kx 2023-04-11 01:18:34 +0300 2740)   }
11c606a6 (kx 2023-04-11 01:18:34 +0300 2741) #endif
11c606a6 (kx 2023-04-11 01:18:34 +0300 2742)   return ret;
11c606a6 (kx 2023-04-11 01:18:34 +0300 2743) }
11c606a6 (kx 2023-04-11 01:18:34 +0300 2744) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 2745) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 2746) static void show_update_progress( void )
11c606a6 (kx 2023-04-11 01:18:34 +0300 2747) {
11c606a6 (kx 2023-04-11 01:18:34 +0300 2748)   fprintf( stdout, "\033[2J" ); /* clear screen */
11c606a6 (kx 2023-04-11 01:18:34 +0300 2749) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 2750)   if( update_mode != CONSOLE )
11c606a6 (kx 2023-04-11 01:18:34 +0300 2751)   {
11c606a6 (kx 2023-04-11 01:18:34 +0300 2752) #if defined( HAVE_DIALOG )
11c606a6 (kx 2023-04-11 01:18:34 +0300 2753)     info_pkg_box( "Update:", pkgname, pkgver, strprio( priority, 0 ),
11c606a6 (kx 2023-04-11 01:18:34 +0300 2754)                   description, 16, 0, 0 );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2755) #else
11c606a6 (kx 2023-04-11 01:18:34 +0300 2756)     fprintf( stdout, "\n Update: %s-%s [%s]...\n", pkgname, pkgver, strprio( priority, 0 ));
11c606a6 (kx 2023-04-11 01:18:34 +0300 2757)     /*************************************************
11c606a6 (kx 2023-04-11 01:18:34 +0300 2758)       Ruler: 68 characters + 2 spaces left and right:
11c606a6 (kx 2023-04-11 01:18:34 +0300 2759) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 2760)                       | ----handy-ruler----------------------------------------------------- | */
11c606a6 (kx 2023-04-11 01:18:34 +0300 2761)     fprintf( stdout, "|======================================================================|\n" );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2762)     fprintf( stdout, "%s\n", description );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2763)     fprintf( stdout, "|======================================================================|\n\n" );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2764)     fprintf( stdout, "\n\n\n" ); /* 3 lines up for final message */
11c606a6 (kx 2023-04-11 01:18:34 +0300 2765) #endif
11c606a6 (kx 2023-04-11 01:18:34 +0300 2766)   }
11c606a6 (kx 2023-04-11 01:18:34 +0300 2767)   else
11c606a6 (kx 2023-04-11 01:18:34 +0300 2768)   {
11c606a6 (kx 2023-04-11 01:18:34 +0300 2769)     fprintf( stdout, "\n Update: %s-%s [%s]...\n", pkgname, pkgver, strprio( priority, 0 ));
11c606a6 (kx 2023-04-11 01:18:34 +0300 2770)     /*************************************************
11c606a6 (kx 2023-04-11 01:18:34 +0300 2771)       Ruler: 68 characters + 2 spaces left and right:
11c606a6 (kx 2023-04-11 01:18:34 +0300 2772) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 2773)                       | ----handy-ruler----------------------------------------------------- | */
11c606a6 (kx 2023-04-11 01:18:34 +0300 2774)     fprintf( stdout, "|======================================================================|\n" );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2775)     fprintf( stdout, "%s\n", description );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2776)     fprintf( stdout, "|======================================================================|\n\n" );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2777)     fprintf( stdout, "\n\n\n" ); /* 3 lines up for final message */
11c606a6 (kx 2023-04-11 01:18:34 +0300 2778)   }
11c606a6 (kx 2023-04-11 01:18:34 +0300 2779) }
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) static void pre_update_routine( void )
11c606a6 (kx 2023-04-11 01:18:34 +0300 2783) {
11c606a6 (kx 2023-04-11 01:18:34 +0300 2784)   pid_t p = (pid_t) -1;
11c606a6 (kx 2023-04-11 01:18:34 +0300 2785)   int   rc;
11c606a6 (kx 2023-04-11 01:18:34 +0300 2786) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 2787)   int   len = 0;
11c606a6 (kx 2023-04-11 01:18:34 +0300 2788)   char *cmd = NULL;
11c606a6 (kx 2023-04-11 01:18:34 +0300 2789) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 2790)   cmd = (char *)malloc( (size_t)PATH_MAX );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2791)   if( !cmd ) { FATAL_ERROR( "Cannot allocate memory" ); }
11c606a6 (kx 2023-04-11 01:18:34 +0300 2792)   bzero( (void *)cmd, PATH_MAX );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2793) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 2794)   len = snprintf( &cmd[0], PATH_MAX,
11c606a6 (kx 2023-04-11 01:18:34 +0300 2795)                   "cd %s && %s/.INSTALL pre_update %s %s > /dev/null 2>&1",
11c606a6 (kx 2023-04-11 01:18:34 +0300 2796)                   root, tmpdir, pkgver, installed_version );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2797)   if( len == 0 || len == PATH_MAX - 1 )
11c606a6 (kx 2023-04-11 01:18:34 +0300 2798)   {
11c606a6 (kx 2023-04-11 01:18:34 +0300 2799)     FATAL_ERROR( "Cannot run pre-update script for '%s-%s' package", pkgname, pkgver );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2800)   }
11c606a6 (kx 2023-04-11 01:18:34 +0300 2801)   p = sys_exec_command( cmd );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2802)   rc = sys_wait_command( p, (char *)NULL, PATH_MAX );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2803) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 2804)   free( cmd );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2805) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 2806)   if( rc != 0 )
11c606a6 (kx 2023-04-11 01:18:34 +0300 2807)   {
11c606a6 (kx 2023-04-11 01:18:34 +0300 2808)     exit_status = 43;
11c606a6 (kx 2023-04-11 01:18:34 +0300 2809) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 2810)     if( update_mode != CONSOLE )
11c606a6 (kx 2023-04-11 01:18:34 +0300 2811)     {
11c606a6 (kx 2023-04-11 01:18:34 +0300 2812) #if defined( HAVE_DIALOG )
11c606a6 (kx 2023-04-11 01:18:34 +0300 2813)       info_pkg_box( "Update:", pkgname, pkgver, strprio( priority, 0 ),
11c606a6 (kx 2023-04-11 01:18:34 +0300 2814)                     "\n\\Z1Pre-update script returned error status.\\Zn\n", 5, 0, 0 );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2815) #else
11c606a6 (kx 2023-04-11 01:18:34 +0300 2816)       fprintf( stdout, "\nPre-update script of '%s-%s' returned error status.\n\n", pkgname, pkgver );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2817) #endif
11c606a6 (kx 2023-04-11 01:18:34 +0300 2818)     }
11c606a6 (kx 2023-04-11 01:18:34 +0300 2819)     else
11c606a6 (kx 2023-04-11 01:18:34 +0300 2820)     {
11c606a6 (kx 2023-04-11 01:18:34 +0300 2821)       fprintf( stdout, "\nPre-update script of '%s-%s' returned error status.\n\n", pkgname, pkgver );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2822)     }
11c606a6 (kx 2023-04-11 01:18:34 +0300 2823) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 2824)     if( tmpdir ) { _rm_tmpdir( (const char *)tmpdir ); free( tmpdir ); }
11c606a6 (kx 2023-04-11 01:18:34 +0300 2825)     free_resources();
11c606a6 (kx 2023-04-11 01:18:34 +0300 2826)     exit( exit_status );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2827)   }
11c606a6 (kx 2023-04-11 01:18:34 +0300 2828) }
11c606a6 (kx 2023-04-11 01:18:34 +0300 2829) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 2830) static const char *fill_decompressor( char *buffer, char compressor )
11c606a6 (kx 2023-04-11 01:18:34 +0300 2831) {
11c606a6 (kx 2023-04-11 01:18:34 +0300 2832)   switch( compressor )
11c606a6 (kx 2023-04-11 01:18:34 +0300 2833)   {
11c606a6 (kx 2023-04-11 01:18:34 +0300 2834)     case 'J':
11c606a6 (kx 2023-04-11 01:18:34 +0300 2835)       (void)sprintf( buffer, "xz --threads=%d -dc", get_nprocs() );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2836)       break;
11c606a6 (kx 2023-04-11 01:18:34 +0300 2837)     case 'j':
11c606a6 (kx 2023-04-11 01:18:34 +0300 2838)       (void)sprintf( buffer, "bzip2 -dc" );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2839)       break;
11c606a6 (kx 2023-04-11 01:18:34 +0300 2840)     case 'z':
11c606a6 (kx 2023-04-11 01:18:34 +0300 2841)       (void)sprintf( buffer, "gzip -dc" );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2842)       break;
11c606a6 (kx 2023-04-11 01:18:34 +0300 2843)     default:
11c606a6 (kx 2023-04-11 01:18:34 +0300 2844)       (void)sprintf( buffer, "cat -" );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2845)       break;
11c606a6 (kx 2023-04-11 01:18:34 +0300 2846)   }
11c606a6 (kx 2023-04-11 01:18:34 +0300 2847)   return (const char *)buffer;
11c606a6 (kx 2023-04-11 01:18:34 +0300 2848) }
11c606a6 (kx 2023-04-11 01:18:34 +0300 2849) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 2850) static void uncompress_package( void )
11c606a6 (kx 2023-04-11 01:18:34 +0300 2851) {
11c606a6 (kx 2023-04-11 01:18:34 +0300 2852)   pid_t p = (pid_t) -1;
11c606a6 (kx 2023-04-11 01:18:34 +0300 2853)   int   rc;
11c606a6 (kx 2023-04-11 01:18:34 +0300 2854) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 2855)   int   len = 0;
11c606a6 (kx 2023-04-11 01:18:34 +0300 2856)   char *cmd = NULL;
11c606a6 (kx 2023-04-11 01:18:34 +0300 2857) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 2858)   char decompressor[64];
11c606a6 (kx 2023-04-11 01:18:34 +0300 2859) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 2860)   (void)fill_decompressor( (char *)&decompressor[0], uncompress );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2861) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 2862)   cmd = (char *)malloc( (size_t)PATH_MAX );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2863)   if( !cmd ) { FATAL_ERROR( "Cannot allocate memory" ); }
11c606a6 (kx 2023-04-11 01:18:34 +0300 2864)   bzero( (void *)cmd, PATH_MAX );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2865) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 2866)   len = snprintf( &cmd[0], PATH_MAX,
11c606a6 (kx 2023-04-11 01:18:34 +0300 2867)                   "cat %s | %s  | tar -C %s "
11c606a6 (kx 2023-04-11 01:18:34 +0300 2868)                   "--exclude='.DESCRIPTION' "
11c606a6 (kx 2023-04-11 01:18:34 +0300 2869)                   "--exclude='.FILELIST' "
11c606a6 (kx 2023-04-11 01:18:34 +0300 2870)                   "--exclude='.INSTALL' "
11c606a6 (kx 2023-04-11 01:18:34 +0300 2871)                   "--exclude='.PKGINFO' "
11c606a6 (kx 2023-04-11 01:18:34 +0300 2872)                   "--exclude='.REQUIRES' "
11c606a6 (kx 2023-04-11 01:18:34 +0300 2873)                   "--exclude='.RESTORELINKS' "
11c606a6 (kx 2023-04-11 01:18:34 +0300 2874)                   "-xf - > /dev/null 2>&1",
11c606a6 (kx 2023-04-11 01:18:34 +0300 2875)                   pkg_fname, decompressor, root );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2876)   if( len == 0 || len == PATH_MAX - 1 )
11c606a6 (kx 2023-04-11 01:18:34 +0300 2877)   {
11c606a6 (kx 2023-04-11 01:18:34 +0300 2878)     FATAL_ERROR( "Cannot uncompress '%s-%s' package", pkgname, pkgver );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2879)   }
11c606a6 (kx 2023-04-11 01:18:34 +0300 2880)   p = sys_exec_command( cmd );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2881)   rc = sys_wait_command( p, (char *)NULL, PATH_MAX );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2882) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 2883)   free( cmd );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2884) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 2885)   if( rc != 0 )
11c606a6 (kx 2023-04-11 01:18:34 +0300 2886)   {
11c606a6 (kx 2023-04-11 01:18:34 +0300 2887)     exit_status = 44;
11c606a6 (kx 2023-04-11 01:18:34 +0300 2888) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 2889)     if( update_mode != CONSOLE )
11c606a6 (kx 2023-04-11 01:18:34 +0300 2890)     {
11c606a6 (kx 2023-04-11 01:18:34 +0300 2891) #if defined( HAVE_DIALOG )
11c606a6 (kx 2023-04-11 01:18:34 +0300 2892)       info_pkg_box( "Update:", pkgname, pkgver, strprio( priority, 0 ),
11c606a6 (kx 2023-04-11 01:18:34 +0300 2893)                     "\n\\Z1Cannot uncompress package.\\Zn\n", 5, 0, 0 );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2894) #else
11c606a6 (kx 2023-04-11 01:18:34 +0300 2895)       fprintf( stdout, "\nCannot uncompress '%s-%s' package.\n\n", pkgname, pkgver );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2896) #endif
11c606a6 (kx 2023-04-11 01:18:34 +0300 2897)     }
11c606a6 (kx 2023-04-11 01:18:34 +0300 2898)     else
11c606a6 (kx 2023-04-11 01:18:34 +0300 2899)     {
11c606a6 (kx 2023-04-11 01:18:34 +0300 2900)       fprintf( stdout, "\nCannot uncompress '%s-%s' package.\n\n", pkgname, pkgver );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2901)     }
11c606a6 (kx 2023-04-11 01:18:34 +0300 2902) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 2903)     if( tmpdir ) { _rm_tmpdir( (const char *)tmpdir ); free( tmpdir ); }
11c606a6 (kx 2023-04-11 01:18:34 +0300 2904)     free_resources();
11c606a6 (kx 2023-04-11 01:18:34 +0300 2905)     exit( exit_status );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2906)   }
11c606a6 (kx 2023-04-11 01:18:34 +0300 2907) }
11c606a6 (kx 2023-04-11 01:18:34 +0300 2908) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 2909) static void restore_links( void )
11c606a6 (kx 2023-04-11 01:18:34 +0300 2910) {
11c606a6 (kx 2023-04-11 01:18:34 +0300 2911)   struct stat st;
11c606a6 (kx 2023-04-11 01:18:34 +0300 2912)   pid_t  p = (pid_t) -1;
11c606a6 (kx 2023-04-11 01:18:34 +0300 2913)   int    rc;
11c606a6 (kx 2023-04-11 01:18:34 +0300 2914) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 2915)   int   len = 0;
11c606a6 (kx 2023-04-11 01:18:34 +0300 2916)   char *cmd = NULL;
11c606a6 (kx 2023-04-11 01:18:34 +0300 2917) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 2918)   cmd = (char *)malloc( (size_t)PATH_MAX );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2919)   if( !cmd ) { FATAL_ERROR( "Cannot allocate memory" ); }
11c606a6 (kx 2023-04-11 01:18:34 +0300 2920)   bzero( (void *)cmd, PATH_MAX );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2921) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 2922)   (void)sprintf( &cmd[0], "%s/.RESTORELINKS", tmpdir );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2923)   bzero( (void *)&st, sizeof( struct stat ) );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2924)   if( (stat( (const char *)&cmd[0], &st ) == -1) || (st.st_size < 8) )
11c606a6 (kx 2023-04-11 01:18:34 +0300 2925)   {
11c606a6 (kx 2023-04-11 01:18:34 +0300 2926)     free( cmd );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2927)     return;
11c606a6 (kx 2023-04-11 01:18:34 +0300 2928)   }
11c606a6 (kx 2023-04-11 01:18:34 +0300 2929)   bzero( (void *)cmd, PATH_MAX );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2930) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 2931)   len = snprintf( &cmd[0], PATH_MAX,
11c606a6 (kx 2023-04-11 01:18:34 +0300 2932)                   "cd %s && sh %s/.RESTORELINKS > /dev/null 2>&1",
11c606a6 (kx 2023-04-11 01:18:34 +0300 2933)                   root, tmpdir );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2934)   if( len == 0 || len == PATH_MAX - 1 )
11c606a6 (kx 2023-04-11 01:18:34 +0300 2935)   {
11c606a6 (kx 2023-04-11 01:18:34 +0300 2936)     FATAL_ERROR( "Cannot restore links for '%s-%s' package", pkgname, pkgver );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2937)   }
11c606a6 (kx 2023-04-11 01:18:34 +0300 2938)   p = sys_exec_command( cmd );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2939)   rc = sys_wait_command( p, (char *)NULL, PATH_MAX );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2940) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 2941)   free( cmd );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2942) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 2943)   if( rc != 0 )
11c606a6 (kx 2023-04-11 01:18:34 +0300 2944)   {
11c606a6 (kx 2023-04-11 01:18:34 +0300 2945)     rollback();
11c606a6 (kx 2023-04-11 01:18:34 +0300 2946) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 2947)     exit_status = 45;
11c606a6 (kx 2023-04-11 01:18:34 +0300 2948) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 2949)     if( update_mode != CONSOLE )
11c606a6 (kx 2023-04-11 01:18:34 +0300 2950)     {
11c606a6 (kx 2023-04-11 01:18:34 +0300 2951) #if defined( HAVE_DIALOG )
11c606a6 (kx 2023-04-11 01:18:34 +0300 2952)       info_pkg_box( "Update:", pkgname, pkgver, strprio( priority, 0 ),
11c606a6 (kx 2023-04-11 01:18:34 +0300 2953)                     "\n\\Z1Restore-links script returned error status.\\Zn\n", 5, 0, 0 );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2954) #else
11c606a6 (kx 2023-04-11 01:18:34 +0300 2955)       fprintf( stdout, "\nRestore-links script of '%s-%s' returned error status.\n\n", pkgname, pkgver );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2956) #endif
11c606a6 (kx 2023-04-11 01:18:34 +0300 2957)     }
11c606a6 (kx 2023-04-11 01:18:34 +0300 2958)     else
11c606a6 (kx 2023-04-11 01:18:34 +0300 2959)     {
11c606a6 (kx 2023-04-11 01:18:34 +0300 2960)       fprintf( stdout, "\nRestore-links script of '%s-%s' returned error status.\n\n", pkgname, pkgver );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2961)     }
11c606a6 (kx 2023-04-11 01:18:34 +0300 2962) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 2963)     if( tmpdir ) { _rm_tmpdir( (const char *)tmpdir ); free( tmpdir ); }
11c606a6 (kx 2023-04-11 01:18:34 +0300 2964)     free_resources();
11c606a6 (kx 2023-04-11 01:18:34 +0300 2965)     exit( exit_status );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2966)   }
11c606a6 (kx 2023-04-11 01:18:34 +0300 2967) }
11c606a6 (kx 2023-04-11 01:18:34 +0300 2968) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 2969) static void post_update_routine( void )
11c606a6 (kx 2023-04-11 01:18:34 +0300 2970) {
11c606a6 (kx 2023-04-11 01:18:34 +0300 2971)   pid_t p = (pid_t) -1;
11c606a6 (kx 2023-04-11 01:18:34 +0300 2972)   int   rc;
11c606a6 (kx 2023-04-11 01:18:34 +0300 2973) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 2974)   int   len = 0;
11c606a6 (kx 2023-04-11 01:18:34 +0300 2975)   char *cmd = NULL;
11c606a6 (kx 2023-04-11 01:18:34 +0300 2976) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 2977)   cmd = (char *)malloc( (size_t)PATH_MAX );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2978)   if( !cmd ) { FATAL_ERROR( "Cannot allocate memory" ); }
11c606a6 (kx 2023-04-11 01:18:34 +0300 2979)   bzero( (void *)cmd, PATH_MAX );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2980) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 2981)   len = snprintf( &cmd[0], PATH_MAX,
11c606a6 (kx 2023-04-11 01:18:34 +0300 2982)                   "cd %s && %s/.INSTALL post_update %s %s > /dev/null 2>&1",
11c606a6 (kx 2023-04-11 01:18:34 +0300 2983)                   root, tmpdir, pkgver, installed_version );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2984)   if( len == 0 || len == PATH_MAX - 1 )
11c606a6 (kx 2023-04-11 01:18:34 +0300 2985)   {
11c606a6 (kx 2023-04-11 01:18:34 +0300 2986)     FATAL_ERROR( "Cannot run post-update script for '%s-%s' package", pkgname, pkgver );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2987)   }
11c606a6 (kx 2023-04-11 01:18:34 +0300 2988)   p = sys_exec_command( cmd );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2989)   rc = sys_wait_command( p, (char *)NULL, PATH_MAX );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2990) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 2991)   free( cmd );
11c606a6 (kx 2023-04-11 01:18:34 +0300 2992) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 2993)   if( rc != 0 )
11c606a6 (kx 2023-04-11 01:18:34 +0300 2994)   {
11c606a6 (kx 2023-04-11 01:18:34 +0300 2995)     rollback();
11c606a6 (kx 2023-04-11 01:18:34 +0300 2996) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 2997)     exit_status = 46;
11c606a6 (kx 2023-04-11 01:18:34 +0300 2998) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 2999)     if( update_mode != CONSOLE )
11c606a6 (kx 2023-04-11 01:18:34 +0300 3000)     {
11c606a6 (kx 2023-04-11 01:18:34 +0300 3001) #if defined( HAVE_DIALOG )
11c606a6 (kx 2023-04-11 01:18:34 +0300 3002)       info_pkg_box( "Update:", pkgname, pkgver, strprio( priority, 0 ),
11c606a6 (kx 2023-04-11 01:18:34 +0300 3003)                     "\n\\Z1Post-update script returned error status.\\Zn\n", 5, 0, 0 );
11c606a6 (kx 2023-04-11 01:18:34 +0300 3004) #else
11c606a6 (kx 2023-04-11 01:18:34 +0300 3005)       fprintf( stdout, "\nPost-update script of '%s-%s' returned error status.\n\n", pkgname, pkgver );
11c606a6 (kx 2023-04-11 01:18:34 +0300 3006) #endif
11c606a6 (kx 2023-04-11 01:18:34 +0300 3007)     }
11c606a6 (kx 2023-04-11 01:18:34 +0300 3008)     else
11c606a6 (kx 2023-04-11 01:18:34 +0300 3009)     {
11c606a6 (kx 2023-04-11 01:18:34 +0300 3010)       fprintf( stdout, "\nPost-update script of '%s-%s' returned error status.\n\n", pkgname, pkgver );
11c606a6 (kx 2023-04-11 01:18:34 +0300 3011)     }
11c606a6 (kx 2023-04-11 01:18:34 +0300 3012) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 3013)     if( tmpdir ) { _rm_tmpdir( (const char *)tmpdir ); free( tmpdir ); }
11c606a6 (kx 2023-04-11 01:18:34 +0300 3014)     free_resources();
11c606a6 (kx 2023-04-11 01:18:34 +0300 3015)     exit( exit_status );
11c606a6 (kx 2023-04-11 01:18:34 +0300 3016)   }
11c606a6 (kx 2023-04-11 01:18:34 +0300 3017) }
11c606a6 (kx 2023-04-11 01:18:34 +0300 3018) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 3019) static void finalize_update( void )
11c606a6 (kx 2023-04-11 01:18:34 +0300 3020) {
11c606a6 (kx 2023-04-11 01:18:34 +0300 3021)   pid_t p = (pid_t) -1;
11c606a6 (kx 2023-04-11 01:18:34 +0300 3022)   int   rc;
11c606a6 (kx 2023-04-11 01:18:34 +0300 3023) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 3024)   int   len = 0;
11c606a6 (kx 2023-04-11 01:18:34 +0300 3025)   char *cmd = NULL, *tmp = NULL;
11c606a6 (kx 2023-04-11 01:18:34 +0300 3026) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 3027)   cmd = (char *)malloc( (size_t)PATH_MAX );
11c606a6 (kx 2023-04-11 01:18:34 +0300 3028)   if( !cmd ) { FATAL_ERROR( "Cannot allocate memory" ); }
11c606a6 (kx 2023-04-11 01:18:34 +0300 3029)   bzero( (void *)cmd, PATH_MAX );
11c606a6 (kx 2023-04-11 01:18:34 +0300 3030) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 3031)   tmp = (char *)malloc( (size_t)PATH_MAX );
11c606a6 (kx 2023-04-11 01:18:34 +0300 3032)   if( !tmp ) { FATAL_ERROR( "Cannot allocate memory" ); }
11c606a6 (kx 2023-04-11 01:18:34 +0300 3033)   bzero( (void *)tmp, PATH_MAX );
11c606a6 (kx 2023-04-11 01:18:34 +0300 3034) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 3035)   if( group )
11c606a6 (kx 2023-04-11 01:18:34 +0300 3036)     (void)sprintf( &tmp[0], "%s/%s/", pkgs_path, group );
11c606a6 (kx 2023-04-11 01:18:34 +0300 3037)   else
11c606a6 (kx 2023-04-11 01:18:34 +0300 3038)     (void)sprintf( &tmp[0], "%s/", pkgs_path );
11c606a6 (kx 2023-04-11 01:18:34 +0300 3039) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 3040)   if( _mkdir_p( tmp, S_IRWXU | S_IRWXG | S_IRWXO ) != 0 )
11c606a6 (kx 2023-04-11 01:18:34 +0300 3041)   {
11c606a6 (kx 2023-04-11 01:18:34 +0300 3042)     FATAL_ERROR( "Cannot access '/%s' directory", PACKAGES_PATH );
11c606a6 (kx 2023-04-11 01:18:34 +0300 3043)   }
11c606a6 (kx 2023-04-11 01:18:34 +0300 3044) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 3045)   /****************************************
11c606a6 (kx 2023-04-11 01:18:34 +0300 3046)     Store PKGLOG file into Setup Database:
11c606a6 (kx 2023-04-11 01:18:34 +0300 3047)    */
11c606a6 (kx 2023-04-11 01:18:34 +0300 3048)   len = snprintf( &cmd[0], PATH_MAX,
11c606a6 (kx 2023-04-11 01:18:34 +0300 3049)                   "cp %s %s > /dev/null 2>&1",
11c606a6 (kx 2023-04-11 01:18:34 +0300 3050)                   pkglog_fname, (const char *)&tmp[0] );
11c606a6 (kx 2023-04-11 01:18:34 +0300 3051)   if( len == 0 || len == PATH_MAX - 1 )
11c606a6 (kx 2023-04-11 01:18:34 +0300 3052)   {
11c606a6 (kx 2023-04-11 01:18:34 +0300 3053)     FATAL_ERROR( "Cannot store '%s' pkglog file", basename( (char *)pkglog_fname ) );
11c606a6 (kx 2023-04-11 01:18:34 +0300 3054)   }
11c606a6 (kx 2023-04-11 01:18:34 +0300 3055)   p = sys_exec_command( cmd );
11c606a6 (kx 2023-04-11 01:18:34 +0300 3056)   rc = sys_wait_command( p, (char *)NULL, PATH_MAX );
11c606a6 (kx 2023-04-11 01:18:34 +0300 3057)   if( rc != 0 )
11c606a6 (kx 2023-04-11 01:18:34 +0300 3058)   {
11c606a6 (kx 2023-04-11 01:18:34 +0300 3059)     rollback();
11c606a6 (kx 2023-04-11 01:18:34 +0300 3060) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 3061)     free( cmd );
11c606a6 (kx 2023-04-11 01:18:34 +0300 3062)     free( tmp );
11c606a6 (kx 2023-04-11 01:18:34 +0300 3063) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 3064)     exit_status = 47;
11c606a6 (kx 2023-04-11 01:18:34 +0300 3065) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 3066)     if( update_mode != CONSOLE )
11c606a6 (kx 2023-04-11 01:18:34 +0300 3067)     {
11c606a6 (kx 2023-04-11 01:18:34 +0300 3068) #if defined( HAVE_DIALOG )
11c606a6 (kx 2023-04-11 01:18:34 +0300 3069)       info_pkg_box( "Update:", pkgname, pkgver, strprio( priority, 0 ),
11c606a6 (kx 2023-04-11 01:18:34 +0300 3070)                     "\n\\Z1Cannot store PKGLOG file into Setup Database.\\Zn\n", 5, 0, 0 );
11c606a6 (kx 2023-04-11 01:18:34 +0300 3071) #else
11c606a6 (kx 2023-04-11 01:18:34 +0300 3072)       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 3073) #endif
11c606a6 (kx 2023-04-11 01:18:34 +0300 3074)     }
11c606a6 (kx 2023-04-11 01:18:34 +0300 3075)     else
11c606a6 (kx 2023-04-11 01:18:34 +0300 3076)     {
11c606a6 (kx 2023-04-11 01:18:34 +0300 3077)       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 3078)     }
11c606a6 (kx 2023-04-11 01:18:34 +0300 3079) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 3080)     if( tmpdir ) { _rm_tmpdir( (const char *)tmpdir ); free( tmpdir ); }
11c606a6 (kx 2023-04-11 01:18:34 +0300 3081)     free_resources();
11c606a6 (kx 2023-04-11 01:18:34 +0300 3082)     exit( exit_status );
11c606a6 (kx 2023-04-11 01:18:34 +0300 3083)   }
11c606a6 (kx 2023-04-11 01:18:34 +0300 3084) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 3085)   /*********************************************
11c606a6 (kx 2023-04-11 01:18:34 +0300 3086)     Increment references in the Setup Database:
11c606a6 (kx 2023-04-11 01:18:34 +0300 3087)    */
a745159c (kx 2023-10-23 21:39:58 +0300 3088) if( !disable_chrefs )
a745159c (kx 2023-10-23 21:39:58 +0300 3089) {
11c606a6 (kx 2023-04-11 01:18:34 +0300 3090)   if( group )
11c606a6 (kx 2023-04-11 01:18:34 +0300 3091)     len = snprintf( &cmd[0], PATH_MAX,
11c606a6 (kx 2023-04-11 01:18:34 +0300 3092)                     "%s/chrefs --operation=inc --destination=%s %s/%s > /dev/null 2>&1",
11c606a6 (kx 2023-04-11 01:18:34 +0300 3093)                     selfdir, pkgs_path, group, basename( (char *)pkglog_fname ) );
11c606a6 (kx 2023-04-11 01:18:34 +0300 3094)   else
11c606a6 (kx 2023-04-11 01:18:34 +0300 3095)     len = snprintf( &cmd[0], PATH_MAX,
11c606a6 (kx 2023-04-11 01:18:34 +0300 3096)                     "%s/chrefs --operation=inc --destination=%s %s > /dev/null 2>&1",
11c606a6 (kx 2023-04-11 01:18:34 +0300 3097)                     selfdir, pkgs_path, basename( (char *)pkglog_fname ) );
11c606a6 (kx 2023-04-11 01:18:34 +0300 3098)   if( len == 0 || len == PATH_MAX - 1 )
11c606a6 (kx 2023-04-11 01:18:34 +0300 3099)   {
11c606a6 (kx 2023-04-11 01:18:34 +0300 3100)     FATAL_ERROR( "Cannot increment '%s-%s' package references", pkgname, pkgver );
11c606a6 (kx 2023-04-11 01:18:34 +0300 3101)   }
11c606a6 (kx 2023-04-11 01:18:34 +0300 3102)   p = sys_exec_command( cmd );
11c606a6 (kx 2023-04-11 01:18:34 +0300 3103)   rc = sys_wait_command( p, (char *)NULL, PATH_MAX );
11c606a6 (kx 2023-04-11 01:18:34 +0300 3104) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 3105)   free( cmd );
11c606a6 (kx 2023-04-11 01:18:34 +0300 3106) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 3107)   if( (rc != 0) && !ignore_chrefs_errors )
11c606a6 (kx 2023-04-11 01:18:34 +0300 3108)   {
11c606a6 (kx 2023-04-11 01:18:34 +0300 3109)     free( tmp );
11c606a6 (kx 2023-04-11 01:18:34 +0300 3110) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 3111)     rollback();
11c606a6 (kx 2023-04-11 01:18:34 +0300 3112) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 3113)     exit_status = 48;
11c606a6 (kx 2023-04-11 01:18:34 +0300 3114) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 3115)     if( update_mode != CONSOLE )
11c606a6 (kx 2023-04-11 01:18:34 +0300 3116)     {
11c606a6 (kx 2023-04-11 01:18:34 +0300 3117) #if defined( HAVE_DIALOG )
11c606a6 (kx 2023-04-11 01:18:34 +0300 3118)       info_pkg_box( "Update:", pkgname, pkgver, strprio( priority, 0 ),
11c606a6 (kx 2023-04-11 01:18:34 +0300 3119)                     "\n\\Z1Cannot increment package references in Setup Database.\\Zn\n", 5, 0, 0 );
11c606a6 (kx 2023-04-11 01:18:34 +0300 3120) #else
11c606a6 (kx 2023-04-11 01:18:34 +0300 3121)       fprintf( stdout, "\nCannot increment '%s-%s' package references in Setup Database.\n\n", pkgname, pkgver );
11c606a6 (kx 2023-04-11 01:18:34 +0300 3122) #endif
11c606a6 (kx 2023-04-11 01:18:34 +0300 3123)     }
11c606a6 (kx 2023-04-11 01:18:34 +0300 3124)     else
11c606a6 (kx 2023-04-11 01:18:34 +0300 3125)     {
11c606a6 (kx 2023-04-11 01:18:34 +0300 3126)       fprintf( stdout, "\nCannot increment '%s-%s' package references in Setup Database.\n\n", pkgname, pkgver );
11c606a6 (kx 2023-04-11 01:18:34 +0300 3127)     }
11c606a6 (kx 2023-04-11 01:18:34 +0300 3128) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 3129)     if( tmpdir ) { _rm_tmpdir( (const char *)tmpdir ); free( tmpdir ); }
11c606a6 (kx 2023-04-11 01:18:34 +0300 3130)     free_resources();
11c606a6 (kx 2023-04-11 01:18:34 +0300 3131)     exit( exit_status );
11c606a6 (kx 2023-04-11 01:18:34 +0300 3132)   }
a745159c (kx 2023-10-23 21:39:58 +0300 3133) }
11c606a6 (kx 2023-04-11 01:18:34 +0300 3134) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 3135)   /*************************************************
11c606a6 (kx 2023-04-11 01:18:34 +0300 3136)     Remove backup PKGLOG file from removed-packages
11c606a6 (kx 2023-04-11 01:18:34 +0300 3137)     directory if exists:
11c606a6 (kx 2023-04-11 01:18:34 +0300 3138)    */
11c606a6 (kx 2023-04-11 01:18:34 +0300 3139)   bzero( (void *)tmp, PATH_MAX );
11c606a6 (kx 2023-04-11 01:18:34 +0300 3140)   {
11c606a6 (kx 2023-04-11 01:18:34 +0300 3141)     const char *fname = basename( (char *)pkglog_fname );
11c606a6 (kx 2023-04-11 01:18:34 +0300 3142) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 3143)     if( group )
11c606a6 (kx 2023-04-11 01:18:34 +0300 3144)       (void)sprintf( &tmp[0], "%s/%s/%s", rempkgs_path, group, fname );
11c606a6 (kx 2023-04-11 01:18:34 +0300 3145)     else
11c606a6 (kx 2023-04-11 01:18:34 +0300 3146)       (void)sprintf( &tmp[0], "%s/%s", rempkgs_path, fname );
11c606a6 (kx 2023-04-11 01:18:34 +0300 3147) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 3148)     (void)unlink( (const char *)&tmp[0] );
11c606a6 (kx 2023-04-11 01:18:34 +0300 3149) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 3150)     if( group )
11c606a6 (kx 2023-04-11 01:18:34 +0300 3151)     {
11c606a6 (kx 2023-04-11 01:18:34 +0300 3152)       const char *dir = (const char *)dirname( (char *)&tmp[0] );
11c606a6 (kx 2023-04-11 01:18:34 +0300 3153)       if( is_dir_empty( dir ) )
11c606a6 (kx 2023-04-11 01:18:34 +0300 3154)       {
11c606a6 (kx 2023-04-11 01:18:34 +0300 3155)         (void)rmdir( dir );
11c606a6 (kx 2023-04-11 01:18:34 +0300 3156)       }
11c606a6 (kx 2023-04-11 01:18:34 +0300 3157)     }
11c606a6 (kx 2023-04-11 01:18:34 +0300 3158)   }
11c606a6 (kx 2023-04-11 01:18:34 +0300 3159) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 3160)   free( tmp );
11c606a6 (kx 2023-04-11 01:18:34 +0300 3161) }
11c606a6 (kx 2023-04-11 01:18:34 +0300 3162) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 3163) #if defined( HAVE_GPG2 )
11c606a6 (kx 2023-04-11 01:18:34 +0300 3164) static void verify_gpg_signature( void )
11c606a6 (kx 2023-04-11 01:18:34 +0300 3165) {
11c606a6 (kx 2023-04-11 01:18:34 +0300 3166)   struct stat st;
11c606a6 (kx 2023-04-11 01:18:34 +0300 3167)   pid_t  p = (pid_t) -1;
11c606a6 (kx 2023-04-11 01:18:34 +0300 3168)   int    rc;
11c606a6 (kx 2023-04-11 01:18:34 +0300 3169) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 3170)   int   len = 0;
11c606a6 (kx 2023-04-11 01:18:34 +0300 3171)   char *cmd = NULL;
11c606a6 (kx 2023-04-11 01:18:34 +0300 3172) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 3173)   bzero( (void *)&st, sizeof( struct stat ) );
11c606a6 (kx 2023-04-11 01:18:34 +0300 3174) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 3175)   /******************************************************************
11c606a6 (kx 2023-04-11 01:18:34 +0300 3176)     Do not try to verify signature if '.asc' file is not accessible:
11c606a6 (kx 2023-04-11 01:18:34 +0300 3177)    */
11c606a6 (kx 2023-04-11 01:18:34 +0300 3178)   if( stat( (const char *)asc_fname, &st ) == -1 ) return;
11c606a6 (kx 2023-04-11 01:18:34 +0300 3179) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 3180)   cmd = (char *)malloc( (size_t)PATH_MAX );
11c606a6 (kx 2023-04-11 01:18:34 +0300 3181)   if( !cmd ) { FATAL_ERROR( "Cannot allocate memory" ); }
11c606a6 (kx 2023-04-11 01:18:34 +0300 3182)   bzero( (void *)cmd, PATH_MAX );
11c606a6 (kx 2023-04-11 01:18:34 +0300 3183) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 3184)   len = snprintf( &cmd[0], PATH_MAX,
11c606a6 (kx 2023-04-11 01:18:34 +0300 3185)                   "gpg2 --verify %s %s > /dev/null 2>&1",
11c606a6 (kx 2023-04-11 01:18:34 +0300 3186)                   asc_fname, pkg_fname );
11c606a6 (kx 2023-04-11 01:18:34 +0300 3187)   if( len == 0 || len == PATH_MAX - 1 )
11c606a6 (kx 2023-04-11 01:18:34 +0300 3188)   {
11c606a6 (kx 2023-04-11 01:18:34 +0300 3189)     FATAL_ERROR( "Cannot verify GPG2 signature of '%s-%s' package", pkgname, pkgver );
11c606a6 (kx 2023-04-11 01:18:34 +0300 3190)   }
11c606a6 (kx 2023-04-11 01:18:34 +0300 3191)   p = sys_exec_command( cmd );
11c606a6 (kx 2023-04-11 01:18:34 +0300 3192)   rc = sys_wait_command( p, (char *)NULL, PATH_MAX );
11c606a6 (kx 2023-04-11 01:18:34 +0300 3193) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 3194)   free( cmd );
11c606a6 (kx 2023-04-11 01:18:34 +0300 3195) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 3196)   if( rc != 0 )
11c606a6 (kx 2023-04-11 01:18:34 +0300 3197)   {
11c606a6 (kx 2023-04-11 01:18:34 +0300 3198)     exit_status = 51;
11c606a6 (kx 2023-04-11 01:18:34 +0300 3199) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 3200)     if( update_mode != CONSOLE )
11c606a6 (kx 2023-04-11 01:18:34 +0300 3201)     {
11c606a6 (kx 2023-04-11 01:18:34 +0300 3202) #if defined( HAVE_DIALOG )
11c606a6 (kx 2023-04-11 01:18:34 +0300 3203)       info_pkg_box( "Update:", pkgname, pkgver, strprio( priority, 0 ),
11c606a6 (kx 2023-04-11 01:18:34 +0300 3204)                     "\n\\Z1Cannot verify GPG2 signature of the package.\\Zn\n", 5, 0, 0 );
11c606a6 (kx 2023-04-11 01:18:34 +0300 3205) #else
11c606a6 (kx 2023-04-11 01:18:34 +0300 3206)       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 3207) #endif
11c606a6 (kx 2023-04-11 01:18:34 +0300 3208)     }
11c606a6 (kx 2023-04-11 01:18:34 +0300 3209)     else
11c606a6 (kx 2023-04-11 01:18:34 +0300 3210)     {
11c606a6 (kx 2023-04-11 01:18:34 +0300 3211)       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 3212)     }
11c606a6 (kx 2023-04-11 01:18:34 +0300 3213) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 3214)     if( tmpdir ) { _rm_tmpdir( (const char *)tmpdir ); free( tmpdir ); }
11c606a6 (kx 2023-04-11 01:18:34 +0300 3215)     free_resources();
11c606a6 (kx 2023-04-11 01:18:34 +0300 3216)     exit( exit_status );
11c606a6 (kx 2023-04-11 01:18:34 +0300 3217)   }
11c606a6 (kx 2023-04-11 01:18:34 +0300 3218) }
11c606a6 (kx 2023-04-11 01:18:34 +0300 3219) #endif
11c606a6 (kx 2023-04-11 01:18:34 +0300 3220) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 3221) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 3222) static void dialogrc( void )
11c606a6 (kx 2023-04-11 01:18:34 +0300 3223) {
11c606a6 (kx 2023-04-11 01:18:34 +0300 3224)   struct stat st;
11c606a6 (kx 2023-04-11 01:18:34 +0300 3225)   char  *tmp = NULL;
11c606a6 (kx 2023-04-11 01:18:34 +0300 3226) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 3227)   tmp = (char *)malloc( (size_t)PATH_MAX );
11c606a6 (kx 2023-04-11 01:18:34 +0300 3228)   if( !tmp ) { FATAL_ERROR( "Cannot allocate memory" ); }
11c606a6 (kx 2023-04-11 01:18:34 +0300 3229)   bzero( (void *)tmp, PATH_MAX );
11c606a6 (kx 2023-04-11 01:18:34 +0300 3230) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 3231)   /* imagine that the utility is in /sbin directory: */
11c606a6 (kx 2023-04-11 01:18:34 +0300 3232)   (void)sprintf( &tmp[0], "%s/../usr/share/%s/.dialogrc", selfdir, PACKAGE_NAME );
11c606a6 (kx 2023-04-11 01:18:34 +0300 3233)   if( stat( (const char *)&tmp[0], &st ) == -1 )
11c606a6 (kx 2023-04-11 01:18:34 +0300 3234)   {
11c606a6 (kx 2023-04-11 01:18:34 +0300 3235)     /* finaly assume that /usr/sbin is a sbindir: */
11c606a6 (kx 2023-04-11 01:18:34 +0300 3236)     (void)sprintf( &tmp[0], "%s/../../usr/share/%s/.dialogrc", selfdir, PACKAGE_NAME );
11c606a6 (kx 2023-04-11 01:18:34 +0300 3237)   }
11c606a6 (kx 2023-04-11 01:18:34 +0300 3238) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 3239)   setenv( "DIALOGRC", (const char *)&tmp[0], 1 );
11c606a6 (kx 2023-04-11 01:18:34 +0300 3240) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 3241)   free( tmp );
11c606a6 (kx 2023-04-11 01:18:34 +0300 3242) }
11c606a6 (kx 2023-04-11 01:18:34 +0300 3243) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 3244) static char *get_curdir( void )
11c606a6 (kx 2023-04-11 01:18:34 +0300 3245) {
11c606a6 (kx 2023-04-11 01:18:34 +0300 3246)   char *cwd = NULL;
11c606a6 (kx 2023-04-11 01:18:34 +0300 3247) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 3248)   cwd = (char *)malloc( PATH_MAX );
11c606a6 (kx 2023-04-11 01:18:34 +0300 3249)   if( !cwd ) { FATAL_ERROR( "Cannot allocate memory" ); }
11c606a6 (kx 2023-04-11 01:18:34 +0300 3250)   bzero( (void *)cwd, PATH_MAX );
11c606a6 (kx 2023-04-11 01:18:34 +0300 3251) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 3252)   if( getcwd( cwd, (size_t)PATH_MAX ) != NULL )
11c606a6 (kx 2023-04-11 01:18:34 +0300 3253)   {
11c606a6 (kx 2023-04-11 01:18:34 +0300 3254)     char *p = NULL;
11c606a6 (kx 2023-04-11 01:18:34 +0300 3255)     remove_trailing_slash( cwd );
11c606a6 (kx 2023-04-11 01:18:34 +0300 3256)     p = xstrdup( (const char *)cwd );
11c606a6 (kx 2023-04-11 01:18:34 +0300 3257)     free( cwd );
11c606a6 (kx 2023-04-11 01:18:34 +0300 3258)     return p;
11c606a6 (kx 2023-04-11 01:18:34 +0300 3259)   }
11c606a6 (kx 2023-04-11 01:18:34 +0300 3260)   else
11c606a6 (kx 2023-04-11 01:18:34 +0300 3261)   {
11c606a6 (kx 2023-04-11 01:18:34 +0300 3262)     FATAL_ERROR( "Cannot get absolute path to current directory" );
11c606a6 (kx 2023-04-11 01:18:34 +0300 3263)   }
11c606a6 (kx 2023-04-11 01:18:34 +0300 3264) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 3265)   return (char *)NULL;
11c606a6 (kx 2023-04-11 01:18:34 +0300 3266) }
11c606a6 (kx 2023-04-11 01:18:34 +0300 3267) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 3268) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 3269) /*********************************************
11c606a6 (kx 2023-04-11 01:18:34 +0300 3270)   Get directory where this program is placed:
11c606a6 (kx 2023-04-11 01:18:34 +0300 3271)  */
11c606a6 (kx 2023-04-11 01:18:34 +0300 3272) char *get_selfdir( void )
11c606a6 (kx 2023-04-11 01:18:34 +0300 3273) {
11c606a6 (kx 2023-04-11 01:18:34 +0300 3274)   char    *buf = NULL;
11c606a6 (kx 2023-04-11 01:18:34 +0300 3275)   ssize_t  len;
11c606a6 (kx 2023-04-11 01:18:34 +0300 3276) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 3277)   buf = (char *)malloc( PATH_MAX );
11c606a6 (kx 2023-04-11 01:18:34 +0300 3278)   if( !buf )
11c606a6 (kx 2023-04-11 01:18:34 +0300 3279)   {
11c606a6 (kx 2023-04-11 01:18:34 +0300 3280)     FATAL_ERROR( "Cannot allocate memory" );
11c606a6 (kx 2023-04-11 01:18:34 +0300 3281)   }
11c606a6 (kx 2023-04-11 01:18:34 +0300 3282) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 3283)   bzero( (void *)buf, PATH_MAX );
11c606a6 (kx 2023-04-11 01:18:34 +0300 3284)   len = readlink( "/proc/self/exe", buf, (size_t)PATH_MAX );
11c606a6 (kx 2023-04-11 01:18:34 +0300 3285)   if( len > 0 && len < PATH_MAX )
11c606a6 (kx 2023-04-11 01:18:34 +0300 3286)   {
11c606a6 (kx 2023-04-11 01:18:34 +0300 3287)     char *p = xstrdup( (const char *)dirname( buf ) );
11c606a6 (kx 2023-04-11 01:18:34 +0300 3288)     free( buf );
11c606a6 (kx 2023-04-11 01:18:34 +0300 3289)     return p;
11c606a6 (kx 2023-04-11 01:18:34 +0300 3290)   }
11c606a6 (kx 2023-04-11 01:18:34 +0300 3291)   FATAL_ERROR( "Cannot determine self directory. Please mount /proc filesystem" );
11c606a6 (kx 2023-04-11 01:18:34 +0300 3292) }
11c606a6 (kx 2023-04-11 01:18:34 +0300 3293) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 3294) void set_stack_size( void )
11c606a6 (kx 2023-04-11 01:18:34 +0300 3295) {
11c606a6 (kx 2023-04-11 01:18:34 +0300 3296)   const rlim_t   stack_size = 16 * 1024 * 1024; /* min stack size = 16 MB */
11c606a6 (kx 2023-04-11 01:18:34 +0300 3297)   struct rlimit  rl;
11c606a6 (kx 2023-04-11 01:18:34 +0300 3298)   int ret;
11c606a6 (kx 2023-04-11 01:18:34 +0300 3299) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 3300)   ret = getrlimit( RLIMIT_STACK, &rl );
11c606a6 (kx 2023-04-11 01:18:34 +0300 3301)   if( ret == 0 )
11c606a6 (kx 2023-04-11 01:18:34 +0300 3302)   {
11c606a6 (kx 2023-04-11 01:18:34 +0300 3303)     if( rl.rlim_cur < stack_size )
11c606a6 (kx 2023-04-11 01:18:34 +0300 3304)     {
11c606a6 (kx 2023-04-11 01:18:34 +0300 3305)       rl.rlim_cur = stack_size;
11c606a6 (kx 2023-04-11 01:18:34 +0300 3306)       ret = setrlimit( RLIMIT_STACK, &rl );
11c606a6 (kx 2023-04-11 01:18:34 +0300 3307)       if( ret != 0 )
11c606a6 (kx 2023-04-11 01:18:34 +0300 3308)       {
11c606a6 (kx 2023-04-11 01:18:34 +0300 3309)         fprintf(stderr, "setrlimit returned result = %d\n", ret);
11c606a6 (kx 2023-04-11 01:18:34 +0300 3310)         FATAL_ERROR( "Cannot set stack size" );
11c606a6 (kx 2023-04-11 01:18:34 +0300 3311)       }
11c606a6 (kx 2023-04-11 01:18:34 +0300 3312)     }
11c606a6 (kx 2023-04-11 01:18:34 +0300 3313)   }
11c606a6 (kx 2023-04-11 01:18:34 +0300 3314) }
11c606a6 (kx 2023-04-11 01:18:34 +0300 3315) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 3316) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 3317) int main( int argc, char *argv[] )
11c606a6 (kx 2023-04-11 01:18:34 +0300 3318) {
11c606a6 (kx 2023-04-11 01:18:34 +0300 3319)   gid_t  gid;
11c606a6 (kx 2023-04-11 01:18:34 +0300 3320) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 3321)   set_signal_handlers();
11c606a6 (kx 2023-04-11 01:18:34 +0300 3322) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 3323)   gid = getgid();
11c606a6 (kx 2023-04-11 01:18:34 +0300 3324)   setgroups( 1, &gid );
11c606a6 (kx 2023-04-11 01:18:34 +0300 3325) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 3326)   fatal_error_hook = fatal_error_actions;
11c606a6 (kx 2023-04-11 01:18:34 +0300 3327) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 3328)   selfdir = get_selfdir();
11c606a6 (kx 2023-04-11 01:18:34 +0300 3329)   curdir  = get_curdir();
11c606a6 (kx 2023-04-11 01:18:34 +0300 3330)   dialogrc();
11c606a6 (kx 2023-04-11 01:18:34 +0300 3331) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 3332)   errlog = stderr;
11c606a6 (kx 2023-04-11 01:18:34 +0300 3333) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 3334)   program = basename( argv[0] );
11c606a6 (kx 2023-04-11 01:18:34 +0300 3335)   get_args( argc, argv );
11c606a6 (kx 2023-04-11 01:18:34 +0300 3336) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 3337)   /* set_stack_size(); */
11c606a6 (kx 2023-04-11 01:18:34 +0300 3338) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 3339)   tmpdir = _mk_tmpdir();
11c606a6 (kx 2023-04-11 01:18:34 +0300 3340)   if( !tmpdir )
11c606a6 (kx 2023-04-11 01:18:34 +0300 3341)   {
11c606a6 (kx 2023-04-11 01:18:34 +0300 3342)     FATAL_ERROR( "Cannot create temporary directory" );
11c606a6 (kx 2023-04-11 01:18:34 +0300 3343)   }
11c606a6 (kx 2023-04-11 01:18:34 +0300 3344) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 3345) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 3346)   {
11c606a6 (kx 2023-04-11 01:18:34 +0300 3347)     int status = 0;
11c606a6 (kx 2023-04-11 01:18:34 +0300 3348) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 3349)     /**********************************************************
11c606a6 (kx 2023-04-11 01:18:34 +0300 3350)       Fill pkginfo data and put or replace pkglog into tmpdir:
11c606a6 (kx 2023-04-11 01:18:34 +0300 3351)      */
11c606a6 (kx 2023-04-11 01:18:34 +0300 3352)     status = check_installed_package();
11c606a6 (kx 2023-04-11 01:18:34 +0300 3353) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 3354)     read_filelist( (void *)&rdirs, (void *)&rfiles, (const char *)rtmpdir );
11c606a6 (kx 2023-04-11 01:18:34 +0300 3355)     read_restorelinks( (void *)&rlinks, (const char *)rtmpdir );
11c606a6 (kx 2023-04-11 01:18:34 +0300 3356)     read_description( (const char *)rtmpdir, 0 );
11c606a6 (kx 2023-04-11 01:18:34 +0300 3357)     if( status == 0 )
11c606a6 (kx 2023-04-11 01:18:34 +0300 3358)     {
11c606a6 (kx 2023-04-11 01:18:34 +0300 3359)       int integrity = check_installed_pkg_integrity();
11c606a6 (kx 2023-04-11 01:18:34 +0300 3360)       if( integrity ) /* not depends on --always-ask option */
11c606a6 (kx 2023-04-11 01:18:34 +0300 3361)       {
11c606a6 (kx 2023-04-11 01:18:34 +0300 3362)         /* same version of requested package is already installed and correct: */
11c606a6 (kx 2023-04-11 01:18:34 +0300 3363)         if( ask_for_reinstall() )
11c606a6 (kx 2023-04-11 01:18:34 +0300 3364)         {
11c606a6 (kx 2023-04-11 01:18:34 +0300 3365)           /* Terminate update procedure with success return code: */
11c606a6 (kx 2023-04-11 01:18:34 +0300 3366)           if( tmpdir ) { _rm_tmpdir( (const char *)tmpdir ); free( tmpdir ); }
11c606a6 (kx 2023-04-11 01:18:34 +0300 3367)           free_resources();
11c606a6 (kx 2023-04-11 01:18:34 +0300 3368)           exit( exit_status );
11c606a6 (kx 2023-04-11 01:18:34 +0300 3369)         }
11c606a6 (kx 2023-04-11 01:18:34 +0300 3370)       }
11c606a6 (kx 2023-04-11 01:18:34 +0300 3371)     }
11c606a6 (kx 2023-04-11 01:18:34 +0300 3372)   }
11c606a6 (kx 2023-04-11 01:18:34 +0300 3373) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 3374)   /************************************************************
11c606a6 (kx 2023-04-11 01:18:34 +0300 3375)     Getting Service Files, reading pkginfo, preserving pkglog:
11c606a6 (kx 2023-04-11 01:18:34 +0300 3376)    */
11c606a6 (kx 2023-04-11 01:18:34 +0300 3377)   read_service_files();
11c606a6 (kx 2023-04-11 01:18:34 +0300 3378) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 3379)   if( rqck ) check_requires();
11c606a6 (kx 2023-04-11 01:18:34 +0300 3380) #if defined( HAVE_GPG2 )
11c606a6 (kx 2023-04-11 01:18:34 +0300 3381)   if( gpgck ) verify_gpg_signature();
11c606a6 (kx 2023-04-11 01:18:34 +0300 3382) #endif
11c606a6 (kx 2023-04-11 01:18:34 +0300 3383) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 3384)   read_filelist( (void *)&dirs, (void *)&files, (const char *)tmpdir );
11c606a6 (kx 2023-04-11 01:18:34 +0300 3385)   read_restorelinks( (void *)&links, (const char *)tmpdir );
11c606a6 (kx 2023-04-11 01:18:34 +0300 3386) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 3387)   read_description( (const char *)tmpdir, 1 );
11c606a6 (kx 2023-04-11 01:18:34 +0300 3388) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 3389)   if( ask_for_update() )
11c606a6 (kx 2023-04-11 01:18:34 +0300 3390)   {
11c606a6 (kx 2023-04-11 01:18:34 +0300 3391)     /* Terminate update: */
11c606a6 (kx 2023-04-11 01:18:34 +0300 3392)     if( tmpdir ) { _rm_tmpdir( (const char *)tmpdir ); free( tmpdir ); }
11c606a6 (kx 2023-04-11 01:18:34 +0300 3393)     free_resources();
11c606a6 (kx 2023-04-11 01:18:34 +0300 3394)     exit( exit_status );
11c606a6 (kx 2023-04-11 01:18:34 +0300 3395)   }
11c606a6 (kx 2023-04-11 01:18:34 +0300 3396) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 3397)   /************
11c606a6 (kx 2023-04-11 01:18:34 +0300 3398)     DO REMOVE:
11c606a6 (kx 2023-04-11 01:18:34 +0300 3399)    */
11c606a6 (kx 2023-04-11 01:18:34 +0300 3400)   remove_package();
11c606a6 (kx 2023-04-11 01:18:34 +0300 3401)   finalize_removal();
11c606a6 (kx 2023-04-11 01:18:34 +0300 3402) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 3403)   show_update_progress();
11c606a6 (kx 2023-04-11 01:18:34 +0300 3404) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 3405)   /************
11c606a6 (kx 2023-04-11 01:18:34 +0300 3406)     DO UPDATE:
11c606a6 (kx 2023-04-11 01:18:34 +0300 3407)    */
11c606a6 (kx 2023-04-11 01:18:34 +0300 3408)   pre_update_routine();
11c606a6 (kx 2023-04-11 01:18:34 +0300 3409)   uncompress_package();
11c606a6 (kx 2023-04-11 01:18:34 +0300 3410)   restore_links();
11c606a6 (kx 2023-04-11 01:18:34 +0300 3411)   post_update_routine();
11c606a6 (kx 2023-04-11 01:18:34 +0300 3412)   finalize_update();
11c606a6 (kx 2023-04-11 01:18:34 +0300 3413) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 3414)   fprintf( stdout, "\033[3A" ); /* move cursor up 3 lines */
11c606a6 (kx 2023-04-11 01:18:34 +0300 3415) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 3416)   if( (update_mode != CONSOLE) && (update_mode == MENUDIALOG) )
11c606a6 (kx 2023-04-11 01:18:34 +0300 3417)   {
11c606a6 (kx 2023-04-11 01:18:34 +0300 3418) #if defined( HAVE_DIALOG )
11c606a6 (kx 2023-04-11 01:18:34 +0300 3419)     info_pkg_box( "Update:", pkgname, pkgver, strprio( priority, 0 ),
11c606a6 (kx 2023-04-11 01:18:34 +0300 3420)                   "\nPackage has been updated.\n", 5, 0, 0 );
11c606a6 (kx 2023-04-11 01:18:34 +0300 3421) #else
11c606a6 (kx 2023-04-11 01:18:34 +0300 3422)     fprintf( stdout, "\nPackage '%s-%s' has been updated.\n\n", pkgname, pkgver );
11c606a6 (kx 2023-04-11 01:18:34 +0300 3423) #endif
11c606a6 (kx 2023-04-11 01:18:34 +0300 3424)   }
11c606a6 (kx 2023-04-11 01:18:34 +0300 3425)   else
11c606a6 (kx 2023-04-11 01:18:34 +0300 3426)   {
11c606a6 (kx 2023-04-11 01:18:34 +0300 3427)     if( (update_mode != INFODIALOG) )
11c606a6 (kx 2023-04-11 01:18:34 +0300 3428)     {
11c606a6 (kx 2023-04-11 01:18:34 +0300 3429)       fprintf( stdout, "\nPackage '%s-%s' has been updated.\n\n", pkgname, pkgver );
11c606a6 (kx 2023-04-11 01:18:34 +0300 3430)     }
11c606a6 (kx 2023-04-11 01:18:34 +0300 3431)   }
11c606a6 (kx 2023-04-11 01:18:34 +0300 3432) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 3433)   setup_log( "Package '%s-%s' has been updated", pkgname, pkgver );
11c606a6 (kx 2023-04-11 01:18:34 +0300 3434) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 3435)   if( tmpdir ) { _rm_tmpdir( (const char *)tmpdir ); free( tmpdir ); }
11c606a6 (kx 2023-04-11 01:18:34 +0300 3436)   free_resources();
11c606a6 (kx 2023-04-11 01:18:34 +0300 3437) 
11c606a6 (kx 2023-04-11 01:18:34 +0300 3438)   exit( exit_status );
11c606a6 (kx 2023-04-11 01:18:34 +0300 3439) }