Advertisement
wkitty42

synchronet bbs update script on linux

Oct 21st, 2019
306
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 11.94 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. # updatesbbs - a update script for a Synchronet BBS installation
  4. # on linux.
  5. #
  6. # author: mark lewis (aka wkitty42 and waldo kitty)
  7. # BBS: The SouthEast Star (sestar)
  8. # BBS domain: sestar.synchro.net
  9. #
  10. # this script is targeted at debian-based linux distributions.
  11. # it does all that is needed to update the sbbs source code and
  12. # build it on an existing installation. all you need to do is
  13. # place the script in the existing sbbs base directory, make it
  14. # executable, and then run it. when it completes you should be
  15. # able to go into sbbs/ctrl and run scfg to double check your
  16. # configuration settings for execution on your system.
  17. #
  18. # this script will create a log file of the same name as this
  19. # script plus the date and time.
  20. # eg: updatesbbs_201810251345.log
  21.  
  22. # first set the variables
  23. # set this to the base directory of your sbbs; this directory
  24. # generally contains everything, even the src directory
  25. SBBSDIR=$HOME/bbs
  26.  
  27. # if your src directory is in a different place, set it here
  28. SOURCEDIR="$SBBSDIR/src"
  29. SRCDIRMACRO="SRCDIR=$SOURCEDIR"
  30.  
  31. # this is where local patches are kept; you may or may not have
  32. # any that you wish to apply; if you do not have any patches to
  33. # apply, leave this set to "false" otherwise, set it to "true"
  34. APPLYPATCHES="false"
  35. PATCHDIR=$SBBSDIR/patches
  36. # this is a space delimited list of local patches you want to
  37. # apply to your build; they are stored in the above PATCHDIR
  38. # and have the extension ".patch"; only list their name here
  39. LOCALPATCHES="logon-readyourmailnowq-noyes"
  40.  
  41. # the user and group that your sbbs will execute as
  42. SUSER="SBBSUSER=sbbs"
  43. SGRP="SBBSGROUP=sbbs"
  44.  
  45. # use INSTALL=CLASSIC to copy the binaries OR
  46. # use INSTALL=SYMLINK for symlinks to the binaries
  47. INSTALLOPT="INSTALL=CLASSIC"
  48.  
  49. # this is where your sbbs is installed to; generally it is in
  50. # the same directory as where all your sbbs files are located
  51. INSTALLDIR="$SBBSDIR"
  52. INSTDIRMACRO="SBBSDIR=$INSTALLDIR"
  53.  
  54. # leave these here and alone; they are used in the BUILDOPTS
  55. # lines selected below
  56. DOSEMUOPT="USE_DOSEMU=1"
  57. DEBUGOPT="DEBUG=1"
  58. RELEASEOPT="RELEASE=1"
  59.  
  60. # choose one of the following four lines based on if you want
  61. # a DEBUG or a RELEASE build and whether you want DOSEMU or not.
  62. # make sure you select the same BUILDOPTS line in the installsbbs
  63. # script available from the same author.
  64. #
  65. # DEBUG without DOSEMU
  66. #BUILDOPTS="$DEBUGOPT $INSTALLOPT $INSTDIRMACRO $SRCDIRMACRO $SUSER $SGRP"
  67. #
  68. # DEBUG with DOSEMU
  69. BUILDOPTS="$DEBUGOPT $DOSEMUOPT $INSTALLOPT $INSTDIRMACRO $SRCDIRMACRO $SUSER $SGRP"
  70. #
  71. # RELEASE without DOSEMU
  72. #BUILDOPTS="$RELEASEOPT $INSTALLOPT $INSTDIRMACRO $SRCDIRMACRO $SUSER $SGRP"
  73. #
  74. # RELEASE without DOSEMU
  75. #BUILDOPTS="$RELEASEOPT $DOSEMUOPT $INSTALLOPT $INSTDIRMACRO $SRCDIRMACRO $SUSER $SGRP"
  76.  
  77.  
  78. # you should not need to edit below this line
  79.  
  80.  
  81. ECODE=0
  82. CWD=$PWD
  83. SDATE1=$(date +"%s")
  84. SCRIPTNAME=$(basename "$0")
  85. EXECDATE=$(date --date="@$SDATE1" '+%Y%m%d%H%M')
  86. LOGFILE="$SBBSDIR"/"$SCRIPTNAME"_"$EXECDATE".log
  87.  
  88. export SBBSCTRL=$SBBSDIR/ctrl
  89. export SBBSEXEC=$SBBSDIR/exec
  90.  
  91. printf "\n"
  92. printf "* %s logging to %s\n" "$SCRIPTNAME" "$LOGFILE"
  93.  
  94. function elapsedtime () {
  95.   local T=$1
  96.   local D=$((T/60/60/24))
  97.   local H=$((T/60/60%24))
  98.   local M=$((T/60%60))
  99.   local S=$((T%60))
  100.  
  101.   printf "** Total Elapsed Time: %s day" "$D"
  102.   if [[ $D = 0 ]] || [[ $D -gt 1 ]]; then printf "s"
  103.   fi
  104.   printf " %s hour" "$H"
  105.   if [[ $H = 0 ]] || [[ $H -gt 1 ]]; then printf "s"
  106.   fi
  107.   printf " %s minute" "$M"
  108.   if [[ $M = 0 ]] || [[ $M -gt 1 ]]; then printf "s"
  109.   fi
  110.   printf " %s second" "$S"
  111.   if [[ $S = 0 ]] || [[ $S -gt 1 ]]; then printf "s"
  112.   fi
  113.   printf " **\n"
  114. }
  115.  
  116. promptyn () {
  117.   if [ "$#" -ne 2 ]; then
  118.     printf "\nIllegal number of parameters: %s\n" $#
  119.     printf "promptyn requires two parameters, the prompt string and the default response\n"
  120.     printf "eg:\n"
  121.     printf "  promptyn \"do something? Y/n\" \"Yes\"\n"
  122.     printf "\nAborting...\n"
  123.     # we should break out of the script completely here but exit 1 is not working for some reason
  124.     #exit 1
  125.     return 1
  126.   else
  127.     while true; do
  128.       printf "\n"
  129.       read -r -t 30 -n 1 -p "$1 " ANSWER
  130.       RSLT=$?
  131.       if [ -n "$ANSWER" ] || [ $RSLT -gt 128 ]; then
  132.         if [ $RSLT -gt 128 ]; then
  133.           printf "timed out"
  134.         fi
  135.         printf "\n"
  136.       fi
  137.       [ -z "$ANSWER" ] && ANSWER="$2"  # force second parameter to be the default choice
  138.       case ${ANSWER:0:1} in
  139.         [Yy]* ) return 0;;
  140.         [Nn]* ) return 1;;
  141.         * ) printf "Please answer yes or no.\n";;
  142.       esac
  143.     done
  144.   fi
  145. }
  146.  
  147.  
  148. # Redirect stdout ( > ) into a named pipe ( >() ) running "tee"
  149. exec > >(tee "$LOGFILE")
  150.  
  151. # Without this, only stdout would be captured - i.e. your
  152. # log file would not contain any error messages.
  153. exec 2>&1
  154.  
  155.  
  156. printf "* starting in %s\n" "$CWD"
  157. printf "* Start Date: %s\n" "$(date --date="@$SDATE1" +'%Y-%m-%d %H:%M:%S')"
  158. printf "\n"
  159.  
  160. ##########################
  161. # * do all the updates * #
  162. ##########################
  163. cd "$SBBSDIR" || exit
  164. printf "* archiving your ctrl and exec directories...\n"
  165. THISCMD="tar -czf ctrl_$EXECDATE.tgz ctrl"
  166. printf "* %s\n" "$THISCMD"
  167. printf "*************************\n"
  168. $THISCMD
  169. printf "* ctrl archived\n\n"
  170.  
  171. THISCMD="tar -czf exec_$EXECDATE.tgz exec"
  172. printf "* %s\n" "$THISCMD"
  173. printf "*************************\n"
  174. $THISCMD
  175. printf "* exec archived\n\n"
  176.  
  177. export CVSROOT=:pserver:anonymous@cvs.synchro.net:/cvsroot/sbbs
  178. printf "* updating exec src 3rdp and xtrn directories...\n"
  179. THISCMD="cvs update -d exec"
  180. printf "* %s\n" "$THISCMD"
  181. printf "*************************\n"
  182. $THISCMD
  183. printf "\n"
  184. THISCMD="cvs update -d src"
  185. printf "* %s\n" "$THISCMD"
  186. printf "*************************\n"
  187. $THISCMD
  188. printf "\n"
  189. THISCMD="cvs update -d 3rdp"
  190. printf "* %s\n" "$THISCMD"
  191. printf "*************************\n"
  192. $THISCMD
  193. printf "\n"
  194. THISCMD="cvs update -d xtrn"
  195. printf "* %s\n" "$THISCMD"
  196. printf "*************************\n"
  197. $THISCMD
  198. printf "\n"
  199.  
  200. if false; then
  201.   printf "* applying default.max.src patch\n"
  202.   pushd /sbbs/exec || exit
  203.   patch -b < /sbbs/default.src.patch
  204.   popd || exit
  205. fi
  206.  
  207. if [[ $APPLYPATCHES == "true" ]]; then
  208.   printf "* applying local patches\n"
  209.   pushd "$SOURCEDIR/sbbs3" > /dev/null || exit
  210.   for THISPATCH in $LOCALPATCHES
  211.   do
  212.     printf "* patch -b < %s.patch\n" "$PATCHDIR/$THISPATCH"
  213.     printf "*************************\n"
  214.     patch -b < "$PATCHDIR/$THISPATCH".patch
  215.     printf "\n"
  216.   done
  217.   popd > /dev/null || exit
  218.   printf "\n"
  219. fi
  220.  
  221. ###################################
  222. # * clean the build directories * #
  223. ###################################
  224. cd "$SOURCEDIR" || exit
  225. if [[ $BUILDOPTS =~ $RELEASEOPT ]]; then
  226.   THISCMD="./cleanall.sh $RELEASEOPT"
  227. else
  228.   THISCMD="./cleanall.sh"
  229. fi
  230. printf "* %s\n" "$THISCMD"
  231. printf "*************************\n"
  232. $THISCMD
  233. printf "\n"
  234.  
  235. ############################
  236. # * build all the things * #
  237. ############################
  238. THISLOC="$SOURCEDIR/sbbs3"
  239. printf "* building %s\n" "$THISLOC"
  240. cd "$THISLOC" || exit
  241. THISCMD="make $BUILDOPTS install"
  242. printf "* %s\n" "$THISCMD"
  243. printf "*************************\n"
  244. $THISCMD
  245. printf "\n"
  246.  
  247. THISLOC="$SOURCEDIR/sexpots"
  248. printf "* building %s\n" "$THISLOC"
  249. cd "$THISLOC" || exit
  250. THISCMD="make $BUILDOPTS"
  251. printf "* %s\n" "$THISCMD"
  252. printf "*************************\n"
  253. $THISCMD
  254. printf "\n"
  255.  
  256. THISLOC="$SBBSDIR/exec"
  257. printf "* building %s\n" "$THISLOC"
  258. cd "$THISLOC" || exit
  259. THISCMD="make $BUILDOPTS"
  260. printf "* %s\n" "$THISCMD"
  261. printf "*************************\n"
  262. $THISCMD
  263. printf "\n"
  264.  
  265. ################################
  266. #* do these only when needed * #
  267. ################################
  268. #printf "running $SBBSDIR/exec/update.js\n"
  269. #$SBBSDIR/exec/jsexec $SBBSDIR/exec/update.js
  270. #printf "\n"
  271. #printf "running $SBBSDIR/exec/sbbsecho_upgrade.js\n"
  272. #$SBBSDIR/exec/jsexec $SBBSDIR/exec/sbbsecho_upgrade.js
  273. #printf "\n"
  274.  
  275. printf "* attempting to grab latest sbbs_run for text.dat comparison\n"
  276. DLDIR="$HOME"/downloads/sbbs-dev
  277. if [ ! -d "$DLDIR" ]; then
  278.   printf "* creating %s...\n" "$DLDIR"
  279.   mkdir -p "$DLDIR"
  280.   printf "\n"
  281. fi
  282. if [ ! -d "$SBBSDIR/temp" ]; then
  283.   printf "* creating %s...\n" "$SBBSDIR/temp"
  284.   mkdir -p "$SBBSDIR/temp"
  285.   printf "\n"
  286. fi
  287. THISCMD="wget --tries=1 ftp://vert.synchro.net/Synchronet/sbbs_run.tgz -O $DLDIR/sbbs_run-$(date '+%Y%m%d').tgz"
  288. printf "* %s\n" "$THISCMD"
  289. printf "*************************\n"
  290. if $THISCMD ; then # wget succeeded
  291.   printf "\n"
  292.   printf "* extracting text.dat\n"
  293.   THISCMD="tar zxvf $DLDIR/sbbs_run-$(date '+%Y%m%d').tgz --strip=1 -C $SBBSDIR/temp/ ctrl/text.dat"
  294.   printf "* %s\n" "$THISCMD"
  295.   printf "*************************\n"
  296.   if $THISCMD ; then #tar succeeded
  297.     printf "\n"
  298.     printf "* moving text.dat to %s\n" "$SBBSDIR/ctrl/text-dev.dat"
  299.     THISCMD="mv -f $SBBSDIR/temp/text.dat $SBBSDIR/ctrl/text-dev.dat"
  300.     printf "* %s\n" "$THISCMD"
  301.     printf "*************************\n"
  302.     if $THISCMD ; then # mv succeeded
  303.       printf "\n"
  304.       printf "* diffing current text.dat with text-dev.dat\n"
  305.       THISCMD="diff $SBBSDIR/ctrl/text.dat $SBBSDIR/ctrl/text-dev.dat > /dev/null 2>&1"
  306.       printf "* %s\n" "$THISCMD"
  307.       printf "*************************\n"
  308.       diff "$SBBSDIR/ctrl/text.dat" "$SBBSDIR/ctrl/text-dev.dat" > /dev/null 2>&1
  309.       ECODE=$?
  310.       if [ $ECODE -eq 0 ] ; then
  311.          printf "* no changes to text.dat since last update\n"
  312.       elif [ $ECODE -eq 1 ] ; then
  313.          printf "*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n"
  314.          printf "* text.dat has changed since last update!\n"
  315.          printf "* use \"diff -Nuar %s %s\" to view the changes\n" "$SBBSDIR/ctrl/text.dat" "$SBBSDIR/ctrl/text-dev.dat"
  316.          printf "* don't forget to copy the new text-dev.dat file to text.dat OR edit\n"
  317.          printf "* your existing text.dat as needed for the new or changed prompts.\n"
  318.          printf "*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n"
  319.       else
  320.          printf "*****************************************************************************\n"
  321.          printf "***** ECODE: %s - There was something wrong with the diff command!! *****\n" $ECODE
  322.          printf "*****************************************************************************\n"
  323.       fi # ECODE
  324.     else # mv failed
  325.       printf "****************************************\n"
  326.       printf "***** ECODE: %s - mv failed!!! *****\n" $ECODE
  327.       printf "****************************************\n"
  328.     fi # mv
  329.   else # tar failed
  330.     printf "*****************************************\n"
  331.     printf "***** ECODE: %s - tar failed!!! *****\n" $ECODE
  332.     printf "*****************************************\n"
  333.   fi # tar
  334. else # wget failed
  335.   printf "******************************************\n"
  336.   printf "***** ECODE: %s - wget failed!!! *****\n" $ECODE
  337.   printf "******************************************\n"
  338. fi # wget
  339. printf "\n"
  340.  
  341. printf "* SBBS CVS update and compile complete!\n"
  342. printf "* you should double check your configuration in case there are new\n"
  343. printf "* or changed settings by entering the following commands:\n"
  344. printf "*\n"
  345. printf "* cd $SBBSDIR/ctrl\n"
  346. printf "* $SBBSDIR/exec/scfg\n"
  347. printf "*\n"
  348. printf "* then restart sbbs via your OS' execution method:\n"
  349. printf "*   SYSV. \"sudo /etc/init.d/sbbs restart\"\n"
  350. printf "* OR\n"
  351. printf "*   systemd. \"sudo systemctl restart sbbs\"\n"
  352. printf "*\n"
  353. printf "* returning to %s\n" "$CWD"
  354. cd "$CWD" || exit
  355.  
  356. EDATE1=$(date +"%s")
  357. printf "* End Date: %s\n" "$(date --date="@$EDATE1" +'%Y-%m-%d %H:%M:%S')"
  358. EDIFF=$((EDATE1-SDATE1))
  359. elapsedtime $EDIFF
  360. printf "*************************\n"
  361. printf "\n"
  362. unset APPLYPATCHES
  363. unset BUILDOPTS
  364. unset CWD
  365. unset DEBUGOPT
  366. unset DLDIR
  367. unset DOSEMUOPT
  368. unset ECODE
  369. unset EDATE1
  370. unset EDIFF
  371. unset EXECDATE
  372. unset INSTALLDIR
  373. unset INSTALLOPT
  374. unset INSTDIRMACRO
  375. unset LOCALPATCHES
  376. unset LOGFILE
  377. unset PATCHDIR
  378. unset RELEASEOPT
  379. unset SBBSDIR
  380. unset SCRIPTNAME
  381. unset SDATE1
  382. unset SGRP
  383. unset SOURCEDIR
  384. unset SRCDIRMACRO
  385. unset SUSER
  386. unset THISCMD
  387. unset THISPATCH
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement