scripts and tools to administer the lingy.in public unix / tilde
Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

100 wiersze
2.9KB

  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. system("echo $admin_un >> ./user_list.txt");
  45. # Setup the virtual environment
  46. system("pkg_add python3");
  47. printf("generating virtual enviornment...\n");
  48. system("su $admin_un -c 'python3 -m venv venv'");
  49. system("su $admin_un -c '. ./venv/bin/activate && pip3 install -r requirements.txt'");
  50. system("pkg_add p5-JSON");
  51. # Install apache
  52. system("pkg_add apache-httpd");
  53. printf("configuring apache\n");
  54. # enable the userdir module
  55. system("sed -i -e 's/^\\(.\\)*#\\(LoadModule userdir_module\\)/\\1\\2/' /etc/apache2/httpd2.conf");
  56. system("sed -i -e 's/^\\(.\\)*#\\(Include \\/etc\\/apache2\\/extra\\/httpd-userdir.conf\\)/\\1\\2/' /etc/apache2/httpd2.conf");
  57. # Enable the CGI directory
  58. system("echo '<Directory \"/home/*/public_html/cgi/\">
  59. Require all granted
  60. Options +ExecCGI
  61. AddHandler cgi-script .cgi
  62. </Directory>' >> /etc/apache2/extra/httpd-userdir.conf");
  63. # Enable the CGI modules
  64. system("sed -i -e 's/^\\(.\\)*#\\(LoadModule cgi_module\\)/\\1\\2/' /etc/apache2/httpd2.conf");
  65. system("sed -i -e 's/^\\(.\\)*#\\(LoadModule cgid_module\\)/\\1\\2/' /etc/apache2/httpd2.conf");
  66. # Disable directory listing
  67. system("sed -i -e 's/\\(<\\/Directory>\\)/ Options -Indexes\\
  68. \\1/g' /etc/apache2/extra/httpd-userdir.conf");
  69. # Change the port to 5001
  70. system("sed -i -e 's/^\\(.\\)*Listen *80/\\1Listen 5001/' /etc/apache2/httpd2.conf");
  71. # rev up those apache processes!
  72. system("rcctl start apache2");
  73. # Install and config haproxy
  74. system("pkg_add haproxy");
  75. printf("configuring haproxy\n");
  76. system("cp ./perl-script/conf/haproxy.cfg /etc/haproxy/haproxy.cfg");
  77. system("rcctl start haproxy");
  78. printf("dont forget to setup your ssh pub key at /home/$admin_un/.ssh/authorized_keys\n");