scripts and tools to administer the lingy.in public unix / tilde
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

109 行
3.1KB

  1. #!/usr/bin/perl
  2. use warnings;
  3. use strict;
  4. # provision.pl
  5. # script to provision a tilde instance
  6. #
  7. # This script is intended to be run on a fresh
  8. # OpenBSD install
  9. #
  10. # gashapwn
  11. # Nov 2020
  12. my $GIT_REPO = 'https://git.lain.church/gashapwn/lyadmin.git';
  13. my ($REPO_DIR) = $GIT_REPO =~ /\/([^\/]*)\.git$/;
  14. my $INST_DIR = "/tilde";
  15. my $SVC_ACCT = "lingyind";
  16. my $pwuid;
  17. my $admin_un;
  18. my $admin_home_dir;
  19. # Make sure we're running as root
  20. $pwuid = getpwuid( $< );
  21. if($pwuid ne "root"){
  22. die "script must be run as root";
  23. }
  24. # Check /etc/passwd for the username created during
  25. # installation
  26. if( ($admin_un) = `tail /etc/passwd | grep -v "nobody:"` =~ /([^:\n]+):[^:]+:[0-9]{4,}/){
  27. printf("admin user will be set to %s\n", $admin_un);
  28. }else{
  29. die "create a non-root user & set user passsword before running this script."
  30. }
  31. $admin_home_dir = "/home/$admin_un";
  32. # grant doas access to admin user
  33. system("echo 'permit $admin_un' > /etc/doas.conf");
  34. # install git
  35. system("pkg_add git");
  36. # Setup install dir
  37. system("mkdir $INST_DIR");
  38. system("useradd -d $INST_DIR -r 100..900 $SVC_ACCT");
  39. system("chown $SVC_ACCT:$SVC_ACCT $INST_DIR");
  40. chdir $INST_DIR;
  41. # clone repo
  42. system("su $SVC_ACCT -c 'git clone $GIT_REPO'");
  43. chdir $REPO_DIR;
  44. # Copy the skel directory
  45. system("mkdir ./skel/public_html/cgi");
  46. system("cp -r ./skel/* /etc/skel/");
  47. # setup admin user
  48. system("cp -r ./skel/* /home/$admin_un/");
  49. system("chown -R $admin_un:$admin_un /home/$admin_un");
  50. system("echo $admin_un >> ./user_list.txt");
  51. # Setup the virtual environment
  52. system("pkg_add python3");
  53. printf("generating virtual enviornment...\n");
  54. system("su $SVC_ACCT -c 'python3 -m venv venv'");
  55. system("su $SVC_ACCT -c '. ./venv/bin/activate && pip3 install -r requirements.txt'");
  56. system("pkg_add p5-JSON");
  57. # Install apache
  58. system("pkg_add apache-httpd");
  59. printf("configuring apache\n");
  60. # enable the userdir module
  61. system("sed -i -e 's/^\\(.\\)*#\\(LoadModule userdir_module\\)/\\1\\2/' /etc/apache2/httpd2.conf");
  62. system("sed -i -e 's/^\\(.\\)*#\\(Include \\/etc\\/apache2\\/extra\\/httpd-userdir.conf\\)/\\1\\2/' /etc/apache2/httpd2.conf");
  63. # Enable the CGI directory
  64. system("echo '<Directory \"/home/*/public_html/cgi/\">
  65. Require all granted
  66. Options +ExecCGI
  67. AddHandler cgi-script .cgi
  68. </Directory>' >> /etc/apache2/extra/httpd-userdir.conf");
  69. # Enable the CGI modules
  70. system("sed -i -e 's/^\\(.\\)*#\\(LoadModule cgi_module\\)/\\1\\2/' /etc/apache2/httpd2.conf");
  71. system("sed -i -e 's/^\\(.\\)*#\\(LoadModule cgid_module\\)/\\1\\2/' /etc/apache2/httpd2.conf");
  72. # Disable directory listing
  73. system("sed -i -e 's/\\(<\\/Directory>\\)/ Options -Indexes\\
  74. \\1/g' /etc/apache2/extra/httpd-userdir.conf");
  75. # Change the port to 5001
  76. system("sed -i -e 's/^\\(.\\)*Listen *80/\\1Listen 5001/' /etc/apache2/httpd2.conf");
  77. # rev up those apache processes!
  78. system("rcctl start apache2");
  79. # Install and config haproxy
  80. system("pkg_add haproxy");
  81. printf("configuring haproxy\n");
  82. system("cp ./perl-script/conf/haproxy.cfg /etc/haproxy/haproxy.cfg");
  83. system("rcctl start haproxy");
  84. printf("dont forget to setup your ssh pub key at /home/$admin_un/.ssh/authorized_keys\n");