static_ocserv.sh 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. #!/bin/bash -e
  2. cd /tmp
  3. #################
  4. #################
  5. ver_nettle=3.3
  6. ver_gnutls=3.5.8
  7. ver_libev=4.22
  8. ver_ocserv=0.12.3
  9. #################
  10. #################
  11. cores=$(grep -c '^processor' /proc/cpuinfo)
  12. instPrefix="/tmp/inst"
  13. export CC=/usr/bin/gcc
  14. export PKG_CONFIG_SYSROOT_DIR="$instPrefix"
  15. export PKG_CONFIG_LIBDIR="$instPrefix/lib/pkgconfig"
  16. #################
  17. #################
  18. rm -rf $instPrefix
  19. mkdir -p $instPrefix
  20. ln -s . $instPrefix/usr
  21. ln -s . $instPrefix/local
  22. #################
  23. #################
  24. # Nettle
  25. wget --no-check-certificate -4 -O nettle.tar.gz https://ftp.gnu.org/gnu/nettle/nettle-${ver_nettle}.tar.gz
  26. [ -d nettle ] && rm -rf nettle
  27. mkdir -p nettle; tar -xz -f nettle.tar.gz -C nettle --strip-components=1;
  28. cd nettle
  29. cat >>mini-gmp.c <<EOF
  30. void mpz_div_2exp(mpz_t quotient, mpz_t dividend, unsigned long int exponent_of_2)
  31. {
  32. mpz_tdiv_q_2exp(quotient, dividend, exponent_of_2);
  33. }
  34. void mpz_mod_2exp(mpz_t remainder, mpz_t dividend, unsigned long int exponent_of_2)
  35. {
  36. mpz_tdiv_r_2exp(remainder, dividend, exponent_of_2);
  37. }
  38. EOF
  39. CFLAGS="-I$instPrefix/include -ffloat-store -O0 --static" \
  40. LDFLAGS="-L$instPrefix/lib -static-libgcc -static-libstdc++" \
  41. ./configure \
  42. --enable-mini-gmp --enable-x86-aesni --enable-static \
  43. --disable-{documentation,shared,rpath}
  44. #sed -i 's/cnd-copy\.c /&cnd-memcpy.c /' Makefile
  45. make -j$cores
  46. [ $? -eq 0 ] || exit 1
  47. make DESTDIR=$instPrefix install
  48. cd ..
  49. # GnuTLS
  50. wget --no-check-certificate -4 -O gnutls.tar.xz ftp://ftp.gnutls.org/gcrypt/gnutls/v${ver_gnutls%.*}/gnutls-${ver_gnutls}.tar.xz
  51. [ -d gnutls ] && rm -rf gnutls
  52. mkdir -p gnutls; tar -xJ -f gnutls.tar.xz -C gnutls --strip-components=1;
  53. cd gnutls
  54. sed -i '/gmp\.h/d' lib/nettle/int/dsa-fips.h
  55. CFLAGS="-I$instPrefix/include -ffloat-store -O0 --static" \
  56. LDFLAGS="-L$instPrefix/lib -static-libgcc -static-libstdc++" \
  57. ./configure \
  58. --with-nettle-mini --with-included-{libtasn1,unistring} \
  59. --without-p11-kit --enable-static \
  60. --disable-{doc,tools,cxx,tests,nls,guile,rpath,shared}
  61. make -j$cores
  62. [ $? -eq 0 ] || exit 1
  63. make DESTDIR=$instPrefix install
  64. cd ..
  65. # libev
  66. wget --no-check-certificate -4 -O libev.tar.gz http://dist.schmorp.de/libev/Attic/libev-${ver_libev}.tar.gz
  67. [ -d libev ] && rm -rf libev
  68. mkdir -p libev; tar -xz -f libev.tar.gz -C libev --strip-components=1;
  69. cd libev
  70. CFLAGS="-I$instPrefix/include -ffloat-store -O0 --static" \
  71. LDFLAGS="-L$instPrefix/lib -static-libgcc -static-libstdc++" \
  72. ./configure \
  73. --enable-static \
  74. --disable-{shared,rpath}
  75. make -j$cores
  76. [ $? -eq 0 ] || exit 1
  77. make DESTDIR=$instPrefix install
  78. cd ..
  79. # readline.h
  80. cat >$instPrefix/include/readline.h <<EOF
  81. #ifndef READLINE_H
  82. #define READLINE_H
  83. typedef char *rl_compentry_func_t(const char*, int);
  84. typedef char **rl_completion_func_t(const char*, int, int);
  85. extern char *rl_line_buffer;
  86. extern char *rl_readline_name;
  87. extern rl_completion_func_t *rl_attempted_completion_function;
  88. extern rl_compentry_func_t *rl_completion_entry_function;
  89. extern int rl_completion_query_items;
  90. char *readline(const char *prompt);
  91. void add_history(const char *string);
  92. int rl_reset_terminal(const char *terminal_name);
  93. char **rl_completion_matches(const char *text, void *entry_func);
  94. void rl_redisplay(void);
  95. #endif
  96. EOF
  97. # readline.c
  98. $CC -xc - -c -o readline.o -ffloat-store -O0 <<EOF
  99. #include <stdio.h>
  100. #include <string.h>
  101. char *rl_line_buffer = NULL;
  102. char *rl_readline_name;
  103. void *rl_attempted_completion_function;
  104. void *rl_completion_entry_function;
  105. int rl_completion_query_items;
  106. char *readline(const char *prompt) {
  107. char buf[512], *ptr;
  108. if(prompt) printf("%s", prompt);
  109. fflush(stdout); ptr = buf;
  110. while((*ptr = getchar()) != '\n') ptr++;
  111. *ptr = '\0';
  112. return strdup(buf);
  113. }
  114. void add_history(const char *string) {}
  115. int rl_reset_terminal(const char *terminal_name) {return 0;}
  116. char **rl_completion_matches(const char *text, void *entry_func) {return NULL;}
  117. void rl_redisplay(void) {}
  118. EOF
  119. # readline.a
  120. ar rcs $instPrefix/lib/libreadline.a readline.o
  121. rm -rf readline.o
  122. # OpenConnect server
  123. rm -rf $HOME/ocserv-bin
  124. mkdir -p $HOME/ocserv-bin
  125. wget --no-check-certificate -4 -O ocserv.tar.xz ftp://ftp.infradead.org/pub/ocserv/ocserv-${ver_ocserv}.tar.xz
  126. [ -d ocserv ] && rm -rf ocserv
  127. mkdir -p ocserv; tar -xJ -f ocserv.tar.xz -C ocserv --strip-components=1;
  128. cd ocserv
  129. #autoreconf -fvi
  130. sed -i 's/#define DEFAULT_CONFIG_ENTRIES 96/#define DEFAULT_CONFIG_ENTRIES 200/' src/vpn.h
  131. sed -i 's/\$LIBS \$LIBEV/\$LIBEV \$LIBS/g' configure
  132. CFLAGS="-I$instPrefix/include -ffloat-store -O0 --static" \
  133. LDFLAGS="-L$instPrefix/lib -static -static-libgcc -static-libstdc++ -s -pthread -lpthread" \
  134. LIBNETTLE_LIBS="-lnettle -lhogweed" LIBREADLINE_LIBS="-lreadline" \
  135. LIBS="-lm" \
  136. ./configure --prefix=/usr \
  137. --disable-rpath \
  138. --with-local-talloc \
  139. --without-{root-tests,docker-tests,nuttcp-tests} \
  140. --without-{protobuf,maxmind,geoip,liboath,pam,radius,utmp,lz4,http-parser,gssapi,pcl-lib}
  141. make -j$cores
  142. [ $? -eq 0 ] || exit 1
  143. make DESTDIR=$HOME/ocserv-bin install
  144. cd ..
  145. # cd $HOME/ocserv-bin
  146. # tar -cvf "../ocserv_v0.12.3.tar" ./
  147. # tar --overwrite -xvf ocserv_v0.12.3.tar -C /