static_ocserv.sh 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. #!/bin/bash -e
  2. # Build static ocserv
  3. # by MoeClub
  4. # apt install -y gcc bison gawk make autoconf pkg-config xz-utils python3-pip
  5. #################
  6. #################
  7. ver_glibc=2.31
  8. ver_libev=4.33
  9. ver_nettle=3.7.3
  10. ver_gnutls=3.6.16
  11. ver_ocserv=1.1.6
  12. #################
  13. #################
  14. cd /tmp
  15. cores=$(grep -c '^processor' /proc/cpuinfo)
  16. installPrefix="/tmp/build"
  17. export CC=/usr/bin/gcc
  18. export PKG_CONFIG_SYSROOT_DIR="$installPrefix"
  19. export PKG_CONFIG_LIBDIR="$installPrefix/lib/pkgconfig:$installPrefix/lib64/pkgconfig"
  20. #################
  21. #################
  22. rm -rf $installPrefix
  23. mkdir -p $installPrefix
  24. ln -s . $installPrefix/usr
  25. ln -s . $installPrefix/local
  26. #################
  27. #################
  28. # glibc
  29. wget --no-check-certificate -4 -O glibc.tar.gz https://ftp.gnu.org/pub/gnu/glibc/glibc-${ver_glibc}.tar.gz
  30. [ -d glibc ] && rm -rf glibc
  31. mkdir -p glibc; tar -xz -f glibc.tar.gz -C glibc --strip-components=1;
  32. mkdir -p glibc/build; cd glibc/build
  33. CFLAGS="-I$installPrefix/include -ffloat-store -O2 --static" \
  34. LDFLAGS="-L$installPrefix/lib -L$installPrefix/lib64 -static -static-libgcc -static-libstdc++ -s -pthread -lpthread" \
  35. ../configure \
  36. --prefix=$installPrefix \
  37. --enable-static --enable-static-nss \
  38. --disable-nscd --disable-sanity-checks
  39. [ $? -eq 0 ] || exit 1
  40. make -j$cores
  41. [ $? -eq 0 ] || exit 1
  42. make install
  43. find "$installPrefix/lib" ! -type d ! -name "*.a" -delete
  44. cd ..
  45. # libev
  46. wget --no-check-certificate -4 -O libev.tar.gz http://dist.schmorp.de/libev/Attic/libev-${ver_libev}.tar.gz
  47. [ -d libev ] && rm -rf libev
  48. mkdir -p libev; tar -xz -f libev.tar.gz -C libev --strip-components=1;
  49. cd libev
  50. CFLAGS="-I$installPrefix/include -ffloat-store -O0 --static" \
  51. LDFLAGS="-L$installPrefix/lib -L$installPrefix/lib64 -static -static-libgcc -static-libstdc++ -s -pthread -lpthread" \
  52. ./configure \
  53. --enable-static \
  54. --disable-shared
  55. [ $? -eq 0 ] || exit 1
  56. make -j$cores
  57. [ $? -eq 0 ] || exit 1
  58. make DESTDIR=$installPrefix install
  59. cd ..
  60. # Nettle
  61. wget --no-check-certificate -4 -O nettle.tar.gz https://ftp.gnu.org/gnu/nettle/nettle-${ver_nettle}.tar.gz
  62. [ -d nettle ] && rm -rf nettle
  63. mkdir -p nettle; tar -xz -f nettle.tar.gz -C nettle --strip-components=1;
  64. cd nettle
  65. CFLAGS="-I$installPrefix/include -ffloat-store -O0 --static" \
  66. LDFLAGS="-L$installPrefix/lib -L$installPrefix/lib64 -static -static-libgcc -static-libstdc++ -s -pthread -lpthread" \
  67. ./configure \
  68. --enable-mini-gmp --enable-x86-aesni --enable-arm-neon --enable-static \
  69. --disable-{documentation,shared,rpath}
  70. [ -f ./cnd-memcpy.c ] && sed -i 's/cnd-copy\.c /&cnd-memcpy.c /' Makefile
  71. [ -f ./shake256.c ] && sed -i 's/cnd-copy\.c /&shake256.c /' Makefile
  72. [ $? -eq 0 ] || exit 1
  73. make -j$cores
  74. [ $? -eq 0 ] || exit 1
  75. make DESTDIR=$installPrefix install
  76. cd ..
  77. # GnuTLS
  78. wget --no-check-certificate -4 -O gnutls.tar.xz https://www.gnupg.org/ftp/gcrypt/gnutls/v${ver_gnutls%.*}/gnutls-${ver_gnutls}.tar.xz
  79. [ -d gnutls ] && rm -rf gnutls
  80. mkdir -p gnutls; tar -xJ -f gnutls.tar.xz -C gnutls --strip-components=1;
  81. cd gnutls
  82. CFLAGS="-I$installPrefix/include -ffloat-store -O0 --static" \
  83. LDFLAGS="-L$installPrefix/lib -L$installPrefix/lib64 -static -static-libgcc -static-libstdc++ -s -pthread -lpthread" \
  84. ./configure \
  85. --with-nettle-mini --with-included-{libtasn1,unistring} \
  86. --without-p11-kit --enable-static --enable-openssl-compatibility \
  87. --disable-{doc,tools,cxx,tests,nls,guile,rpath,shared}
  88. [ $? -eq 0 ] || exit 1
  89. make -j$cores
  90. [ $? -eq 0 ] || exit 1
  91. make DESTDIR=$installPrefix install
  92. cd ..
  93. # readline.h
  94. cat >$installPrefix/include/readline.h <<EOF
  95. #ifndef READLINE_H
  96. #define READLINE_H
  97. typedef char *rl_compentry_func_t(const char*, int);
  98. typedef char **rl_completion_func_t(const char*, int, int);
  99. extern char *rl_line_buffer;
  100. extern char *rl_readline_name;
  101. extern rl_completion_func_t *rl_attempted_completion_function;
  102. extern rl_compentry_func_t *rl_completion_entry_function;
  103. extern int rl_completion_query_items;
  104. char *readline(const char *prompt);
  105. void add_history(const char *string);
  106. int rl_reset_terminal(const char *terminal_name);
  107. char **rl_completion_matches(const char *text, void *entry_func);
  108. void rl_redisplay(void);
  109. #endif
  110. EOF
  111. # readline.c
  112. $CC -xc - -c -o readline.o -ffloat-store -O0 <<EOF
  113. #include <stdio.h>
  114. #include <string.h>
  115. char *rl_line_buffer = NULL;
  116. char *rl_readline_name;
  117. void *rl_attempted_completion_function;
  118. void *rl_completion_entry_function;
  119. int rl_completion_query_items;
  120. char *readline(const char *prompt) {
  121. char buf[512], *ptr;
  122. if(prompt) printf("%s", prompt);
  123. fflush(stdout); ptr = buf;
  124. while((*ptr = getchar()) != '\n') ptr++;
  125. *ptr = '\0';
  126. return strdup(buf);
  127. }
  128. void add_history(const char *string) {}
  129. int rl_reset_terminal(const char *terminal_name) {return 0;}
  130. char **rl_completion_matches(const char *text, void *entry_func) {return NULL;}
  131. void rl_redisplay(void) {}
  132. EOF
  133. # readline.a
  134. ar rcs $installPrefix/lib/libreadline.a readline.o
  135. rm -rf readline.o
  136. # OpenConnect Server
  137. rm -rf $HOME/ocserv-build
  138. mkdir -p $HOME/ocserv-build
  139. wget --no-check-certificate -4 -O ocserv.tar.xz ftp://ftp.infradead.org/pub/ocserv/ocserv-${ver_ocserv}.tar.xz
  140. [ -d ocserv ] && rm -rf ocserv
  141. mkdir -p ocserv; tar -xJ -f ocserv.tar.xz -C ocserv --strip-components=1;
  142. cd ocserv
  143. #autoreconf -fvi
  144. sed -i 's/#define DEFAULT_CONFIG_ENTRIES 96/#define DEFAULT_CONFIG_ENTRIES 200/' src/vpn.h
  145. sed -i 's/login_end = OC_LOGIN_END;/&\n\t\tif (ws->req.user_agent_type == AGENT_UNKNOWN) {\n\t\t\tcstp_cork(ws);\n\t\t\tret = (cstp_printf(ws, "HTTP\/1.%u 200 OK\\r\\nContent-Type: text\/plain\\r\\nContent-Length: 0\\r\\n\\r\\n", http_ver) < 0 || cstp_uncork(ws) < 0);\n\t\t\tstr_clear(\&str);\n\t\t\treturn -1;\n\t\t}/' src/worker-auth.c
  146. #sed -i 's/case AC_PKT_DPD_OUT:/&\n\t\tws->last_nc_msg = now;/' src/worker-vpn.c
  147. #sed -i 's/\$LIBS \$LIBEV/\$LIBEV \$LIBS/g' configure
  148. CFLAGS="-I$installPrefix/include -ffloat-store -O0 --static" \
  149. LDFLAGS="-L$installPrefix/lib -L$installPrefix/lib64 -static -static-libgcc -static-libstdc++ -s -pthread -lpthread" \
  150. LIBS="-lev -lm -lnettle -lhogweed -lreadline" \
  151. ./configure --prefix=/usr \
  152. --disable-rpath \
  153. --with-local-talloc \
  154. --without-{root-tests,docker-tests,nuttcp-tests} \
  155. --without-{protobuf,maxmind,geoip,liboath,pam,radius,utmp,lz4,http-parser,gssapi,pcl-lib}
  156. [ $? -eq 0 ] || exit 1
  157. make -j$cores
  158. [ $? -eq 0 ] || exit 1
  159. make DESTDIR=$HOME/ocserv-build install
  160. cd ..
  161. # Package
  162. cd $HOME/ocserv-build
  163. for item in `find . -type f`; do strip -s "$item" 2>/dev/null; done
  164. case `uname -m` in aarch64|arm64) arch="arm64";; x86_64|amd64) arch="amd64";; *) arch="unknown";; esac
  165. tar -cvf "../ocserv_${arch}_v${ver_ocserv}.tar" ./
  166. # tar --overwrite -xvf "ocserv_${arch}_v${ver_ocserv}.tar" -C /