Advertisement
opexxx

marionnet_from_scratch.sh

Nov 23rd, 2013
281
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 53.67 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. # This file is part of marionnet
  4. # Copyright (C) 2010 2011 2012 2013  Jean-Vincent Loddo
  5. # Copyright (C) 2010 2011 2012 2013  Université Paris 13
  6. #
  7. # This program is free software: you can redistribute it and/or modify
  8. # it under the terms of the GNU General Public License as published by
  9. # the Free Software Foundation, either version 2 of the License, or
  10. # (at your option) any later version.
  11. #
  12. # This program is distributed in the hope that it will be useful,
  13. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15. # GNU General Public License for more details.
  16. #
  17. # You should have received a copy of the GNU General Public License
  18. # along with this program.  If not, see <http://www.gnu.org/licenses/>.
  19.  
  20. # Script version: 0.90.25
  21. # 2013.10.07
  22.  
  23. # Thanks:
  24. # - Lucas Nussbaum for the idea of having an option "--download-only/-O",
  25. #   and for his patch proposal (July 2013)
  26.  
  27.  
  28.  
  29. set -e
  30. shopt -s nullglob
  31. shopt -s expand_aliases
  32.  
  33. # Prevent problems compiling `ocamlbricks' (the command `cd' prints
  34. # the target directory when CDPATH is set, in the style of `pushd',
  35. # and this unexpected behaviour get the make process confused):
  36. unset CDPATH
  37.  
  38. # Prevent problems installing files as root (sudo) with a more
  39. # restrictive umask (like for instance 027):
  40. umask 022
  41.  
  42. # By default SUDO_OR_EVAL and SUDO_OR_NOTHING are set to 'sudo' for normal users:
  43. if [[ $USER = root ]]; then
  44.   export SUDO_OR_EVAL=eval
  45.   export SUDO_OR_NOTHING=
  46. else
  47.   export SUDO_OR_EVAL=sudo
  48.   export SUDO_OR_NOTHING=sudo
  49. fi
  50.  
  51. function exiting_because_error {
  52.  # global KEEP_DEBRIS TWDIR
  53.  echo -e "Exiting because of an unexpected error in line $BASH_LINENO"
  54.  if [[ $KEEP_DEBRIS = no ]]; then
  55.   rm -rf $TWDIR
  56.  fi
  57.  exit 3
  58. }
  59. #
  60. trap exiting_because_error ERR
  61.  
  62. # =============================================================
  63. #                     SELF DEPENDENCIES
  64. # =============================================================
  65.  
  66. function abspath {
  67.  local B=$(basename $1)
  68.  local D=$(dirname $1)
  69.  (builtin cd $D; echo $PWD/$B)
  70. }
  71.  
  72. # If realpath is not installed, use the poor man version:
  73. type -t realpath 2>/dev/null 1>/dev/null || {
  74.  function realpath { abspath "$@"; }
  75.  export -f realpath
  76. }
  77.  
  78. # Backup of the command line:
  79. COMMAND_LINE="$(type -p $0 || realpath $0) "
  80. COMMAND_LINE="$(realpath $COMMAND_LINE) "$@""
  81.  
  82. # =============================================================
  83. #                  PARSING COMMAND LINE
  84. # =============================================================
  85.  
  86. # Getopt's format used to parse the command line:
  87. OPTSTRING="hp:m:b:o:gG:t:kl:d:v:NVDKPFAOc:"
  88.  
  89. function parse_cmdline {
  90. local i j flag
  91. # Transform long format options into the short one:
  92. for i in "$@"; do
  93.   if [[ double_dash_found = 1 ]]; then
  94.     ARGS+=("$i")
  95.   else case "$i" in
  96.     --help)
  97.       ARGS+=("-h");
  98.       ;;
  99.     --marionnet-version|--marionnet)
  100.      ARGS+=("-m");
  101.      ;;
  102.     --ocamlbricks-version|--ocamlbricks)
  103.      ARGS+=("-b");
  104.      ;;
  105.     --ocaml-version|--ocaml)
  106.      ARGS+=("-o");
  107.      ;;
  108.     --use-godi)
  109.      ARGS+=("-g");
  110.      ;;
  111.     --no-native|--bytecode)
  112.      ARGS+=("-N");
  113.      ;;
  114.     --lablgtk-version|--lablgtk)
  115.      ARGS+=("-l");
  116.      ;;
  117.     --vde-version|--vde)
  118.      ARGS+=("-v");
  119.      ;;
  120.     --dot-version|--dot|--graphviz)
  121.      ARGS+=("-d");
  122.      ;;
  123.     --godi-version|--godi)
  124.      ARGS+=("-G");
  125.      ;;
  126.     --debris|--keep-debris)
  127.      ARGS+=("-k");
  128.      ;;
  129.     --no-vde|--ignore-vde)
  130.      ARGS+=("-V");
  131.      ;;
  132.     --no-dot|--ignore-dot)
  133.      ARGS+=("-D");
  134.      ;;
  135.     --no-kernels|--ignore-kernels)
  136.      ARGS+=("-K");
  137.      ;;
  138.     --no-pinocchio|--ignore-pinocchio)
  139.      ARGS+=("-P");
  140.      ;;
  141.     --no-filesystems|--ignore-filesystems)
  142.      ARGS+=("-F");
  143.      ;;
  144.     --download-only)
  145.      ARGS+=("-O");
  146.      ;;
  147.     --no-all|--ignore-all)
  148.      ARGS+=("-A");
  149.      ;;
  150.     --continue)
  151.      ARGS+=("-c");
  152.      ;;
  153.     --prefix)
  154.      ARGS+=("-p");
  155.      ;;
  156.     --tmpdir)
  157.      ARGS+=("-t");
  158.      ;;
  159.     --)
  160.       ARGS+=("--");
  161.       double_dash_found=1;
  162.       ;;
  163.     --[a-zA-Z0-9]*)
  164.       echo "*** Illegal long option $i.";
  165.       exit 1;
  166.       ;;
  167.     -[a-zA-Z0-9]*)
  168.       j="${i:1}";
  169.       while [[ $j != "" ]]; do ARGS+=("-${j:0:1}"); j="${j:1}"; done;
  170.       ;;
  171.     *)
  172.       ARGS+=("$i")
  173.       ;;
  174.   esac
  175.   fi
  176. done
  177. set - "${ARGS[@]}"
  178. unset ARGS
  179.  
  180. # Interpret short format options:
  181. while [[ $# -gt 0 ]]; do
  182.   OPTIND=1
  183.   while getopts ":$OPTSTRING" flag; do
  184.     if [[ $flag = '?' ]]; then
  185.       echo "ERROR: illegal option -$OPTARG.";
  186.       exit 1;
  187.     fi
  188.     eval "option_${flag}=$OPTIND"
  189.     eval "option_${flag}_arg='$OPTARG'"
  190.   done
  191.   for ((j=1; j<OPTIND; j++)) do
  192.     if [[ $1 = "--" ]]; then
  193.       shift;
  194.       for i in "$@"; do ARGS+=("$i"); shift; done
  195.       break 2;
  196.     else
  197.       shift;
  198.     fi
  199.   done
  200.   # Get just the first argument and reloop:
  201.   for i in "$@"; do ARGS+=("$i"); shift; break; done
  202. done
  203. } # end of parse_cmdline()
  204.  
  205. declare -a ARGS
  206. parse_cmdline "$@" # read OPTSTRING and set ARGS
  207. # Warning: the following two branches could not be grouped
  208. # into the single command (`else' branch):
  209. # set - "${ARGS[@]}";
  210. # The behaviour is not the same when the array is empty!
  211. if [[ ${#ARGS[@]} -eq 0 ]]; then
  212.   set - "";
  213. else
  214.   set - "${ARGS[@]}";
  215. fi
  216. unset ARGS
  217.  
  218. function print_usage_and_exit {
  219.  echo -e "Usage: ${0##*/} [OPTIONS]
  220. Download, compile and install marionnet and its principal dependencies.
  221. In addition to compile-time dependencies, when a run-time dependency
  222. like 'vde' or 'dot' seems not installed, the script automatically
  223. downloads, compiles and installs it from the appropriate project homepage
  224. or from our mirror (i.e. http://www.marionnet.org/download/mirror/).
  225. Options:
  226.   -p, --prefix PATH     Set the installation prefix
  227.   -t, --tmpdir PATH     Set the temporary working directory
  228.   -c, --continue PATH       Continue execution started in PATH
  229.   -k, --keep-debris     Don't clean temporary files when exiting
  230.   -h                Print this message and exit
  231.   -m, --marionnet VERSION   Set marionnet's version
  232.   -b, --ocamlbricks VERSION Set ocamlbricks' version
  233.   -o, --ocaml VERSION       Set ocaml's version
  234.   -g, --use-godi        Use godi's ocaml distribution
  235.   -G, --godi VERSION        Set godi's version
  236.  -l, --lablgtk VERSION         Set lablgtk's version
  237.  -v, --vde VERSION             Set vde2's version
  238.   -d, --dot VERSION         Set dot's (graphviz) version
  239.   -N, --bytecode        Generate bytecode only (no native executables)
  240.   -V, --no-vde          Do nothing about vde
  241.   -D, --no-dot          Do nothing about dot (graphviz)
  242.   -K, --no-kernels      Don't download kernels
  243.   -P, --no-pinocchio        Don't download pinocchio (small) filesystems
  244.   -F, --no-filesystems      Don't download other (big) filesystems
  245.  -O, --download-only           Skip everything except downloads of kernels and filesystems
  246.   -A, --no-all              Equivalent to --no-{vde,dot,kernels,pinocchio,filesystems}
  247. Defaults:
  248.  - the installation prefix is ${PREFIX}
  249.  - the temporary working directory is $TMPDIR
  250.  - continue execution: ${CONTINUE:-none}
  251.  - marionnet's version is ${MARIONNET_VERSION:-latest}
  252.  - ocamlbricks' version is ${OCAMLBRICKS_VERSION:-latest}
  253.  - ocaml's version is ${OCAML_VERSION:-latest}
  254.  - godi's version is ${GODI_OCAML_VERSION:-latest}
  255.  - lablgtk's version is ${LABLGTK_VERSION:-latest}
  256.  - vde's version is ${VDE2_VERSION:-latest}
  257.  - dot's (graphviz') version is ${GRAPHVIZ_VERSION:-latest}
  258.  - using godi: $USING_GODI
  259.  - keep debris: $KEEP_DEBRIS
  260.  - generate bytecode only: $GENERATE_BYTECODE
  261.  - ignore vde: $IGNORE_VDE
  262.  - ignore dot: $IGNORE_DOT
  263.  - ignore kernels: $IGNORE_KERNELS
  264.  - ignore pinocchio filesystems: $IGNORE_PINOCCHIO_FILESYSTEMS
  265.  - ignore other (big) filesystems: $IGNORE_BIG_FILESYSTEMS"
  266.  exit $1
  267. }
  268.  
  269. # =============================================================
  270. #                         TUNING
  271. # =============================================================
  272.  
  273. # Option -p, --prefix
  274. if [[ -n ${option_p} ]]; then
  275.  PREFIX=$(realpath "${option_p_arg}")
  276. else
  277.  PREFIX=$(realpath /usr/local)
  278. fi
  279.  
  280. # Option -t, --tmpdir
  281. if [[ -n ${option_t} ]]; then
  282.  TMPDIR=$(realpath "${option_t_arg}")
  283. else
  284.  # We initialize the system variable TMPDIR if necessary:
  285.  TMPDIR=${TMPDIR:-/tmp}
  286.  TMPDIR=$(realpath $TMPDIR)
  287. fi
  288.  
  289. # Option -m, --marionnet-version
  290. if [[ -n ${option_m} ]]; then
  291.  MARIONNET_VERSION="${option_m_arg}"
  292. fi
  293.  
  294. # Option -b, --ocamlbricks-version
  295. if [[ -n ${option_b} ]]; then
  296.  OCAMLBRICKS_VERSION="${option_b_arg}"
  297. elif [[ $MARIONNET_VERSION = "trunk" ]]; then
  298.  OCAMLBRICKS_VERSION="trunk"
  299. fi
  300.  
  301. # Option -o, --ocaml-version
  302. if [[ -n ${option_o} ]]; then
  303.  OCAML_VERSION="${option_o_arg}"
  304. elif [[ $MARIONNET_VERSION = "trunk" ]]; then
  305.  # This value must be updated each time the trunk
  306.  # will require a new OCaml version:
  307.  OCAML_VERSION="3[.]12[.]1"
  308. else
  309.  # Fixed for marionnet 0.90.6:
  310.  OCAML_VERSION="3[.]11[.]2"
  311. fi
  312.  
  313. # Option -l, --lablgtk-version
  314. if [[ -n ${option_l} ]]; then
  315.  LABLGTK_VERSION="${option_l_arg}"
  316. else
  317.  # Fixed for marionnet 0.90.6:
  318.  LABLGTK_VERSION="2[.]14[.]2"
  319. fi
  320.  
  321. # Option -v, --vde-version
  322. if [[ -n ${option_v} ]]; then
  323.  VDE2_VERSION="${option_v_arg}"
  324. fi
  325.  
  326. # Option -d, --dot-version
  327. if [[ -n ${option_d} ]]; then
  328.  GRAPHVIZ_VERSION="${option_d_arg}"
  329. fi
  330.  
  331. # Option -g, --use-godi
  332. if [[ -n ${option_g} ]]; then
  333.  USING_GODI=yes
  334.  REQUIRED_MB=380
  335. else
  336.  USING_GODI=no
  337.  REQUIRED_MB=480
  338. fi
  339.  
  340. # Option -G, --godi-version
  341. if [[ -n ${option_G} ]]; then
  342.  GODI_OCAML_VERSION="${option_G_arg}"
  343. fi
  344.  
  345. # Option -N, --no-native, --bytecode
  346. if [[ -n ${option_N} ]]; then
  347.  GENERATE_BYTECODE=yes
  348. else
  349.  GENERATE_BYTECODE=no
  350. fi
  351.  
  352. # Option -k, --keep-debris
  353. if [[ -n ${option_k} ]]; then
  354.  KEEP_DEBRIS=yes
  355. else
  356.  KEEP_DEBRIS=no
  357. fi
  358.  
  359. # Option -c, --continue
  360. if [[ -n ${option_c} ]]; then
  361.   if [[ -d "${option_c_arg}" ]]; then
  362.    TMPDIR=$(realpath "${option_c_arg}")
  363.    TWDIR="$TMPDIR"
  364.    CONTINUE=yes
  365.   else
  366.    echo "Error: ${option_c_arg} doesn't exist or is not a directory."
  367.    echo "Exiting."
  368.    exit 1
  369.   fi
  370. fi
  371.  
  372. # Option -V, --no-vde
  373. if [[ -n ${option_V} || -n ${option_A} ]]; then IGNORE_VDE=yes; else IGNORE_VDE=no; fi
  374.  
  375. # Option -D, --no-dot
  376. if [[ -n ${option_D} || -n ${option_A} ]]; then IGNORE_DOT=yes; else IGNORE_DOT=no; fi
  377.  
  378. # Option -K, --no-kernels
  379. if [[ -n ${option_K} || -n ${option_A} ]]; then IGNORE_KERNELS=yes; else IGNORE_KERNELS=no; fi
  380.  
  381. # Option -P, --no-pinocchio
  382. if [[ -n ${option_P} || -n ${option_A} ]]; then IGNORE_PINOCCHIO_FILESYSTEMS=yes; else IGNORE_PINOCCHIO_FILESYSTEMS=no; fi
  383.  
  384. # Option -F, --no-filesystems
  385. if [[ -n ${option_F} || -n ${option_A} ]]; then IGNORE_BIG_FILESYSTEMS=yes; else IGNORE_BIG_FILESYSTEMS=no; fi
  386.  
  387. # Option -O, --download-only
  388. if [[ -n ${option_O} ]]; then DOWNLOAD_ONLY=yes; else DOWNLOAD_ONLY=no; fi
  389.  
  390. # Option -h
  391. if [[ -n ${option_h}  ]]; then
  392.  print_usage_and_exit 0
  393. fi
  394.  
  395. # =============================================================
  396. #                     TEMPORARY STUFF
  397. # =============================================================
  398.  
  399. function exiting_because_signal {
  400.  # global KEEP_DEBRIS TWDIR COMMAND_LINE
  401.  echo -e "Exiting because of signal."
  402.  if [[ $KEEP_DEBRIS = no ]]; then
  403.   rm -rf $TWDIR
  404.  else
  405.   echo -e "You can continue the execution launching the following command:
  406. ---
  407. $COMMAND_LINE -c $TWDIR
  408. ---
  409. Exiting."
  410.  fi
  411.  exit 2
  412. }
  413.  
  414. # Temporary Working Directory TWDIR (global variable)
  415. # Automatically cleaned when some events occur
  416. function tmpfile {
  417.  # global TMPDIR TWDIR
  418.  if [[ -z $TWDIR ]]; then
  419.    local FREE_MB=$(df -B 1M -P $TMPDIR | awk '{print $4}' | tail -n 1)
  420.    if [[ $FREE_MB -lt $REQUIRED_MB ]]; then
  421.      echo "Insufficient free disk space (${FREE_MB} Mb) in the directory $TMPDIR."
  422.      echo "You can set a larger temporary working directory using the -t option."
  423.      echo "Near to $REQUIRED_MB Mb are required for the script's execution."
  424.      echo "Exiting."
  425.      exit 1
  426.    fi 1>&2
  427.    TWDIR=$(mktemp -p ${TMPDIR:-/tmp} -d ${0##*/}.XXXXXXXX)
  428.    local SIGINT=2
  429.    local SIGQUIT=3
  430.    local SIGABRT=6
  431.    local SIGKILL=9
  432.    local SIGTERM=15 # CTRL-C
  433.    local TRAPPED_EVENTS="$SIGINT $SIGQUIT $SIGABRT $SIGKILL $SIGTERM"
  434.    trap "exiting_because_signal" $TRAPPED_EVENTS
  435.  fi
  436.  if [[ $# = 0 ]]; then
  437.    local TMPFILE=$(mktemp -p $TWDIR tmpfile.XXXXXXXX)
  438.  else
  439.    local TMPFILE=$(mktemp -p $TWDIR "$@")
  440.  fi
  441.  echo "$TMPFILE"
  442. }
  443.  
  444. # =============================================================
  445. #                           TOOLS
  446. # =============================================================
  447.  
  448. function exit_and_continue_as_root {
  449. # global TWDIR COMMAND_LINE
  450. echo
  451. if [[ -n "$1" ]]; then
  452.   echo "Error using the program '$1' to become the super user."
  453. else
  454.   echo "No manner to become the super user."
  455. fi
  456. echo -e "In order to install marionnet, become super user and continue launching
  457. the following command:
  458. ---
  459. $COMMAND_LINE -c $TWDIR
  460. ---
  461. Exiting."
  462. exit 1
  463. }
  464.  
  465. function ensure_sudo {
  466. # global USER TWDIR COMMAND_LINE
  467. [[ $USER = root ]] && return 0
  468. sudo -v "$@" || exit_and_continue_as_root "sudo"
  469. }
  470.  
  471. function ensure_sudo_or_continue_as_root {
  472. # global USER TWDIR COMMAND_LINE
  473. local MESSAGE_ABOUT_ACTION="$1"
  474. if [[ $USER = root ]]; then
  475.   echo "Fine, I'm root." 1>&2
  476. elif type -t sudo 1>&2; then
  477.   ensure_sudo -p "* Required the [sudo] password for %u:"
  478. elif type -t su 1>&2; then
  479.   echo "* $MESSAGE_ABOUT_ACTION"
  480.   echo "  The script will be continued as root."
  481.   echo -n "  Please provide root's password: "
  482.   su -c "echo; $COMMAND_LINE -c $TWDIR" || exit_and_continue_as_root "su"
  483.   exit 0
  484. else
  485.   exit_and_continue_as_root
  486. fi
  487. }
  488.  
  489.  
  490. function append_line_if_needed {
  491. # global SUDO_OR_NOTHING
  492. local LINE="$1"
  493. local FILE="$2"
  494. { test -f "$FILE" && grep -q "${LINE}" "$FILE"; } || $SUDO_OR_NOTHING echo "$LINE" >> "$FILE"
  495. }
  496.  
  497. function wait_printing_dots {
  498.  while sleep 2 && jobs %% 1>/dev/null 2>&1; do echo -n "."; done
  499. }
  500.  
  501. function define_global_TAB {
  502. local i COLS
  503. if [[ -z $COLUMNS ]]; then
  504.  if type tput 1>/dev/null 2>/dev/null; then
  505.    COLUMNS=$(tput cols)
  506.  else
  507.    COLUMNS=80
  508.  fi
  509. fi
  510. # COLS is the max between $COLUMNS and 104
  511. if [[ $COLUMNS -gt 104 ]]; then COLS=104; else COLS=$COLUMNS; fi
  512. global_TAB+='\r'
  513. for ((i=1; i<=(COLS/8)-1; i++)); do global_TAB+='\t'; done
  514. }
  515.  
  516. define_global_TAB;
  517.  
  518. function echo_at_right_side {
  519.  local NEWLINE=""
  520.  if [[ $1 = --newline ]]; then NEWLINE="\n"; shift; fi
  521.  eval echo -en "'$global_TAB'"
  522.  eval printf "'%4s$NEWLINE'" "$1"
  523. }
  524.  
  525. function wait_printing_percent_progress {
  526.  if [[ -z $1 ]];
  527.  then wait_printing_dots
  528.  else
  529.    local SECTION_SIZE=$1 # or "weight"
  530.    local LOGSIZE=$(wc -c <$LOGFILE)
  531.    local OFFSET=$LOGSIZE
  532.    local TAB=${2:-$global_TAB}
  533.    local PERCENT
  534.    while sleep 2 && jobs %% 1>/dev/null 2>&1; do
  535.      LOGSIZE=$(wc -c <$LOGFILE)
  536.      eval echo -en "'$TAB'"
  537.      PERCENT=$((100*(LOGSIZE-OFFSET)/SECTION_SIZE))
  538.      if [[ $PERCENT -gt 100 ]]; then PERCENT=100; fi
  539.      printf "%3d%%" $PERCENT
  540.    done
  541.    eval echo -en "'$TAB'"
  542.    printf "100%%"
  543.  fi
  544. }
  545.  
  546. function launch_and_log {
  547.  # global COMMAND_RESULT ALREADY_DONE SUDO_OR_EVAL
  548.  # The option --as-root implies --as-script if the user in not root (in order to
  549.  # prevent sudo to re-ask the password)
  550.  # The option --as-script implies that the command will be launched
  551.  # as a standalone script
  552.  local DO_NOT_REGISTER_AS_DONE
  553.  if [[ $1 = --do-not-register-as-done ]]; then shift; DO_NOT_REGISTER_AS_DONE=y; fi
  554.  local EVAL_OR_SUDO
  555.  local AS_SCRIPT
  556.  # By default EVAL_OR_SUDO is equal to eval
  557.  EVAL_OR_SUDO=eval
  558.  if [[ $1 = --as-root   || $1 = --sudo   ]]; then shift; EVAL_OR_SUDO=$SUDO_OR_EVAL; fi
  559.  if [[ $1 = --as-script || $1 = --script ]]; then shift; AS_SCRIPT=yes; fi
  560.  if [[ $EVAL_OR_SUDO = sudo ]]; then
  561.    AS_SCRIPT=yes
  562.  fi
  563.  local MSG="$1"
  564.  echo -n "* $MSG ..."
  565.  if grep <$ALREADY_DONE -q "^$MSG DONE$"; then
  566.   echo_at_right_side "done";
  567.   echo
  568.   return 0
  569.  fi
  570.  local CMD="{ $2 2>&1 || echo 1 > $COMMAND_RESULT; } 1>&2"
  571.  local SECTION_SIZE=$3
  572.  echo -e "===\nCHECKPOINT: $MSG\n===\n" 1>&2
  573.  echo 0 > $COMMAND_RESULT
  574.  case $AS_SCRIPT in
  575.    yes)
  576.      local TMPSCRIPT=$(tmpfile script.XXXXXX)
  577.      echo '#!/bin/bash' > $TMPSCRIPT
  578.      echo "export PATH=$PATH" >> $TMPSCRIPT
  579.      echo $CMD >> $TMPSCRIPT
  580.      chmod +x $TMPSCRIPT
  581.      $EVAL_OR_SUDO $TMPSCRIPT &
  582.      ;;
  583.      *)
  584.      $EVAL_OR_SUDO $CMD &
  585.      ;;
  586.  esac
  587.  wait_printing_percent_progress $SECTION_SIZE
  588.  sync
  589.  local RETURN_CODE=$(<$COMMAND_RESULT)
  590.  if [[ $RETURN_CODE -eq 1 ]]; then
  591.   echo "FAILED!"
  592.   echo "Last 20 lines of log ($LOGFILE):"
  593.   echo "======"
  594.   tail -n 20 $LOGFILE
  595.   echo "======"
  596.   echo "Exiting."
  597.  else
  598.   echo
  599.   if [[ -z $DO_NOT_REGISTER_AS_DONE ]]; then
  600.     echo "$MSG DONE" >> $ALREADY_DONE
  601.   fi
  602.  fi
  603.  return $RETURN_CODE
  604. }
  605.  
  606. # Support https:
  607. alias wget='wget --no-check-certificate'
  608.  
  609.  
  610. function download_tar_gz_from_definite_url {
  611. local BASENAME="$1" # ex: vde2
  612. local URL="$2" # ex: http://sourceforge.net/projects/vde/files/vde2/2.3.2/vde2-2.3.2.tar.gz
  613. { wget -O - "$URL" \
  614.   | tar 1>&2 xvzf -
  615.   } || return 1
  616. ln -s ${BASENAME}-* ${BASENAME} || true
  617. return 0
  618. }
  619.  
  620.  
  621. function download_latest_tar_gz_from_url {
  622. local BASENAME="$1" # ex: vde2
  623. local VERSION="${2:-[0-9][0-9]*[.][0-9][0-9]*[.][0-9][0-9]*}"
  624. local URL="$3" # ex: http://sourceforge.net/projects/vde/
  625. local TGZ="${4:-$(tmpfile)}"
  626. { wget -O - "$URL" \
  627.   | grep -o "href=\".*${BASENAME}-${VERSION}[.]tar[.]gz[0-9A-Za-z/_-]*\"" \
  628.   | cut -d\" -f2
  629.   } > $TGZ || return 1
  630. LATEST=$(grep <$TGZ -o "${VERSION}[.]tar[.]gz" | tr '.' ' '| sort -n | tr ' ' '.' | tail -n 1)
  631. if [[ -z "$LATEST" ]]; then
  632.   echo "No latest version of $BASENAME found looking into $URL."
  633.   return 2
  634. else
  635.   echo "Ok, latest version $LATEST of $BASENAME found looking into $URL."
  636. fi 1>&2
  637. TGZ=$(grep <$TGZ -o ".*${BASENAME}-${LATEST}[0-9A-Za-z/_-]*")
  638. # Adjust relative href:
  639. if [[ ${TGZ#http://} = ${TGZ} ]] && [[ ${TGZ#https://} = ${TGZ} ]] && [[ ${TGZ#ftp://} = ${TGZ} ]]; then
  640. TGZ="${URL%/*}/$TGZ"
  641. fi
  642. { wget -O - $TGZ \
  643.   | tar 1>&2 xvzf -
  644.   } || return 1
  645. ln -s ${BASENAME}-* ${BASENAME} || true
  646. return 0
  647. }
  648.  
  649. # Usage: download_latest_tar_gz [(-v|--version) REGEXPR] BASENAME URL...
  650. function download_latest_tar_gz {
  651. local VERSION
  652. if [[ $1 = '-v' || $1 = '--version' ]]; then
  653.  VERSION="$2"
  654.  shift 2 || return 2
  655. else
  656.  VERSION="[0-9][0-9]*[.][0-9][0-9]*[.][0-9][0-9]*"
  657. fi
  658. # "-v latest" means the latest matching the default regexp:
  659. if [[ $VERSION = latest || -z $VERSION ]]; then
  660.   VERSION="[0-9][0-9]*[.][0-9][0-9]*[.][0-9][0-9]*"
  661. fi
  662. local BASENAME="$1" # ex: vde2
  663. shift || return 2
  664. local URL LATEST
  665. local TGZ=$(tmpfile)
  666. for URL in "$@"; do
  667.  download_latest_tar_gz_from_url "$BASENAME" "$VERSION" "$URL" "$TGZ"  && {
  668.    [[ $# -gt 1 ]] && echo "Downloaded from $URL"
  669.    rm -f "$TGZ"
  670.    return 0
  671.    }
  672. done
  673. rm -f "$TGZ"
  674. return 1
  675. }
  676.  
  677. # =============================================================
  678. #                        DOWNLOADS
  679. # =============================================================
  680.  
  681. # We look first at our mirror because the new versions of godi
  682. # use ocaml 3.12
  683. function download_latest_godi {
  684.   local VERSION="${GODI_OCAML_VERSION:-20[0-9]*}"
  685.   download_latest_tar_gz -v "$VERSION" godi-rocketboost \
  686.     $OUR_MIRROR \
  687.     "http://download.camlcity.org/download/"
  688. }
  689.  
  690. # Marionnet 0.90.2 has a problem with 3.12.0 (camlp4)
  691. function download_latest_ocaml {
  692.   local VERSION="${OCAML_VERSION:-[0-9][.][0-9][0-9][.][0-9]*}"
  693.   download_latest_tar_gz -v "$VERSION" ocaml \
  694.     "http://caml.inria.fr/pub/distrib/ocaml-3.11/" \
  695.     $OUR_MIRROR \
  696.     "http://caml.inria.fr/download.html"
  697. }
  698.  
  699.  
  700. # Obsolete url: "ftp://ftp.kurims.kyoto-u.ac.jp/pub/lang/olabl/"
  701. function download_latest_lablgtk {
  702.   local VERSION="${LABLGTK_VERSION:-[0-9][.][0-9][0-9]*[.][0-9][0-9]*}"
  703.   download_latest_tar_gz -v "$VERSION" lablgtk \
  704.     "http://wwwfun.kurims.kyoto-u.ac.jp/soft/lsl/lablgtk.html" \
  705.     $OUR_MIRROR
  706. }
  707.  
  708. function download_latest_vde {
  709.   local VERSION=${VDE2_VERSION:-2.3.2}
  710.   local URL="http://sourceforge.net/projects/vde/files/vde2/2.3.2/vde2-2.3.2.tar.gz"
  711.   download_tar_gz_from_definite_url vde2 "$URL" || \
  712.     download_latest_tar_gz -v "$VERSION" vde2 $OUR_MIRROR
  713. }
  714.  
  715. function download_latest_marionnet {
  716.   local VERSION=${MARIONNET_VERSION:-latest}
  717.   download_latest_tar_gz -v "$VERSION" marionnet \
  718.     "https://launchpad.net/marionnet" \
  719.     $OUR_MIRROR
  720. }
  721.  
  722. function download_latest_ocamlbricks  {
  723.   local VERSION=${OCAMLBRICKS_VERSION:-latest}
  724.   download_latest_tar_gz -v "$VERSION" ocamlbricks \
  725.     "https://launchpad.net/ocamlbricks" \
  726.     $OUR_MIRROR
  727. }
  728.  
  729. function download_latest_graphviz {
  730.   local VERSION=${GRAPHVIZ_VERSION:-latest}
  731.   download_latest_tar_gz -v "$VERSION" graphviz \
  732.     "http://www.graphviz.org/Download_source.php" \
  733.     $OUR_MIRROR
  734. }
  735.  
  736. # =============================================================
  737. #                     DEBIAN or derived
  738. # =============================================================
  739.  
  740. function are_we_in_debian_or_derived {
  741.   $(which dpkg) -L bash 2>/dev/null | grep -q $(which bash) &&
  742.   $(which dpkg) -L apt  2>/dev/null | grep -q $(which apt-get)
  743. }
  744.  
  745. # Useless now (since 2011-11-07)
  746. function are_we_in_ubuntu_11_or_greater {
  747.  if [[ -f /etc/issue ]]; then
  748.    local A=$(head -n 1 /etc/issue)
  749.    local a b c
  750.    read a b c <<<"$A"
  751.    if [[ "$a" = "Ubuntu" ]]; then
  752.      IFS="." read a c <<<"$b"
  753.      [[ "$a" -ge 11 ]]
  754.    else
  755.      return 1
  756.    fi
  757.  else
  758.   return 1
  759.  fi
  760. }
  761.  
  762. # (problems with the packaged version of vde2)
  763. function are_we_in_ubuntu_12_04 {
  764.  if [[ -f /etc/issue ]]; then
  765.    local A=$(head -n 1 /etc/issue)
  766.    local a b c
  767.    read a b c <<<"$A"
  768.    if [[ "$a" = "Ubuntu" ]]; then
  769.      IFS="." read a c d <<<"$b"
  770.      [[ "$a" = "12" && "$c" = "04" ]]
  771.    else
  772.      return 1
  773.    fi
  774.  else
  775.   return 1
  776.  fi
  777. }
  778.  
  779. function echo_debian_package_for_binary_if_really_needed {
  780.  local BINARY=$1
  781.  local PACKAGE=$2
  782.  if type -t $BINARY 1>&2; then
  783.    return 0 # not needed
  784.  else
  785.    echo "$PACKAGE " # note the trailing blank
  786.  fi
  787. }
  788.  
  789. function is_aptitude_installed  {
  790.  type 1>&2 aptitude
  791. }
  792.  
  793.  
  794. function is_package_installed {
  795.  local L=en_US.UTF-8
  796.  LANG=$L LC_ALL=$L LC_MESSAGES=$L LANGUAGE=$L dpkg -s $1 2>/dev/null | \grep -q 'Status: install ok installed';
  797. }
  798.  
  799. function echo_required_debian_packages {
  800.  local LIST i VDE2_VERSION EXTRA_FOR_GODI
  801.  
  802.  # Then continue with aptitude
  803.  for i in gcc g++ make flex libtool bison grep tar xterm wget mktemp realpath sed gawk aptitude; do
  804.    LIST+=$(echo_debian_package_for_binary_if_really_needed $i $i)
  805.  done
  806.  
  807.  LIST+=$(echo_debian_package_for_binary_if_really_needed dot graphviz)
  808.  LIST+=$(echo_debian_package_for_binary_if_really_needed uml_switch uml-utilities)
  809.  
  810.  if [[ $USING_GODI = yes ]]; then
  811.   EXTRA_FOR_GODI="gtkgl-dev freeglut3-dev tk8.4-dev libxmu-dev"
  812.  fi
  813.  
  814.  for i in \
  815.    libgtk2.0-dev libglade2-dev liblablgtksourceview2-ocaml-dev $EXTRA_FOR_GODI \
  816.    bridge-utils coreutils debianutils diffutils \
  817.    net-tools uml-utilities util-linux x11-xserver-utils \
  818.    coreutils findutils login procps gettext \
  819.    rlfe; # alternatives are rlwrap and ledit
  820.    do
  821.    if ! is_package_installed $i; then
  822.      LIST+="$i "
  823.    fi
  824.  done
  825.  
  826.  # vde2 only if is not already installed and the available version is >= 2.2.1
  827.  if type 1>&2 aptitude; then
  828.    type 1>&2 vde_switch || {
  829.        VDE2_VERSION=$(aptitude show vde2 | awk '/^Version.*[2-9][.][0-9][.][0-9].*/ {print $2}' | awk -F '-' '{print $1}')
  830.        VDE2_VERSION=$(echo $VDE2_VERSION | awk -F '.' '(($2 * 100 + $3 * 10 + $4) >= 221) {print}')
  831.        if [[ -n "$VDE2_VERSION" ]]; then
  832.        LIST+="vde2 "
  833.        fi
  834.    }
  835.  fi
  836.  
  837.  # x86_64 => libc6-i386
  838.  if type uname && [[ $(uname -m) = "x86_64" ]] && ! dpkg -p libc6-i386; then
  839.    LIST+="libc6-i386 "
  840.  fi 1>&2
  841.  
  842.  # Return the list:
  843.  echo "$LIST"
  844. }
  845.  
  846. # =============================================================
  847. #                  OUR KERNELS AND FILESYSTEMS
  848. # =============================================================
  849.  
  850. function download_our_kernels {
  851.   # global OUR_BASE_URL
  852.   local KERNELS
  853.   KERNELS=$(wget -O - "$OUR_BASE_URL" \
  854.   | grep -o 'href="kernels_.*"' \
  855.   | grep -o "kernels_.*[.]tar[.]gz"\
  856.   )
  857.   local i WEIGHT
  858.   for i in $KERNELS; do
  859.     # Known weights:
  860.     case "$i" in
  861.       "kernels_linux-2.6.18-ghost.tar.gz") WEIGHT=6032 ;;
  862.       *) unset WEIGHT ;;
  863.     esac
  864.     launch_and_log --sudo --script "Installing $i" "{ wget -O - '$OUR_BASE_URL/$i' | tar 1>&2 xvzf -; }" $WEIGHT
  865.   done
  866. }
  867.  
  868. function download_our_big_filesystems {
  869.   # global OUR_BASE_URL
  870.   local FILESYSTEMS
  871.   FILESYSTEMS=$(wget -O - "$OUR_BASE_URL" \
  872.   | grep -o 'href="filesystems_.*"' \
  873.   | grep -o "filesystems_.*[.]tar[.]gz"\
  874.   | grep -v "filesystems_pinocchio.*[.]tar[.]gz"\
  875.   )
  876.   local i WEIGHT
  877.   for i in $FILESYSTEMS; do
  878.     # Known weights:
  879.     case "$i" in
  880.       "filesystems_machine-debian-lenny-sid-2008.tar.gz") WEIGHT=677935 ;;
  881.       "filesystems_machine-mandriva20100215.tar.gz") WEIGHT=540521 ;;
  882.       *) unset WEIGHT ;;
  883.     esac
  884.     launch_and_log --sudo --script "Installing $i" "{ wget -O - '$OUR_BASE_URL/$i' | tar 1>&2 xvzf -; }" $WEIGHT
  885.   done
  886. }
  887.  
  888. function download_our_pinocchio_filesystems {
  889.   # global OUR_BASE_URL
  890.   local FILESYSTEMS
  891.   FILESYSTEMS=$(wget -O - "$OUR_BASE_URL" \
  892.   | grep -o 'href="filesystems_pinocchio.*"' \
  893.   | grep -o "filesystems_.*[.]tar[.]gz"\
  894.   )
  895.   local i WEIGHT
  896.   for i in $FILESYSTEMS; do
  897.     # Known weights:
  898.     case "$i" in
  899.       "filesystems_pinocchio.tar.gz") WEIGHT=77543 ;;
  900.       *) unset WEIGHT ;;
  901.     esac
  902.     launch_and_log --sudo --script "Installing $i" "{ wget -O - '$OUR_BASE_URL/$i' | tar 1>&2 xvzf -; }"  $WEIGHT
  903.   done
  904. }
  905.  
  906. # Main function calling the previously defined functions (download_our_*):
  907. function download_marionnet_kernels_and_filesystems {
  908.   # global  OUR_BASE_URL  SUDO_OR_NOTHING  PREFIX
  909.   #Â global  IGNORE_KERNELS  IGNORE_PINOCCHIO_FILESYSTEMS  IGNORE_BIG_FILESYSTEMS
  910.   ensure_sudo -p "* Required the [sudo] password for %u:"
  911.   $SUDO_OR_NOTHING mkdir -p $PREFIX/share/marionnet/
  912.   pushd $PREFIX/share/marionnet/ 1>&2
  913.  
  914.   if [[ $IGNORE_KERNELS = yes ]]; then
  915.   echo -n "* Installing kernels: dependency ignored (--no-kernels)"
  916.   echo_at_right_side --newline "ok"
  917.   else download_our_kernels; fi
  918.  
  919.   if [[ $IGNORE_PINOCCHIO_FILESYSTEMS = yes ]]; then
  920.   echo -n "* Installing pinocchio filesystems: dependency ignored (--no-pinocchio)"
  921.   echo_at_right_side --newline "ok"
  922.   else download_our_pinocchio_filesystems; fi
  923.  
  924.   if [[ $IGNORE_BIG_FILESYSTEMS = yes ]]; then
  925.   echo -n "* Installing other filesystems: dependency ignored (--no-filesystems)"
  926.   echo_at_right_side --newline "ok"
  927.   else download_our_big_filesystems; fi
  928.  
  929.   popd 1>&2
  930. }
  931.  
  932. # =============================================================
  933. #                            MAIN
  934. # =============================================================
  935.  
  936. # Ubuntu 11.x workaround:
  937. # if are_we_in_debian_or_derived; then
  938. #   if [[ $USING_GODI = no ]] && are_we_in_ubuntu_11_or_greater ; then
  939. #     echo "* Warning: some OCaml/Ubuntu (>= 11.x) combinations may require the option -g"
  940. #     echo -n "  Shall I do as if you chose -g (compile OCaml with Godi) ([y]/n)? "; read z
  941. #     if [[ $z != n && $z != N ]]; then
  942. #         USING_GODI="yes"
  943. #         REQUIRED_MB=380
  944. #     fi
  945. #   fi
  946. # fi
  947.  
  948. PATH_BACKUP=$PATH
  949. cd "$TMPDIR"
  950.  
  951. if [[ $CONTINUE != yes ]]; then
  952. tmpfile -u 1>/dev/null # just create the temporary working directory $TWDIR
  953. fi
  954.  
  955. # We reassign the system variable TMPDIR used by mktemp (for children):
  956. export TMPDIR=$TWDIR
  957. export -f tmpfile
  958.  
  959. REPODIR="$TWDIR"
  960. REPODIR=$(realpath $REPODIR)
  961. # echo -e "Working directory \r\t\t\t: $REPODIR"
  962. cd $REPODIR
  963. LOGFILE=$REPODIR/log
  964. echo -e "* The log file is $LOGFILE"
  965.  
  966. # Redirect stderr to the log file:
  967. exec 2>>$LOGFILE
  968.  
  969. COMMAND_RESULT=$REPODIR/result
  970. ALREADY_DONE=$REPODIR/already_done
  971. touch $COMMAND_RESULT $ALREADY_DONE
  972.  
  973. OUR_BASE_URL="http://www.marionnet.org/download/marionnet_from_scratch"
  974. OUR_MIRROR="$OUR_BASE_URL/mirror/"
  975.  
  976. if [[ $DOWNLOAD_ONLY = yes ]]; then
  977.   download_marionnet_kernels_and_filesystems
  978.   echo '---'
  979.   echo "Success."
  980.   exit 0
  981. fi
  982.  
  983. if are_we_in_debian_or_derived; then
  984.   echo "* This looks like a Debian or derived distribution. Oh, joy!"
  985.   DEBIAN_PACKAGE_LIST=$(echo_required_debian_packages)
  986.   echo "DEBIAN_PACKAGE_LIST=$DEBIAN_PACKAGE_LIST" 1>&2 # debugging
  987.   if [[ -n ${DEBIAN_PACKAGE_LIST%% } ]]; then
  988.     echo "  Required packages: $DEBIAN_PACKAGE_LIST"
  989.     echo -n "  Shall I install required package(s) with aptitude ([y]/n)? "
  990.     read z
  991.     if [[ $z != n && $z != N ]]; then
  992.       echo -n "  Shall I use the aptitude option --allow-untrusted ([y]/n)? "; read z
  993.       if [[ $z != n && $z != N ]]; then
  994.     APTITUDE_OPTIONS+="--allow-untrusted "
  995.       fi
  996.       MSG="Installing required packages with aptitude"
  997.       ensure_sudo_or_continue_as_root "* $MSG"
  998.       # First install aptitude if needed:
  999.       if ! type 1>&2 aptitude; then
  1000.     launch_and_log --sudo "Installing aptitude" "apt-get -y install aptitude"
  1001.     APTITUDE_INSTALLED_NOW=yes
  1002.       fi
  1003.       # vde2 only if is not already installed and the available version is >= 2.2.1
  1004.       if [[ $APTITUDE_INSTALLED_NOW = yes ]] && ! type 1>&2 vde_switch; then
  1005.     VDE2_VERSION=$(aptitude $APTITUDE_OPTIONS show vde2 | awk '/^Version.*[2-9][.][0-9][.][0-9].*/ {print $2}' | awk -F '-' '{print $1}')
  1006.     VDE2_VERSION=$(echo $VDE2_VERSION | awk -F '.' '(($2 * 100 + $3 * 10 + $4) >= 221) {print}')
  1007.     if [[ -n "$VDE2_VERSION" ]]; then
  1008.       DEBIAN_PACKAGE_LIST+="vde2 "
  1009.       echo "  Note: I will also install vde2 with aptitude"
  1010.     fi
  1011.       fi
  1012.       # We set the option `--do-not-register-as-done' because sometimes a single call to aptitude is not sufficient to install all things...
  1013.       launch_and_log --do-not-register-as-done --sudo "$MSG" "aptitude $APTITUDE_OPTIONS -q -y install $DEBIAN_PACKAGE_LIST"
  1014.       DISABLE_libc6_i386_WARNING=yes
  1015.     fi # answered yes
  1016.   fi # package list not empty
  1017. fi # are_we_in_debian_or_derived
  1018.  
  1019. launch_and_log "Downloading marionnet" download_latest_marionnet 22400
  1020. launch_and_log "Downloading ocamlbricks" download_latest_ocamlbricks 7500
  1021.  
  1022. # =============================================================
  1023. #                       OCAML & LABLGTK
  1024. # =============================================================
  1025.  
  1026. function compile_ocaml {
  1027. cd ocaml
  1028. # Download and apply the patch bugfix-5237.diff for ocaml 3.11 on a 64 bits architecture
  1029. if type uname 1>&2 && [[ $(uname -m) = "x86_64" ]]; then
  1030.   local BUGFIX_FILE="bugfix-5237.diff"
  1031.   echo "Downloading the ocaml 3.11 patch ($BUGFIX_FILE) for x86_64"
  1032.   wget -O $BUGFIX_FILE "$OUR_MIRROR/$BUGFIX_FILE" || \
  1033.     wget -O $BUGFIX_FILE 'http://caml.inria.fr/mantis/file_download.php?file_id=415&type=bug' || \
  1034.       return 1
  1035.   echo "Applying the ocaml 3.11 patch ($BUGFIX_FILE) for x86_64"
  1036.   patch -p1 < $BUGFIX_FILE
  1037. # Download and apply the patch 0007-Fix-ocamlopt-w.r.t.-binutils-2.2[1-9].patch
  1038. # for ocaml 3.11 on a 32 bits architecture with binutils version=2.2[1-9].x
  1039. elif type ld 1>&2 && ld -v | \grep -q '[ ]2[.]2[1-9]'; then
  1040.   local BUGFIX_FILE="bugfix-5237-i386.diff"
  1041.   echo "Downloading the ocaml 3.11 patch ($BUGFIX_FILE) for i386"
  1042.   wget -O $BUGFIX_FILE "$OUR_MIRROR/$BUGFIX_FILE" || \
  1043.     wget -O $BUGFIX_FILE 'http://caml.inria.fr/mantis/file_download.php?file_id=418&type=bug' || \
  1044.       return 1
  1045.   echo "Applying the ocaml 3.11 patch ($BUGFIX_FILE) for i386"
  1046.   patch -p1 < $BUGFIX_FILE
  1047. fi
  1048. # Compile now:
  1049. { ./configure -prefix $OCAML_PREFIX -no-curses -no-tk &&
  1050.   make world.opt &&
  1051.   make install &&
  1052.   make -C tools/ objinfo &&
  1053.   if [[ ! -e $OCAML_PREFIX/bin/ocamlobjinfo ]]; then
  1054.     cp tools/objinfo $OCAML_PREFIX/bin/ &&
  1055.     [[ -e $OCAML_PREFIX/bin/ocamlobjinfo ]] || ln -s objinfo $OCAML_PREFIX/bin/ocamlobjinfo
  1056.   fi
  1057.   } || return 1
  1058. cd ..
  1059. }
  1060.  
  1061. function compile_lablgtk {
  1062. cd lablgtk
  1063. { ./configure --prefix $OCAML_PREFIX \
  1064.   --with-glade --without-gl --without-rsvg --without-gnomecanvas --without-gnomeui \
  1065.   --without-panel --without-gtkspell --without-gtksourceview --with-gtksourceview2 \
  1066.   --without-quartz &&
  1067.   make &&
  1068.   make opt &&
  1069.   make install
  1070.   } || return 1
  1071. cd ..
  1072. }
  1073.  
  1074. function compile_godi {
  1075. cd godi-rocketboost
  1076. ./bootstrap --batch -prefix $GODI_PREFIX 1>&2
  1077. export PATH=$GODI_PREFIX/bin:$GODI_PREFIX/sbin:$PATH
  1078. echo "GODI_BASEPKG_PCRE=yes" >> $GODI_PREFIX/etc/godi.conf
  1079. { ./bootstrap_stage2 1>&2 &&
  1080.   godi_perform -build godi-lablgtk2  1>&2 &&
  1081.   [[ -e ../godi/bin/ocamlobjinfo ]] || ln -s objinfo ../godi/bin/ocamlobjinfo
  1082.   } || return 1
  1083. cd ..
  1084. }
  1085.  
  1086. case $USING_GODI in
  1087.  no)
  1088.   # Tuning:
  1089.   export OCAML_PREFIX=$PWD/local
  1090.   export PATH=$OCAML_PREFIX/bin:$PATH
  1091.   LIB_OCAML=$OCAML_PREFIX/lib/ocaml/
  1092.   export CAML_LD_LIBRARY_PATH=${LIB_OCAML}/stublibs
  1093.   launch_and_log "Downloading ocaml" download_latest_ocaml 83000
  1094.   launch_and_log "Downloading lablgtk" download_latest_lablgtk 17800
  1095.   launch_and_log "Compiling ocaml" compile_ocaml 382000
  1096.   launch_and_log "Compiling lablgtk" compile_lablgtk 56000
  1097.  ;;
  1098.  
  1099.  yes)
  1100.   export GODI_PREFIX=$PWD/godi
  1101.   launch_and_log "Downloading ocaml (godi)" download_latest_godi 37342
  1102.   launch_and_log "Compiling ocaml with godi" compile_godi 990130
  1103.   # Tuning using godi
  1104.   export PATH=$GODI_PREFIX/bin:$GODI_PREFIX/sbin:$PATH
  1105.   LIB_OCAML=$GODI_PREFIX/lib/ocaml/std-lib/
  1106.  ;;
  1107.  
  1108. esac
  1109.  
  1110. # =============================================================
  1111. #                       OCAMLBRICKS
  1112. # =============================================================
  1113.  
  1114. cd ocamlbricks
  1115. cat >CONFIGME <<EOF
  1116. ocaml_libraryprefix=$LIB_OCAML
  1117. libraryprefix=$LIB_OCAML
  1118. prefix=$PREFIX
  1119. configurationprefix=\$prefix/etc
  1120. documentationprefix=\$prefix/share/doc
  1121. localeprefix=\$prefix/share/locale
  1122. ocaml_sources=$LIB_OCAML/caml
  1123. EOF
  1124.  
  1125. launch_and_log "Compiling ocamlbricks" 'make clean && make && make install' 4002673
  1126. cd ..
  1127.  
  1128. # =============================================================
  1129. #                        MARIONNET
  1130. # =============================================================
  1131.  
  1132. cd marionnet
  1133. cp ../ocamlbricks/CONFIGME .
  1134.  
  1135. # make
  1136.  
  1137. case $GENERATE_BYTECODE in
  1138.  yes)
  1139.   MARIONNET_MAKE_COMMAND='make clean byte'
  1140.   WEIGHT=2460914
  1141.   ;;
  1142.  no)
  1143.   MARIONNET_MAKE_COMMAND='make clean native'
  1144.   WEIGHT=2780316
  1145.   ;;
  1146. esac
  1147.  
  1148. launch_and_log \
  1149.   "Compiling marionnet" \
  1150.   "$MARIONNET_MAKE_COMMAND" \
  1151.   $WEIGHT
  1152.  
  1153. # make install
  1154.  
  1155. if [[ $USER = root ]]; then
  1156.   MAKE_INSTALL='make install'
  1157.   # Reset SUDO_OR_EVAL and SUDO_OR_NOTHING:
  1158.   SUDO_OR_EVAL=eval
  1159.   unset AS_ROOT SUDO_OR_NOTHING
  1160. elif [[ -w "$PREFIX" ]]; then
  1161.   MAKE_INSTALL='make install'
  1162.   unset AS_ROOT
  1163. elif type -t sudo 1>&2; then
  1164.   ensure_sudo -p "* Required the [sudo] password for %u:"
  1165.   MAKE_INSTALL="PATH=$PATH make install"
  1166.   SUDO_MAKE_INSTALL="sudo make install"
  1167.   AS_ROOT=--as-root
  1168. elif type -t su 1>&2; then
  1169.   echo "* Preparing to install in $PREFIX"
  1170.   echo "  The script will be continued as root."
  1171.   echo -n "  Please provide root's password: "
  1172.   su -c "echo; $COMMAND_LINE -c $TWDIR" || exit_and_continue_as_root "su"
  1173.   exit 0
  1174. else
  1175.   exit_and_continue_as_root
  1176. fi
  1177.  
  1178. # Set a default if not already set (when sudo is required and available):
  1179. SUDO_MAKE_INSTALL=${SUDO_MAKE_INSTALL:-$SUDO_OR_NOTHING $MAKE_INSTALL}
  1180.  
  1181. launch_and_log ${AS_ROOT} \
  1182.   "Installing marionnet" \
  1183.   "$MAKE_INSTALL" \
  1184.   3918924 # weight
  1185.  
  1186. # Alias for marionnet -> marionnet.native (or marionnet.byte)
  1187. if ! type marionnet 1>&2; then
  1188.  pushd $PREFIX/bin/
  1189.  for i in marionnet.{native,byte}; do
  1190.    if [[ -x $i ]]; then
  1191.      $SUDO_OR_NOTHING ln -sf $i marionnet
  1192.      break
  1193.    fi
  1194.  done
  1195.  popd
  1196. fi 1>&2
  1197.  
  1198. cd ..
  1199.  
  1200. # =============================================================
  1201. #                           VDE
  1202. # =============================================================
  1203.  
  1204. function download_compile_and_install_vde2 {
  1205.   download_latest_vde &&
  1206.   cd vde2
  1207.   { ./configure -prefix $PREFIX &&
  1208.     make &&
  1209.     $SUDO_MAKE_INSTALL
  1210.     } || return 1
  1211.   cd ..
  1212. }
  1213.  
  1214. if [[ $IGNORE_VDE = yes ]]; then
  1215.  echo -n "* Installing vde2: dependency ignored (--no-vde)"
  1216.  echo_at_right_side --newline "ok"
  1217. elif type vde_switch 1>&2; then
  1218.  echo -n "* Installing vde2: it seems to be already installed"
  1219.  echo_at_right_side --newline "ok"
  1220. else
  1221.  launch_and_log \
  1222.    "Downloading, compiling and installing vde2" \
  1223.    download_compile_and_install_vde2 \
  1224.    54276 # weight
  1225. fi
  1226.  
  1227. # =============================================================
  1228. #                       DOT (GRAPHVIZ)
  1229. # =============================================================
  1230.  
  1231. function download_compile_and_install_graphviz {
  1232.   download_latest_graphviz &&
  1233.   cd graphviz
  1234.   { ./configure -prefix=$PREFIX &&
  1235.     make &&
  1236.     $SUDO_MAKE_INSTALL
  1237.     } || return 1
  1238.   cd ..
  1239. }
  1240.  
  1241. if [[ $IGNORE_DOT = yes ]]; then
  1242.  echo -n "* Installing dot (graphviz): dependency ignored (--no-dot)"
  1243.  echo_at_right_side --newline "ok"
  1244. elif type dot 1>&2; then
  1245.  echo -n "* Installing dot (graphviz): it seems to be already installed"
  1246.  echo_at_right_side --newline "ok"
  1247. else
  1248.  launch_and_log \
  1249.    "Downloading, compiling and installing dot (graphviz)" \
  1250.    download_compile_and_install_graphviz \
  1251.    863227 # weight
  1252. fi
  1253.  
  1254. # =============================================================
  1255. #                     KERNELS AND FILESYSTEMS
  1256. # =============================================================
  1257.  
  1258. # The functions related to these features are located at the
  1259. # beginning of this script in order to manage the option
  1260. # download--only. So, at this point we have just to call the
  1261. # good function:
  1262. download_marionnet_kernels_and_filesystems
  1263.  
  1264. # =============================================================
  1265. #                     marionnet.conf
  1266. # =============================================================
  1267.  
  1268. if [[ -f $PREFIX/share/marionnet/marionnet.conf ]]; then
  1269.  MARIONNET_DOT_CONF=$PREFIX/share/marionnet/marionnet.conf
  1270. elif [[ -f $PREFIX/etc/marionnet/marionnet.conf ]]; then
  1271.  MARIONNET_DOT_CONF=$PREFIX/etc/marionnet/marionnet.conf
  1272. else
  1273.  echo "File \`marionnet.conf' not found. Exiting.";
  1274. exit 3
  1275. fi
  1276.  
  1277. function first_installed_binary_of_list {
  1278. local i
  1279. for i in "$@"; do
  1280.   if type -t $i &>/dev/null; then
  1281.     echo $i
  1282.     return 0
  1283.   fi
  1284. done
  1285. # otherwise return the first:
  1286. echo $1
  1287. }
  1288.  
  1289. MARIONNET_KEYBOARD_LAYOUT=$(echo $LANG | grep -o '^[a-z]*')
  1290. MARIONNET_KEYBOARD_LAYOUT=${MARIONNET_KEYBOARD_LAYOUT=:-us}
  1291. MARIONNET_PDF_READER=$(first_installed_binary_of_list evince okular kpdf xpdf gv)
  1292. MARIONNET_POSTSCRIPT_READER=$MARIONNET_PDF_READER
  1293. MARIONNET_DVI_READER=$MARIONNET_PDF_READER
  1294. MARIONNET_HTML_READER=$(first_installed_binary_of_list firefox epiphany galeon konqueror rekonq chromium opera)
  1295. MARIONNET_TEXT_EDITOR=$(first_installed_binary_of_list emacs gedit kate kwrite xemacs)
  1296.  
  1297. for i in MARIONNET_{PDF,POSTSCRIPT,DVI,HTML}_READER MARIONNET_TEXT_EDITOR MARIONNET_KEYBOARD_LAYOUT; do
  1298. v=$(eval echo \$$i);
  1299. $SUDO_OR_NOTHING sed -i -e "s/$i=\(.*\)/$i=$v/" $MARIONNET_DOT_CONF
  1300. done
  1301.  
  1302. if [[ ! -f /etc/marionnet/marionnet.conf ]]; then
  1303.  echo -n "* Installing /etc/marionnet/marionnet.conf ..."
  1304.  $SUDO_OR_NOTHING mkdir -p /etc/marionnet/
  1305.  $SUDO_OR_NOTHING cp $MARIONNET_DOT_CONF /etc/marionnet/
  1306.  echo_at_right_side --newline "ok"
  1307. fi
  1308.  
  1309. # =============================================================
  1310. #                     SysV-style INIT
  1311. # =============================================================
  1312.  
  1313. function generate_the_marionnet_daemon_script {
  1314. local TMPFILE=$(tmpfile)
  1315. cat >$TMPFILE <<EOF
  1316. #!/bin/bash
  1317.  
  1318. # This file was automatically generated by ${0##*/}
  1319.  
  1320. # This file is part of marionnet
  1321. # Copyright (C) 2010 Jean-Vincent Loddo
  1322. #
  1323. # This program is free software: you can redistribute it and/or modify
  1324. # it under the terms of the GNU General Public License as published by
  1325. # the Free Software Foundation, either version 2 of the License, or
  1326. # (at your option) any later version.
  1327. #
  1328. # This program is distributed in the hope that it will be useful,
  1329. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  1330. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  1331. # GNU General Public License for more details.
  1332. #
  1333. # You should have received a copy of the GNU General Public License
  1334. # along with this program.  If not, see <http://www.gnu.org/licenses/>.
  1335.  
  1336. # Very basic init launcher for the marionnet-daemon
  1337.  
  1338. ### BEGIN INIT INFO
  1339. # Provides: marionnet-daemon
  1340. # Required-Start: \$local_fs \$remote_fs \$network
  1341. # Required-Stop:
  1342. # Default-Start: 2 3 4 5
  1343. # Default-Stop: 0 1 6
  1344. # Short-Description: Support daemon for marionnet
  1345. # Description: Support daemon for marionnet
  1346. ### END INIT INFO
  1347.  
  1348. set -e
  1349. PATH=$PREFIX/bin:$PREFIX/sbin:\$PATH
  1350.  
  1351. DAEMON=\$(type -p marionnet-daemon.native || type -p marionnet-daemon.byte) || {
  1352.  echo "Error: neither marionnet-daemon.native nor marionnet-daemon.byte found."
  1353.  exit 1
  1354. }
  1355.  
  1356. function killall_marionnet_daemon {
  1357. ps -u 0 -o pid,cmd | awk '\$2 ~ /marionnet-daemon/ {print \$1}' | while read pid; do kill -9 \$pid; done
  1358. }
  1359.  
  1360. function is_marionnet_daemon_launched {
  1361. ps -u 0 -o cmd | awk '\$1 ~ /marionnet-daemon/ {print \$1}' | grep -q 'marionnet-daemon'
  1362. }
  1363.  
  1364. function pid_of_marionnet_daemon {
  1365. ps -u 0 -o pid,cmd | awk '\$2 ~ /marionnet-daemon/ {print \$1}' | while read pid; do echo \$pid; done
  1366. }
  1367.  
  1368. case "\$1" in
  1369. start)
  1370.  if is_marionnet_daemon_launched; then
  1371.    echo "The marionnet daemon is already launched."
  1372.    exit 0
  1373.  else
  1374.    echo -n "Starting the marionnet daemon..."
  1375.    \$DAEMON >/dev/null 2>/dev/null &
  1376.  fi
  1377.  echo " Ok"
  1378.  ;;
  1379. stop)
  1380.  echo -n "Stopping the marionnet daemon..."
  1381.  killall_marionnet_daemon || true
  1382.  echo " Ok"
  1383.  ;;
  1384. status)
  1385.  if is_marionnet_daemon_launched; then
  1386.    PID=\$(pid_of_marionnet_daemon)
  1387.    echo "The marionnet daemon is running (PID=\$PID)."
  1388.  else
  1389.    echo "The marionnet daemon is stopped."
  1390.  fi
  1391.  exit 0
  1392.  ;;
  1393. *)
  1394.  echo "Usage: $1 (start|stop|status)"
  1395.  echo "Start or stop the marionnet daemon."
  1396.  exit 1
  1397. esac
  1398. EOF
  1399. chmod +x $TMPFILE
  1400. $SUDO_OR_NOTHING mv -f $TMPFILE $1
  1401. }
  1402.  
  1403. function install_the_marionnet_daemon_script {
  1404. # global INIT_DIR
  1405. generate_the_marionnet_daemon_script $INIT_DIR/marionnet-daemon
  1406. local RC_DIRS i
  1407. RC_DIRS=$(for i in /etc/rc[2-5S].d /etc/*/rc[2-5S].d/ /etc/*/*/rc[2-5S].d ; do
  1408.  [[ -d $i ]] && B=$(basename $i) && echo "$B $i $B"
  1409. done | sort -u --key=1,1 | { while read _ b _; do echo $b; done })
  1410.  
  1411. for i in $RC_DIRS; do
  1412. pushd $i
  1413. if [[ "$(realpath ../init.d)" = "$INIT_DIR" ]]; then
  1414.   $SUDO_OR_NOTHING ln -sf ../init.d/marionnet-daemon S90marionnet-daemon
  1415. elif [[ "$(realpath ../../init.d)" = "$INIT_DIR" ]]; then
  1416.   $SUDO_OR_NOTHING ln -sf ../../init.d/marionnet-daemon S90marionnet-daemon
  1417. else
  1418.   $SUDO_OR_NOTHING ln -sf $INIT_DIR/marionnet-daemon S90marionnet-daemon
  1419. fi
  1420. popd
  1421. done 1>&2
  1422. }
  1423.  
  1424. function launch_the_marionnet_daemon_script {
  1425. # global INIT_DIR SUDO_OR_NOTHING
  1426. $SUDO_OR_NOTHING $INIT_DIR/marionnet-daemon start 1>&2
  1427. }
  1428.  
  1429. function define_global_INIT_DIR {
  1430. # global INIT_DIR
  1431. local i j
  1432. if [[ -d /etc/init.d ]]; then
  1433. INIT_DIR=/etc/init.d
  1434. else
  1435. declare -i j
  1436. j=0
  1437. for i in /etc/*/init.d; do
  1438.   [[ -d $i ]] && INIT_DIR=$i && j+=1
  1439. done
  1440. if [[ j != 1 ]]; then unset INIT_DIR; fi
  1441. fi
  1442. }
  1443.  
  1444. define_global_INIT_DIR;
  1445.  
  1446. if [[ -z $INIT_DIR ]]; then
  1447. echo -n "* Installing daemon: directory init.d not found in /etc"
  1448. echo_at_right_side --newline "ko"
  1449. elif [[ -f $INIT_DIR/marionnet-daemon ]]; then
  1450. echo -n "* Installing daemon: script already exists in $INIT_DIR"
  1451. echo_at_right_side --newline "ok"
  1452. else
  1453.  echo "* Installing daemon:"
  1454.  echo -n "  Shall I install the marionnet daemon in your runlevels ([y]/n)? "
  1455.  read z
  1456.  if [[ $z != n && $z != N ]]; then
  1457.    ensure_sudo -p "  Required the [sudo] password for %u:"
  1458.    echo -n "  Installing the marionnet daemon ..."
  1459.    install_the_marionnet_daemon_script
  1460.    [[ -e /dev/net/tun ]] || $SUDO_OR_NOTHING mknod /dev/net/tun c 10 200
  1461.    $SUDO_OR_NOTHING chmod a+rw /dev/net/tun
  1462.    if [[ -f /etc/modules.conf ]]; then
  1463.      append_line_if_needed "alias char-major-10-200 tun" /etc/modules.conf
  1464.      $SUDO_OR_NOTHING depmod -a
  1465.    fi 1>&2
  1466.    echo_at_right_side --newline "ok"
  1467.    echo -n "  Launching the marionnet daemon ..."
  1468.    launch_the_marionnet_daemon_script
  1469.    echo_at_right_side --newline "ok"
  1470.    DAEMON_LAUNCHED=yes
  1471.  fi
  1472. fi
  1473.  
  1474. # =============================================================
  1475. #                     Adjust X -nolisten tcp
  1476. # =============================================================
  1477.  
  1478. function remove_nolisten_assignment_from {
  1479. # global SUDO_OR_NOTHING
  1480. local i=$1
  1481. $SUDO_OR_NOTHING sed -i -e 's/\(^[a-ZA-Z0-9]*[=].*[-]nolisten tcp.*\)$/#\1\n\1/g' $i
  1482. $SUDO_OR_NOTHING sed -i -e 's/\(^[a-ZA-Z0-9]*[=].*\)[-]nolisten tcp\(.*\)$/\1 \2/g' $i
  1483. }
  1484.  
  1485. function remove_nolisten_X_or_startx_actuals_from {
  1486. # global SUDO_OR_NOTHING
  1487. local i=$1
  1488. $SUDO_OR_NOTHING sed -i -e 's/\(^[a-ZA-Z0-9/: ]*X.*\)[-]nolisten tcp\(.*\)$/\1\2/g' $i
  1489. $SUDO_OR_NOTHING sed -i -e 's/\(^[a-ZA-Z0-9/: ]*startx.*\)[-]nolisten tcp\(.*\)$/\1\2/g' $i
  1490. }
  1491.  
  1492. function remove_DisallowTCP_from {
  1493. # global SUDO_OR_NOTHING
  1494. local i=$1
  1495. $SUDO_OR_NOTHING sed -i -e 's/\(^DisallowTCP=true.*\)$/#\1\nDisallowTCP=false/g' $i
  1496. }
  1497.  
  1498. # Sections in file have the form "[security]"
  1499. function ensure_section_and_binding {
  1500. [[ $# -ge 3 ]] || return 1
  1501. local SECTION=$1   # ex: security
  1502. local VARIABLE=$2  # ex: Enable
  1503. local VALUE=$3     # ex: true
  1504. local AWK_PROGRAM
  1505. shift 3
  1506. AWK_PROGRAM="
  1507.   BEGIN {x=0}
  1508.   /\[$SECTION\]/ {x=1;print;next}
  1509.   (x==1) && /$VARIABLE=.*/ {print \"$VARIABLE=$VALUE\"; x=2; next}
  1510.   (x==1) && /\[.*\]/       {print \"$VARIABLE=$VALUE\n\"; print; x=2; next}
  1511.   /\[.*\]/ {print;next}
  1512.   {print}
  1513.   END {if (x==0) print \"[$SECTION]\"; if (x==0 || x==1) print \"$VARIABLE=$VALUE\n\";}"
  1514. case $# in
  1515. 0) awk "$AWK_PROGRAM" ;;
  1516. *)
  1517.  local i
  1518.  local TMPFILE=$(tmpfile)
  1519.  for i in "$@"; do
  1520.    awk 0<"$i" 1>$TMPFILE "$AWK_PROGRAM"
  1521.    cat $TMPFILE 1>"$i"
  1522.  done
  1523.  rm $TMPFILE
  1524.  ;;
  1525. esac
  1526. }
  1527.  
  1528. # This is needed, for instance, for ubuntu 10.10
  1529. function ensure_DisallowTCP_false_to_gdm_custom_dot_conf {
  1530. # global SUDO_OR_NOTHING CHANGED_FILES
  1531. local custom=${1:-/etc/gdm/custom.conf}
  1532. local TMPFILE=$(tmpfile)
  1533. cp $custom $TMPFILE
  1534. ensure_section_and_binding "security" "DisallowTCP" "false" $TMPFILE
  1535. ensure_section_and_binding "xdmcp" "Enable" "true" $TMPFILE
  1536. if ! diff -q $custom $TMPFILE >/dev/null; then
  1537.  CHANGED_FILES+="$custom "
  1538.  $SUDO_OR_NOTHING bash -c "cat $TMPFILE >$custom"
  1539. fi
  1540. }
  1541.  
  1542. # This is needed, for instance, for ubuntu 12.04
  1543. function ensure_xserver_allow_tcp_in_lightdm_dot_conf {
  1544. # global SUDO_OR_NOTHING CHANGED_FILES
  1545. local custom=${1:-/etc/lightdm/lightdm.conf}
  1546. local TMPFILE=$(tmpfile)
  1547. cp $custom $TMPFILE
  1548. ensure_section_and_binding "SeatDefaults" "xserver-allow-tcp" "true" $TMPFILE
  1549. if ! diff -q $custom $TMPFILE >/dev/null; then
  1550.  CHANGED_FILES+="$custom "
  1551.  $SUDO_OR_NOTHING bash -c "cat $TMPFILE >$custom"
  1552. fi
  1553. }
  1554.  
  1555.  
  1556. function apply_all_filters {
  1557. # global CHANGED_FILES
  1558. local i=$1
  1559. cat $i > $BACKUP
  1560. { remove_nolisten_assignment_from $i;
  1561.  remove_DisallowTCP_from $i;
  1562.  remove_nolisten_X_or_startx_actuals_from $i;
  1563.  } || true
  1564. diff -q $BACKUP $i >/dev/null || {
  1565.  CHANGED_FILES+="$i "
  1566.  }
  1567. }
  1568.  
  1569. function adjust_X_display_manager {
  1570. # global SUDO_OR_NOTHING CHANGED_FILES
  1571. local BACKUP=$(tmpfile)
  1572. DIRS=$($SUDO_OR_NOTHING find /etc/ -type d -name "?dm")
  1573. if [[ -d /etc/X11/xinit ]]; then DIRS+=" /etc/X11/xinit/"; fi
  1574. FILES=$([[ -n $DIRS ]] && $SUDO_OR_NOTHING find $DIRS -name "*rc" -o -name "*.conf")
  1575. FILES=$(for i in $FILES; do grep -l "^[a-zA-Z0-9/_\-= ]*[-]nolisten tcp" $i; done)
  1576. for i in $FILES; do apply_all_filters $i; done
  1577. rm -f $BACKUP
  1578. # A special case: gdm/gdm3 :
  1579. if [[ -d /etc/gdm ]]; then
  1580.  $SUDO_OR_NOTHING touch /etc/gdm/custom.conf
  1581.  ensure_DisallowTCP_false_to_gdm_custom_dot_conf
  1582. elif [[ -d /etc/gdm? ]]; then
  1583.  $SUDO_OR_NOTHING touch /etc/gdm?/custom.conf /etc/gdm?/daemon.conf
  1584.  ensure_DisallowTCP_false_to_gdm_custom_dot_conf /etc/gdm?/custom.conf
  1585.  ensure_DisallowTCP_false_to_gdm_custom_dot_conf /etc/gdm?/daemon.conf
  1586. fi
  1587. # Another special case: lightdm
  1588. if [[ -d /etc/lightdm ]]; then
  1589.  $SUDO_OR_NOTHING touch /etc/lightdm/lightdm.conf
  1590.  ensure_xserver_allow_tcp_in_lightdm_dot_conf
  1591. fi
  1592. [[ -n $CHANGED_FILES ]]
  1593. }
  1594.  
  1595. if ps -A -o cmd | grep -q '^[a-zA-Z0-9/]*X.*[-]nolisten tcp'; then
  1596. echo '---'
  1597. echo "* Warning: your X server has been launched with the option '-nolisten tcp'"
  1598. echo "  => This option should be removed from your X display manager configuration."
  1599. echo -n "     Shall I try to fix it ([y]/n)? "
  1600. read z
  1601. if [[ $z != n && $z != N ]]; then
  1602.   if adjust_X_display_manager; then
  1603.     echo "     Ok. File(s) changed: $CHANGED_FILES"
  1604.     echo "     You must restart your X display manager for the changes to take effect."
  1605.   else
  1606.     echo "     Sorry, no change performed: you must edit your configuration manually."
  1607.   fi
  1608. fi
  1609. fi
  1610.  
  1611. # =============================================================
  1612. #                  Fix problems in Ubuntu
  1613. # =============================================================
  1614.  
  1615. if are_we_in_ubuntu_11_or_greater ; then
  1616.  echo "* Warning: Ubuntu (>= 11.x) systems require to launch marionnet with UBUNTU_MENUPROXY=0"
  1617.  echo "  => The problem may be solved defining an alias in your shell configuration:"
  1618.  echo "     alias marionnet='UBUNTU_MENUPROXY=0 marionnet'"
  1619.  case $USER in
  1620.   root)
  1621.     DEST='/etc/profile'
  1622.     echo -n "     Shall I add this line to $DEST ([y]/n)? "
  1623.     ;;
  1624.   *)
  1625.     DEST=~/.bashrc
  1626.     echo -n "     Shall I add this line to your ~/.bashrc ([y]/n)? "
  1627.     ;;
  1628.  esac
  1629.  read z
  1630.  if [[ $z != n && $z != N ]]; then
  1631.    append_line_if_needed "alias marionnet='UBUNTU_MENUPROXY=0 marionnet'" $DEST
  1632.  fi
  1633. fi
  1634.  
  1635. function is_the_packaged_vde2_version_lt_2_3_0 {
  1636. local VDE2_VERSION
  1637. if type 1>&2 aptitude && type 1>&2 vde_switch; then
  1638.   VDE2_VERSION=$(aptitude show vde2 | awk '/^Version.*[2-9][.][0-9][.][0-9].*/ {print $2}' | awk -F '-' '{print $1}')
  1639.   VDE2_VERSION=$(echo $VDE2_VERSION | awk -F '.' '(($2 * 100 + $3 * 10 + $4) <= 230) {print}')
  1640.   [[ -n "$VDE2_VERSION" ]]
  1641. else
  1642.   return 1
  1643. fi
  1644. }
  1645.  
  1646. if are_we_in_ubuntu_12_04 && is_the_packaged_vde2_version_lt_2_3_0; then
  1647.  echo "* Warning: Ubuntu 12.04 systems have an old packaged version of vde2"
  1648.  echo "  => The problem may be solved installing a vde2 backport (Virtualization)"
  1649.  echo "     (see: https://launchpad.net/~pdffs/+archive/precise-virt)"
  1650.  echo -n "     Shall I install the vde2 backport ([y]/n)? "
  1651.  read z
  1652.  if [[ $z != n && $z != N ]]; then
  1653.    launch_and_log --sudo "Installing vde2 backport for Ubuntu 12.04" "add-apt-repository -y ppa:pdffs/precise-virt && aptitude update && aptitude install -y vde2"
  1654.  fi
  1655. fi
  1656.  
  1657. # =============================================================
  1658. #                         Adjust PATH
  1659. # =============================================================
  1660.  
  1661. # Path warning:
  1662. if echo "$PATH_BACKUP" | tr ':' '\n' | grep -q "$PREFIX/bin"; then
  1663. echo "PATH contains $PREFIX/bin. Good." 1>&2
  1664. else
  1665. echo '---'
  1666. echo "* Warning: the path $PREFIX/bin seems not to be contained in your PATH."
  1667. echo "  => Put something like the following line in your shell configuration:"
  1668. echo "     export PATH=$PREFIX/bin:$PREFIX/sbin:\$PATH"
  1669. case $USER in
  1670.   root)
  1671.     DEST='/etc/profile'
  1672.     echo -n "     Shall I add this line to $DEST ([y]/n)? "
  1673.     ;;
  1674.   *)
  1675.     DEST=~/.bashrc
  1676.     echo -n "     Shall I add this line to your ~/.bashrc ([y]/n)? "
  1677.     ;;
  1678. esac
  1679. read z
  1680. if [[ $z != n && $z != N ]]; then
  1681.   append_line_if_needed "export PATH=$PREFIX/bin:$PREFIX/sbin:\$PATH" $DEST
  1682. fi
  1683. fi
  1684.  
  1685.  
  1686. # =============================================================
  1687. #                       Adjust LOCALES
  1688. #     `/usr/share/locale'  vs  `/usr/local/share/locale'
  1689. # =============================================================
  1690.  
  1691. # When PREFIX is set to `/usr/local' ocamlbricks and marionnet install their
  1692. # locale-related files in `$PREFIX/share/locale' (i.e. `/usr/local/share/locale')
  1693. # while some distributions install their locales into `/usr/share/locale'
  1694. # ignoring files installed in `/usr/local/share/locale'
  1695. # (for instance Ubuntu 12.04 LTS 64 bits). So:
  1696. if [[ $PREFIX = "/usr/local" && -d "/usr/share/locale/" && -d "/usr/local/share/locale" ]]; then
  1697. PROBABLY_GOOD="/usr/share/locale/"
  1698. PROBABLY_BAD="/usr/local/share/locale"
  1699. COUNT_GOOD=$(find $PROBABLY_GOOD -type f -name "*.mo" | wc -l)
  1700. COUNT_BAD=$(find $PROBABLY_BAD -type f -name "*.mo" | wc -l)
  1701. # Heuristic method (of course): is $COUNT_GOOD twenty times bigger then $COUNT_BAD?
  1702. if [[ $((COUNT_GOOD/COUNT_BAD)) -gt 20 ]]; then
  1703.  # Move `marionnet.mo' files from $PROBABLY_BAD to $PROBABLY_GOOD:
  1704.  echo -n "* Moving installed locales into $PROBABLY_GOOD"
  1705.  pushd >/dev/null $PROBABLY_BAD
  1706.  find . -name "marionnet.mo" | xargs tar -cf - | $SUDO_OR_NOTHING tar -C $PROBABLY_GOOD -xf -
  1707.  $SUDO_OR_NOTHING find . -name "marionnet.mo" -exec rm {} \;
  1708.  popd >/dev/null
  1709.  echo_at_right_side --newline "ok"
  1710. fi
  1711. fi
  1712.  
  1713. # =============================================================
  1714. #                        64-bit warning
  1715. # =============================================================
  1716.  
  1717. # 64-bit architecture warning:
  1718. if [[ -z $DISABLE_libc6_i386_WARNING ]]; then
  1719. if type uname 1>&2 && [[ $(uname -m) = "x86_64" ]]; then
  1720.  echo '---'
  1721.  echo "* Warning: this is 64-bit architecture."
  1722.  echo "  => Make sure that the package libc6-i386 is installed."
  1723. fi
  1724. fi
  1725.  
  1726. # =============================================================
  1727. #                          Mr Proper
  1728. # =============================================================
  1729.  
  1730. # Mr proper
  1731. echo '---'
  1732. if [[ $KEEP_DEBRIS = yes ]]; then
  1733. echo -n "* Cleaning: $TWDIR not removed (-k)"
  1734. echo_at_right_side --newline "ok"
  1735. else
  1736. echo "* Cleaning..."
  1737. rm -rf $TWDIR
  1738. fi
  1739.  
  1740. # =============================================================
  1741. #                          Notes
  1742. # =============================================================
  1743.  
  1744. # Where to install filesystems and kernels:
  1745. echo '---'
  1746. echo "* Notes:"
  1747. echo "  - Install additional filesystem in" $PREFIX/share/marionnet/filesystems/
  1748. echo "  - Install additional kernels in" $PREFIX/share/marionnet/kernels/
  1749. echo "  - Customize your installation by editing /etc/marionnet/marionnet.conf"
  1750.  
  1751. echo '---'
  1752. echo "Success."
  1753. exit 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement