src/Pure/Tools/phabricator.scala
changeset 71122 730090397e0d
parent 71116 aa1338a778c1
child 71124 7dbadecdc118
equal deleted inserted replaced
71119:30ed6786d775 71122:730090397e0d
    63 
    63 
    64 
    64 
    65   /** global configuration **/
    65   /** global configuration **/
    66 
    66 
    67   val global_config = Path.explode("/etc/" + isabelle_phabricator_name(ext = "conf"))
    67   val global_config = Path.explode("/etc/" + isabelle_phabricator_name(ext = "conf"))
       
    68 
       
    69   def global_config_script(
       
    70     header: Boolean = false,
       
    71     init: String = "",
       
    72     body: String = "",
       
    73     exit: String = ""): String =
       
    74   {
       
    75     (if (header) "#!/bin/bash\n" else "") +
       
    76 """
       
    77 {""" + (if (init.nonEmpty) "\n" + Library.prefix_lines("  ", init) else "") + """
       
    78   while { unset REPLY; read -r; test "$?" = 0 -o -n "$REPLY"; }
       
    79   do
       
    80     NAME="$(echo "$REPLY" | cut -d: -f1)"
       
    81     ROOT="$(echo "$REPLY" | cut -d: -f2)"
       
    82 """ + Library.prefix_lines("    ", body) + """
       
    83   done""" +
       
    84     (if (exit.nonEmpty) "\n" + Library.prefix_lines("  ", exit) else "") + """
       
    85 } < """ + File.bash_path(global_config) + """
       
    86 """
       
    87   }
    68 
    88 
    69   sealed case class Config(name: String, root: Path)
    89   sealed case class Config(name: String, root: Path)
    70   {
    90   {
    71     def home: Path = root + Path.explode(phabricator_name())
    91     def home: Path = root + Path.explode(phabricator_name())
    72 
    92 
   580     }
   600     }
   581 
   601 
   582     progress.echo("Configuring " + ssh_name + " service")
   602     progress.echo("Configuring " + ssh_name + " service")
   583 
   603 
   584     File.write(ssh_command,
   604     File.write(ssh_command,
   585 """#!/bin/bash
   605       global_config_script(
   586 {
   606         header = true,
   587   while { unset REPLY; read -r; test "$?" = 0 -o -n "$REPLY"; }
   607         body =
   588   do
   608 """if [ "$1" = "$NAME" ]
   589     NAME="$(echo "$REPLY" | cut -d: -f1)"
   609 then
   590     ROOT="$(echo "$REPLY" | cut -d: -f2)"
   610   exec "$ROOT/phabricator/bin/ssh-auth" "$@"
   591     if [ "$1" = "$NAME" ]
   611 fi""",
   592     then
   612         exit = "exit 1"))
   593       exec "$ROOT/phabricator/bin/ssh-auth" "$@"
       
   594     fi
       
   595   done
       
   596   exit 1
       
   597 } < /etc/isabelle-phabricator.conf
       
   598 """)
       
   599     Isabelle_System.chmod("755", ssh_command)
   613     Isabelle_System.chmod("755", ssh_command)
   600     Isabelle_System.chown("root:root", ssh_command)
   614     Isabelle_System.chown("root:root", ssh_command)
   601 
   615 
   602     File.write(sshd_conf_server,
   616     File.write(sshd_conf_server,
   603 """# OpenBSD Secure Shell server for Isabelle/Phabricator
   617 """# OpenBSD Secure Shell server for Isabelle/Phabricator