src/Pure/Tools/phabricator.scala
changeset 71266 8451c86ffa85
parent 71265 6ca561001244
child 71268 e2fb60756fb8
equal deleted inserted replaced
71265:6ca561001244 71266:8451c86ffa85
   281 """)
   281 """)
   282 
   282 
   283     Linux.service_restart("mysql")
   283     Linux.service_restart("mysql")
   284 
   284 
   285 
   285 
   286     def mysql_conf(R: Regex): Option[String] =
   286     def mysql_conf(R: Regex, which: String): String =
   287       split_lines(File.read(Path.explode("/etc/mysql/debian.cnf"))).collectFirst({ case R(a) => a })
   287     {
   288 
   288       val conf = Path.explode("/etc/mysql/debian.cnf")
   289     for (user <- mysql_conf("""^user\s*=\s*(\S*)\s*$""".r)) {
   289       split_lines(File.read(conf)).collectFirst({ case R(a) => a }) match {
   290       config.execute("config set mysql.user " + Bash.string(user))
   290         case Some(res) => res
   291     }
   291         case None => error("Cannot determine " + which + " from " + conf)
   292 
   292       }
   293     for (pass <- mysql_conf("""^password\s*=\s*(\S*)\s*$""".r)) {
   293     }
   294       config.execute("config set mysql.pass " + Bash.string(pass))
   294 
   295     }
   295     val mysql_root_user = mysql_conf("""^user\s*=\s*(\S*)\s*$""".r, "superuser name")
   296 
   296     val mysql_root_password = mysql_conf("""^password\s*=\s*(\S*)\s*$""".r, "superuser password")
   297     config.execute("config set storage.default-namespace " +
   297 
   298       Bash.string(phabricator_name(name = name).replace("-", "_")))
   298     val mysql_name = phabricator_name(name = name).replace("-", "_")
   299 
   299     val mysql_user_string = SQL.string(mysql_name) + "@'localhost'"
       
   300     val mysql_password = Linux.generate_password()
       
   301 
       
   302     Isabelle_System.bash("mysql --user=" + Bash.string(mysql_root_user) +
       
   303       " --password=" + Bash.string(mysql_root_password) + " --execute=" +
       
   304       Bash.string(
       
   305         """CREATE USER IF NOT EXISTS """ + mysql_user_string +
       
   306         """ IDENTIFIED BY """ + SQL.string(mysql_password) + """ PASSWORD EXPIRE NEVER; """ +
       
   307         """GRANT ALL ON `""" + (mysql_name + "_%").replace("_", "\\_") +
       
   308         """`.* TO """ + mysql_user_string + ";")).check
       
   309 
       
   310     config.execute("config set mysql.user " + Bash.string(mysql_name))
       
   311     config.execute("config set mysql.pass " + Bash.string(mysql_password))
       
   312 
       
   313     config.execute("config set phabricator.cache-namespace " + Bash.string(mysql_name))
       
   314     config.execute("config set storage.default-namespace " + Bash.string(mysql_name))
   300     config.execute("config set storage.mysql-engine.max-size 8388608")
   315     config.execute("config set storage.mysql-engine.max-size 8388608")
   301 
   316 
   302     progress.bash("bin/storage upgrade --force", cwd = config.home.file, echo = true).check
   317     progress.bash("bin/storage upgrade --force", cwd = config.home.file, echo = true).check
   303 
   318 
   304 
   319