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

87 行
2.4KB

  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 $pwuid;
  15. my $admin_un;
  16. my $admin_home_dir;
  17. # Make sure we're running as root
  18. $pwuid = getpwuid( $< );
  19. if($pwuid ne "root"){
  20. die "script must be run as root";
  21. }
  22. # Check /etc/passwd for the username created during
  23. # installation
  24. if( ($admin_un) = `tail /etc/passwd | grep -v "nobody:"` =~ /([^:\n]+):[^:]+:[0-9]{4,}/){
  25. printf("admin user will be set to %s\n", $admin_un);
  26. }else{
  27. die "create a non-root user & set user passsword before running this script."
  28. }
  29. $admin_home_dir = "/home/$admin_un";
  30. # grant doas access to admin user
  31. system("echo 'permit $admin_un' > /etc/doas.conf");
  32. # install git
  33. system("pkg_add git");
  34. chdir $admin_home_dir;
  35. # clone repo
  36. system("su $admin_un -c 'git clone $GIT_REPO'");
  37. chdir $REPO_DIR;
  38. # Copy the skel directory
  39. system("mkdir ./skel/public_html/cgi");
  40. system("cp -r ./skel/* /etc/skel/");
  41. # setup admin user
  42. system("cp -r ./skel/* /home/$admin_un/");
  43. system("chown -R $admin_un:$admin_un /home/$admin_un");
  44. # Setup the virtual environment
  45. system("pkg_add python3");
  46. printf("generating virutal enviornment...\n");
  47. system("su $admin_un -c 'python3 -m venv venv'");
  48. system("su $admin_un -c '. ./venv/bin/activate && pip3 install -r requirements.txt'");
  49. system("pkg_add p5-JSON");
  50. # Install apache
  51. system("pkg_add apache-httpd");
  52. # enable the userdir module
  53. system("sed -i -e 's/^\(.\)*#\(LoadModule userdir_module\)/\1\2/' /etc/apache2/httpd2.conf");
  54. system("sed -i -e 's/^\(.\)*#\(Include \/etc\/apache2\/extra\/httpd-userdir.conf\)/\1\2/' /etc/apache2/httpd2.conf");
  55. # Enable the CGI directory
  56. system("echo '<Directory \"/home/*/public_html/cgi/\">
  57. Require all granted
  58. Options +ExecCGI
  59. AddHandler cgi-script .cgi
  60. </Directory>' >> /etc/apache2/extra/httpd-userdir.conf");
  61. # Enable the CGI modules
  62. system("sed -i -e 's/^\(.\)*#\(LoadModule cgi_module\)/\1\2/' /etc/apache2/httpd2.conf");
  63. system("sed -i -e 's/^\(.\)*#\(LoadModule cgid_module\)/\1\2/' /etc/apache2/httpd2.conf");
  64. # Disable directory listing
  65. system("sed -i -e 's/\(<\/Directory>\)/ Options -Indexes\
  66. \1/g' /etc/apache2/extra/httpd-userdir.conf");
  67. # Change the port to 5001
  68. system("sed -i -e 's/^\(.\)*Listen *80/\1Listen 5001/' /etc/apache2/httpd2.conf");