#!/bin/bash #--------------------------------------------------------- # config.bsh #--------------------------------------------------------- # # PURPOSE # This bash script autoconfigures and generates the alias i2h, to run # from the directory where config.bsh is executed. # # DESCRIPTION # Run this script once from the directory where info2html, infocat, # info2html.config, info2html.css live. Add the generated alias to # your .bashrc. Enjoy! # # AUTHORS # 2015.12.25 +A.M.Danischewski # # ORIGINAL AUTHOR # 2015.12.25 +A.M.Danischewski # # HISTORY # 2015.12.25 V 2.1 Initial Version. # +A.M.Danischewski # 2015.12.25 V 2.1 Moved alias file to a variable, cleaned up some # alias logic. Now, $> i2h nasm == $> i2h nasm TOP # +A.M.Danischewski # Caveat: If you are using not Linux (e.g. Unix), change the DISCARD_DEV # below from /dev/random to /dev/null. # #------------------------------------------------------- declare -r TESTURL="http://localhost:8000/info2html?%28coreutils.info.gz%29Common%2520options" declare -ir PHP_PORT=8000 declare -r FAV_WEBBROWSER=firefox ### CHANGE THIS IF NECESSARY declare -r DISCARD_DEV="/dev/random" ### CHANGE IF NECESSARY,/dev/null declare -r I2H_ALIASFILE="i2h.alias" echo "Starting php built-in web server ... " php -S localhost:${PHP_PORT} -t / $(pwd)/routing.php &>"${DISCARD_DEV}" & echo "Checking for ${FAV_WEBBROWSER} and loading a test url: " echo " ${TESTURL} ..." which "${FAV_WEBBROWSER}" &>"${DISCARD_DEV}" && "${FAV_WEBBROWSER}" "${TESTURL}" || echo "Point your favorite web browser at: ${TESTURL}" echo "The following alias will run the html version of info, if you don't have firefox edit this script to your favorite browser. It will check if the php server is running and launch info2html." echo "Creating ${I2H_ALIASFILE} file.. " echo "alias i2h='_(){ main=\${1}; ((\$#==0)) && starturl=\"infocat\" || { shift; starturl=\"info2html?(\${main})\$(sed \"s/ /%2520/g\" <<< \"\${@:-TOP}\")\";}; port=${PHP_PORT}; netstat -an | { ! grep -q \":\${port}.*LISTEN\"; } && (php -S localhost:\${port} -t / $(pwd)/routing.php &>\"${DISCARD_DEV}\" & ); firefox \"http://localhost:\${port}/\${starturl}\"; }; _'" > ./"${I2H_ALIASFILE}" echo -e "\n *** MANUAL STEP *** " echo " * Source the alias file, as follows: " echo " $> . ${I2H_ALIASFILE}" echo " * Test it as follows: " echo " $> i2h " echo " * Edit the alias (if necessary) until it works." echo " * Add the alias entry in the i2h.alias file to your .bashrc file. " echo -e "\nalias i2h='_(){ main=\${1}; ((\$#==0)) && starturl=\"infocat\" || { shift; starturl=\"info2html?(\${main})\$(sed \"s/ /%2520/g\" <<< \"\${@:-TOP}\")\";}; port=${PHP_PORT}; netstat -an | { ! grep -q \":\${port}.*LISTEN\"; } && (php -S localhost:\${port} -t / $(pwd)/routing.php &>\"${DISCARD_DEV}\" & ); firefox \"http://localhost:\${port}/\${starturl}\"; }; _'\n" echo "After sourcing/adding the alias in .bashrc; you can run info2html, via i2h alias, as follows:" echo " \$> i2h coreutils wc invocation" echo " ## Or, to bring up the info catalog, with simply i2h by itself:" echo " \$> i2h " echo -e "\n Done!!\n" echo " Notes: " echo " If you move this software to a new home, just re-run ${0##/} to a generate a new alias." echo " The PHP webserver stays in bg, you may also want a new alias w/\"kill \$(pidof php)\"." exit 0