1#!/bin/sh 2 3## $Id: getrra-c-util 10483 2021-01-04 07:12:27Z iulius $ 4## 5## Synchronize INN files maintained in rra-c-util with upstream. 6## 7## This script downloads the latest version of the files maintained 8## in the rra-c-util package that INN uses for most of its utility and 9## portability functions. These files are available at 10## <https://www.eyrie.org/~eagle/software/rra-c-util/>. 11## 12## Running this script permits keeping up-to-date most of INN utility and 13## portability functions by automatically fetching the latest version of 14## the upstream files, and putting them in the expected location in the 15## INN source code. 16## The name of the files that have been modified since the last run of the 17## script are written to standard output. Have a look at the changes and, 18## if all looks right, commit the changes. 19 20## URL where the files can be downloaded. 21URL_START="https://git.eyrie.org/?p=devel/rra-c-util.git;a=blob_plain;hb=HEAD;f=" 22 23## This function downloads the files and copies them to the expected 24## location in the INN source code, after having performed a few minimal 25## changes to integrate them in the INN build system. 26## If a file is not found in upstream or has been modified since the last 27## run of the script, write it on standard output. 28## 29## This function expects the following arguments: 30## $1 - full path of the file to download in the upstream package 31## $2 - directory where the file should be copied in INN source code 32## $3 - name of the file in INN source code 33download () 34{ 35 TEMP=$3.tmp 36 37 rm -f ${TEMP} 38 wget -q "${URL_START}$1" -O ${TEMP} 39 40 if [ ! -s "${TEMP}" ] 41 then 42 echo "File $1 does not exist in upstream package" 43 else 44 # Add the SVN Id keyword at the beginning of source code files, 45 # and update the path of included C header files. 46 # Change "RRA_" to "INN_", "rra_" to "inn_", and "UTIL_" to "INN_" 47 # so as to keep a homogeneous naming convention in INN source code. 48 # Changes in shell, m4 and C files are not the same. 49 if [ "$2" = "m4" ] 50 then 51 sed -i -e 's/RRA_/INN_/g' \ 52 -e 's/rra_/inn_/g' \ 53 -e '1 a\ 54dnl \$Id\$' \ 55 ${TEMP} 56 57 # Remove useless function for INN. 58 if [ "$3" = "cc-flags.m4" ] 59 then 60 sed -i -e '/dnl Provides INN_PROG_CC_WARNINGS_FLAGS/,+6d' \ 61 -e '/dnl Determine the full set/,$d' \ 62 ${TEMP} 63 fi 64 elif [ "$2" = "include/inn" ] || [ "$2" = "include/portable" ] \ 65 || [ "$2" = "include" ] || [ "$2" = "lib" ] || [ "$2" = "tests/lib" ] \ 66 || [ "$2" = "tests/lib/network" ] || [ "$2" = "tests/tap" ] 67 then 68 if [ "$3" = "xmalloc.t" ] 69 then 70 # Path should be updated in this shell script. 71 sed -i -e "3 i \\ 72# \$Id\$\\ 73#" \ 74 -e 's/\$C_TAP_BUILD\/util/\$C_TAP_BUILD\/lib/g' \ 75 ${TEMP} 76 chmod 755 ${TEMP} 77 else 78 if [ "$3" = "network.c" ] 79 then 80 # Apply specific changes to take into account how sourceaddress 81 # and sourceaddress6 work. 82 sed -i -e "61 i \\ 83#include \"inn/innconf.h\"" \ 84 -e '455 s/)$/ \&\& innconf == NULL)/' \ 85 -e '456,457d' \ 86 -e "462 i \\ 87 if (source == NULL && innconf != NULL)\\ 88 source = innconf->sourceaddress;\\ 89 if (source == NULL ||\\ 90 strcmp(source, \"all\") == 0 || strcmp(source, \"any\") == 0)\\ 91 return true;\\ 92" \ 93 -e "475 i \\ 94 if (source == NULL && innconf != NULL)\\ 95 source = innconf->sourceaddress6;\\ 96 if (source == NULL ||\\ 97 strcmp(source, \"all\") == 0 || strcmp(source, \"any\") == 0)\\ 98 return true;\\ 99" \ 100 ${TEMP} 101 fi 102 103 if [ "$3" = "clibrary.h" ] 104 then 105 # Add INN-specific stuff. 106 sed -i -e 's/<portable\/macros\.h>/"inn\/macros.h"/g' \ 107 -e 's/PORTABLE_SYSTEM_H/CLIBRARY_H/g' \ 108 -e "8 i \\ 109 * #include \"inn/macros.h\"" \ 110 -e "108 i \\ 111/*\\ 112 * This almost certainly isn't necessary, but it's not hurting anything.\\ 113 * gcc assumes that if SEEK_SET isn't defined none of the rest are either,\\ 114 * so we certainly can as well.\\ 115 */\\ 116#ifndef SEEK_SET\\ 117# define SEEK_SET 0\\ 118# define SEEK_CUR 1\\ 119# define SEEK_END 2\\ 120#endif\\ 121" \ 122 -e "135 i \\ 123/*\\ 124 * Handle defining fseeko and ftello. If HAVE_FSEEKO is defined, the system\\ 125 * header files take care of this for us. Otherwise, see if we're building\\ 126 * with large file support. If we are, we have to provide some real fseeko\\ 127 * and ftello implementation; declare them if they're not already declared and\\ 128 * we'll use replacement versions in libinn. If we're not using large files,\\ 129 * we can safely just use fseek and ftell.\\ 130 *\\ 131 * We'd rather use fseeko and ftello unconditionally, even when we're not\\ 132 * building with large file support, since they're a better interface.\\ 133 * Unfortunately, they're available but not declared on some systems unless\\ 134 * building with large file support, the AC_FUNC_FSEEKO Autoconf function\\ 135 * always turns on large file support, and our fake declarations won't work on\\ 136 * some systems (like HP_UX). This is the best compromise we've been able to\\ 137 * come up with.\\ 138 */\\ 139#if !HAVE_FSEEKO\\ 140# if DO_LARGEFILES\\ 141# if !HAVE_DECL_FSEEKO\\ 142extern int fseeko(FILE *, off_t, int);\\ 143# endif\\ 144# if !HAVE_DECL_FTELLO\\ 145extern off_t ftello(FILE *);\\ 146# endif\\ 147# else\\ 148# define fseeko(f, o, w) fseek((f), (long)(o), (w))\\ 149# define ftello(f) ftell(f)\\ 150# endif\\ 151#endif\\ 152\\ 153/* Other prototypes. */\\ 154#if !HAVE_DECL_PREAD\\ 155extern ssize_t pread(int, void *, size_t, off_t);\\ 156#endif\\ 157#if !HAVE_DECL_PWRITE\\ 158extern ssize_t pwrite(int, const void *, size_t, off_t);\\ 159#endif\\ 160#if !HAVE_SYMLINK\\ 161extern int symlink(const char *, const char *);\\ 162#endif\\ 163" \ 164 -e "147 i \\ 165#if !HAVE_DECL_SNPRINTF\\ 166extern int snprintf(char *, size_t, const char *, ...)\\ 167 __attribute__((__format__(printf, 3, 4)));\\ 168#endif\\ 169#if !HAVE_DECL_VSNPRINTF\\ 170extern int vsnprintf(char *, size_t, const char *, va_list)\\ 171 __attribute__((__format__(printf, 3, 0)));\\ 172#endif" \ 173 -e "164 i \\ 174#if !HAVE_DECL_STRLCAT\\ 175extern size_t strlcat(char *, const char *, size_t);\\ 176#endif\\ 177#if !HAVE_DECL_STRLCPY\\ 178extern size_t strlcpy(char *, const char *, size_t);\\ 179#endif\\ 180#if !HAVE_GETPAGESIZE\\ 181extern int getpagesize(void);\\ 182#endif\\ 183#if !HAVE_STRCASECMP\\ 184extern int strcasecmp(const char *, const char *);\\ 185extern int strncasecmp(const char *, const char *, size_t);\\ 186#endif\\ 187#if !HAVE_STRSPN\\ 188extern size_t strspn(const char *, const char *);\\ 189#endif\\ 190#if !HAVE_STRTOK\\ 191extern char * strtok(char *, const char *);\\ 192#endif" \ 193 -e '/#if !HAVE_DAEMON/,+2d' \ 194 -e '/#if !HAVE_ISSETUGID/,+2d' \ 195 -e '/#if !HAVE_STRNDUP/,+2d' \ 196 ${TEMP} 197 fi 198 199 sed -i -e 's/UTIL_/INN_/g' \ 200 -e '/^\/\* Default to a hidden visibility for all .* functions\. \*\/$/,+2d' \ 201 -e '/^\/\* Undo default visibility change\. \*\/$/,+2d' \ 202 -e 's/<config\.h>$/"config.h"/g' \ 203 -e 's/<portable\/system\.h>/"clibrary.h"/g' \ 204 -e 's/<util\/\(.*\)>/"inn\/\1"/g' \ 205 -e 's/<portable\/\(.*\)>/"portable\/\1"/g' \ 206 -e 's/<tests\/tap\/\(.*\)>/"tap\/\1"/g' \ 207 -e 's/<tests\/util\/\(.*\)>/"lib\/\1"/g' \ 208 -e '1 s/$/ \$Id\$\n */' \ 209 ${TEMP} 210 211 # For compatibility with the integration of C TAP Harness in INN. 212 if [ "$2" = "tests/lib" ] || [ "$2" = "tests/lib/network" ] \ 213 || [ "$3" = "process.c" ] 214 then 215 sed -i -e "0,/^$/{s/^$/\n#define LIBTEST_NEW_FORMAT 1\n/}" \ 216 ${TEMP} 217 fi 218 219 # Rename a few symbols defined by autoconf since they're too likely 220 # to conflict with other packages. 221 # Please see support/mksystem for more information. 222 if [ "$2" = "include/inn" ] 223 then 224 sed -i -e 's/\([^_]\)HAVE_C99_VAMACROS/\1INN_HAVE_C99_VAMACROS/g' \ 225 -e 's/\([^_]\)HAVE_GNU_VAMACROS/\1INN_HAVE_GNU_VAMACROS/g' \ 226 -e 's/\([^_]\)HAVE_INET6/\1INN_HAVE_INET6/g' \ 227 -e 's/\([^_]\)HAVE_INTTYPES_H/\1INN_HAVE_INTTYPES_H/g' \ 228 -e 's/\([^_]\)HAVE_MSYNC_3_ARG/\1INN_HAVE_MSYNC_3_ARG/g' \ 229 -e 's/\([^_]\)HAVE_STDBOOL_H/\1INN_HAVE_STDBOOL_H/g' \ 230 -e 's/\([^_]\)HAVE_SYS_BITYPES_H/\1INN_HAVE_SYS_BITYPES_H/g' \ 231 -e 's/\([^_]\)HAVE__BOOL/\1INN_HAVE__BOOL/g' \ 232 -e 's/"portable\/\(.*\)"/"inn\/portable-\1"/g' \ 233 -e 's/"config\.h"/<inn\/defines.h>/g' \ 234 ${TEMP} 235 fi 236 fi 237 fi 238 239 mv -f ${TEMP} ../$2/$3 240 svn status ../$2/$3 241 fi 242} 243 244## Synchronize Autoconf macros from upstream. 245download m4/bdb.m4 m4 bdb.m4 246download m4/cc-flags.m4 m4 cc-flags.m4 247download m4/inet-ntoa.m4 m4 inet-ntoa.m4 248download m4/krb5-config.m4 m4 krb5-config.m4 249download m4/krb5.m4 m4 krb5.m4 250download m4/lib-depends.m4 m4 lib-depends.m4 251download m4/lib-helper.m4 m4 lib-helper.m4 252download m4/lib-pathname.m4 m4 lib-pathname.m4 253download m4/openssl.m4 m4 openssl.m4 254download m4/pam-const.m4 m4 pam-const.m4 255download m4/perl.m4 m4 perl.m4 256download m4/python.m4 m4 python.m4 257download m4/sasl.m4 m4 sasl.m4 258download m4/socket-unix.m4 m4 socket-unix.m4 259download m4/socket.m4 m4 socket.m4 260download m4/systemd.m4 m4 systemd.m4 261download m4/vamacros.m4 m4 vamacros.m4 262download m4/zlib.m4 m4 zlib.m4 263 264## Synchronize portability functions from upstream. 265download portable/asprintf.c lib asprintf.c 266download portable/getaddrinfo.c lib getaddrinfo.c 267download portable/getaddrinfo.h include/portable getaddrinfo.h 268download portable/getnameinfo.c lib getnameinfo.c 269download portable/getnameinfo.h include/portable getnameinfo.h 270download portable/inet_aton.c lib inet_aton.c 271download portable/inet_ntoa.c lib inet_ntoa.c 272download portable/inet_ntop.c lib inet_ntop.c 273download portable/macros.h include/portable macros.h 274download portable/mkstemp.c lib mkstemp.c 275download portable/reallocarray.c lib reallocarray.c 276download portable/sd-daemon.h include/portable sd-daemon.h 277download portable/setenv.c lib setenv.c 278download portable/seteuid.c lib seteuid.c 279download portable/socket.h include/portable socket.h 280download portable/socket-unix.h include/portable socket-unix.h 281download portable/stdbool.h include/portable stdbool.h 282download portable/system.h include clibrary.h 283download portable/uio.h include/portable uio.h 284 285## Synchronize utility functions from upstream. 286download util/buffer.c lib buffer.c 287download util/buffer.h include/inn buffer.h 288download util/fdflag.c lib fdflag.c 289download util/fdflag.h include/inn fdflag.h 290download util/macros.h include/inn macros.h 291download util/messages.c lib messages.c 292download util/messages.h include/inn messages.h 293download util/network.c lib network.c 294download util/network.h include/inn network.h 295download util/vector.c lib vector.c 296download util/vector.h include/inn vector.h 297download util/xmalloc.c lib xmalloc.c 298download util/xmalloc.h include/inn xmalloc.h 299download util/xwrite.c lib xwrite.c 300download util/xwrite.h include/inn xwrite.h 301 302## Synchronize test suite files for portability functions from upstream. 303download tests/portable/asprintf-t.c tests/lib asprintf-t.c 304download tests/portable/getaddrinfo-t.c tests/lib getaddrinfo-t.c 305download tests/portable/getnameinfo-t.c tests/lib getnameinfo-t.c 306download tests/portable/inet_aton-t.c tests/lib inet_aton-t.c 307download tests/portable/inet_ntoa-t.c tests/lib inet_ntoa-t.c 308download tests/portable/inet_ntop-t.c tests/lib inet_ntop-t.c 309download tests/portable/mkstemp-t.c tests/lib mkstemp-t.c 310download tests/portable/reallocarray-t.c tests/lib reallocarray-t.c 311download tests/portable/setenv-t.c tests/lib setenv-t.c 312 313## Synchronize test suite files for utility functions from upstream. 314download tests/util/buffer-t.c tests/lib buffer-t.c 315download tests/util/fakewrite.c tests/lib fakewrite.c 316download tests/util/fakewrite.h tests/lib fakewrite.h 317download tests/util/fdflag-t.c tests/lib fdflag-t.c 318download tests/util/messages-t.c tests/lib messages-t.c 319download tests/util/vector-t.c tests/lib vector-t.c 320download tests/util/xmalloc-t tests/lib xmalloc.t 321download tests/util/xmalloc.c tests/lib xmalloc.c 322download tests/util/xwrite-t.c tests/lib xwrite-t.c 323download tests/util/network/addr-ipv4-t.c tests/lib/network addr-ipv4-t.c 324download tests/util/network/addr-ipv6-t.c tests/lib/network addr-ipv6-t.c 325download tests/util/network/client-t.c tests/lib/network client-t.c 326download tests/util/network/server-t.c tests/lib/network server-t.c 327 328## Synchronize useful utility functions used for the test suite from upstream. 329download tests/tap/messages.c tests/tap messages.c 330download tests/tap/messages.h tests/tap messages.h 331download tests/tap/process.c tests/tap process.c 332download tests/tap/process.h tests/tap process.h 333download tests/tap/string.c tests/tap string.c 334download tests/tap/string.h tests/tap string.h 335