Guest User

tesstttt

a guest
Nov 4th, 2017
978
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 15.94 KB | None | 0 0
  1. #!/bin/bash
  2. ################################################################################
  3. # Author: crombiecrunch
  4. # Credit: appleboy ( appleboy.tw AT gmail.com)
  5. # Web: www.my4x4.club
  6. #
  7. # Program:
  8. # Install Pterodactyl-Panel on Ubuntu
  9. #
  10. ################################################################################
  11.  
  12.  
  13. clear
  14. # get sever os name: ubuntu or centos
  15. server_name=`lsb_release -ds | awk -F ' ' '{printf $1}' | tr A-Z a-z`
  16. version_name=`lsb_release -cs`
  17. usage() {
  18. echo 'Usage: '$0' [-i|--install] [nginx] [apache]'
  19. exit 1;
  20. }
  21.  
  22. output() {
  23. printf "\E[0;33;40m"
  24. echo $1
  25. printf "\E[0m"
  26. }
  27.  
  28. displayErr() {
  29. echo
  30. echo $1;
  31. echo
  32. exit 1;
  33. }
  34. # get user input
  35. server_setup() {
  36. clear
  37. output "Hope you enjoy this install script created by http://www.my4x4.club. Please enter the information below. "
  38. read -p "Enter admin email (e.g. admin@example.com) : " EMAIL
  39. read -p "Enter servername (e.g. portal.example.com) : " SERVNAME
  40. read -p "Enter time zone (e.g. America/New_York) : " TIME
  41. read -p "Portal password : " PORTALPASS
  42. }
  43.  
  44. initial() {
  45. output "Updating all packages"
  46. # update package and upgrade Ubuntu
  47. sudo apt-get -y update
  48. sudo apt-get -y upgrade
  49. sudo apt-get -y autoremove
  50. output "Switching to Aptitude"
  51. sudo apt-get -y install aptitude
  52. sudo aptitude update -y
  53. whoami=`whoami`
  54. }
  55.  
  56. install_nginx() {
  57. output "Installing Nginx server."
  58. sudo aptitude -y install nginx
  59. sudo service nginx start
  60. sudo service cron start
  61. }
  62.  
  63. install_apache() {
  64. output "Installing Apache server."
  65. sudo aptitude -y install apache2
  66. sudo service apache2 start
  67. sudo service cron start
  68. }
  69.  
  70. install_mariadb() {
  71. output "Installing Mariadb Server."
  72. # create random password
  73. rootpasswd=$(openssl rand -base64 12)
  74. export DEBIAN_FRONTEND="noninteractive"
  75. sudo aptitude -y install mariadb-server
  76.  
  77. # adding user to group, creating dir structure, setting permissions
  78. sudo mkdir -p /var/www/pterodactyl/html
  79. sudo chown -R $whoami:$whoami /var/www/pterodactyl/html
  80. sudo chmod -R 775 /var/www/pterodactyl/html
  81. }
  82.  
  83. install_dependencies() {
  84. output "Installing PHP and Dependencies."
  85. sudo aptitude -y install php7.0 php7.0-cli php7.0-gd php7.0-mysql php7.0-common php7.0-mbstring php7.0-tokenizer php7.0-bcmath php7.0-xml php7.0-fpm php7.0-curl
  86. }
  87.  
  88. install_dependencies_apache() {
  89. output "Installing PHP and Dependencies."
  90. sudo aptitude -y install php7.0 php7.0-cli php7.0-gd php7.0-mysql php7.0-common php7.0-mbstring php7.0-tokenizer php7.0-bcmath php7.0-xml php7.0-fpm php7.0-curl libapache2-mod-php
  91. }
  92.  
  93. install_timezone() {
  94. output "Update default timezone."
  95. output "Thanks for using this installation script. Donations welcome PayPal:support@my4x4.club"
  96. # check if link file
  97. sudo [ -L /etc/localtime ] && sudo unlink /etc/localtime
  98. # update time zone
  99. sudo ln -sf /usr/share/zoneinfo/$TIME /etc/localtime
  100. sudo aptitude -y install ntpdate
  101. sudo ntpdate time.stdtime.gov.tw
  102. # write time to clock.
  103. sudo hwclock -w
  104. }
  105.  
  106. server() {
  107. output "Installing Server Packages."
  108. # installing more server files
  109. sudo aptitude -y install curl
  110. sudo aptitude -y install tar
  111. sudo aptitude -y install unzip
  112. sudo aptitude -y install git
  113. sudo aptitude -y install python-pip
  114. pip install --upgrade pip
  115. sudo aptitude -y install supervisor
  116. sudo aptitude -y install make
  117. sudo aptitude -y install g++
  118. sudo aptitude -y install python-minimal
  119. sudo aptitude -y install gcc
  120. sudo aptitude -y install libssl-dev
  121. }
  122.  
  123. pterodactyl() {
  124. output "Install Pterodactyl-Panel."
  125. # Installing the Panel
  126. cd /var/www/pterodactyl/html
  127. curl -Lo v0.5.7.tar.gz https://github.com/Pterodactyl/Panel/archive/develop.zip
  128. sudo chmod -R 777 storage/* bootstrap/cache
  129. curl -sS https://getcomposer.org/installer | sudo php -- --install-dir=/usr/local/bin --filename=composer
  130. composer setup
  131. # create mysql structure
  132. # create database
  133. password=`cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 32 | head -n 1`
  134. Q1="CREATE DATABASE IF NOT EXISTS pterodactyl;"
  135. Q2="GRANT ALL ON *.* TO 'panel'@'localhost' IDENTIFIED BY '$password';"
  136. Q3="FLUSH PRIVILEGES;"
  137. SQL="${Q1}${Q2}${Q3}"
  138.  
  139. sudo mysql -u root -p="" -e "$SQL"
  140.  
  141. output "Database 'pterodactyl' and user 'panel' created with password $password"
  142. }
  143. pterodactyl_1() {
  144. clear
  145. output "Environment Setup"
  146. php artisan pterodactyl:env --dbhost=localhost --dbport=3306 --dbname=pterodactyl --dbuser=panel --dbpass=$password --url=http://$SERVNAME --timezone=$TIME
  147. output "Mail Setup"
  148. # php artisan pterodactyl:mail
  149. output "Database Setup"
  150. php artisan migrate --force
  151. output "Seeding the database"
  152. php artisan db:seed --force
  153. output "Create First User"
  154. php artisan pterodactyl:user --email="$EMAIL" --password=$PORTALPASS --admin=1
  155. sudo service cron restart
  156. sudo service supervisor start
  157.  
  158.  
  159. output "Creating config files"
  160. sudo bash -c 'cat > /etc/supervisor/conf.d/pterodactyl-worker.conf' <<-'EOF'
  161. [program:pterodactyl-worker]
  162. process_name=%(program_name)s_%(process_num)02d
  163. command=php /var/www/pterodactyl/html/artisan queue:work database --queue=high,standard,low --sleep=3 --tries=3
  164. autostart=true
  165. autorestart=true
  166. user=www-data
  167. numprocs=2
  168. redirect_stderr=true
  169. stdout_logfile=/var/www/pterodactyl/html/storage/logs/queue-worker.log
  170. EOF
  171. output "Updating Supervisor"
  172. sudo supervisorctl reread
  173. sudo supervisorctl update
  174. sudo supervisorctl start pterodactyl-worker:*
  175. sudo systemctl enable supervisor.service
  176. }
  177.  
  178. pterodactyl_niginx() {
  179. output "Creating webserver initial config file"
  180. echo '
  181. server {
  182. listen 80;
  183. listen [::]:80;
  184. server_name '"${SERVNAME}"';
  185.  
  186. root "/var/www/pterodactyl/html/public";
  187. index index.html index.htm index.php;
  188. charset utf-8;
  189.  
  190. location / {
  191. try_files $uri $uri/ /index.php?$query_string;
  192. }
  193.  
  194. location = /favicon.ico { access_log off; log_not_found off; }
  195. location = /robots.txt { access_log off; log_not_found off; }
  196.  
  197. access_log off;
  198. error_log /var/log/nginx/pterodactyl.app-error.log error;
  199.  
  200. # allow larger file uploads and longer script runtimes
  201. client_max_body_size 100m;
  202. client_body_timeout 120s;
  203.  
  204. sendfile off;
  205.  
  206. location ~ \.php$ {
  207. fastcgi_split_path_info ^(.+\.php)(/.+)$;
  208. fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
  209. fastcgi_index index.php;
  210. include fastcgi_params;
  211. fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
  212. fastcgi_intercept_errors off;
  213. fastcgi_buffer_size 16k;
  214. fastcgi_buffers 4 16k;
  215. fastcgi_connect_timeout 300;
  216. fastcgi_send_timeout 300;
  217. fastcgi_read_timeout 300;
  218. }
  219.  
  220. location ~ /\.ht {
  221. deny all;
  222. }
  223. location ~ /.well-known {
  224. allow all;
  225. }
  226. }
  227. ' | sudo -E tee /etc/nginx/sites-available/pterodactyl.conf >/dev/null 2>&1
  228.  
  229. sudo ln -s /etc/nginx/sites-available/pterodactyl.conf /etc/nginx/sites-enabled/pterodactyl.conf
  230. output "Install LetsEncrypt and setting SSL"
  231. sudo service nginx restart
  232. sudo aptitude -y install letsencrypt
  233. sudo letsencrypt certonly -a webroot --webroot-path=/var/www/pterodactyl/html/public --email "$EMAIL" --agree-tos -d "$SERVNAME"
  234. sudo rm /etc/nginx/sites-available/pterodactyl.conf
  235. sudo openssl dhparam -out /etc/ssl/certs/dhparam.pem 2048
  236. echo '
  237. server {
  238. listen 80;
  239. listen [::]:80;
  240. server_name '"${SERVNAME}"';
  241. # enforce https
  242. return 301 https://$server_name$request_uri;
  243. }
  244.  
  245. server {
  246. listen 443 ssl http2;
  247. listen [::]:443 ssl http2;
  248. server_name '"${SERVNAME}"';
  249.  
  250. root /var/www/pterodactyl/html/public;
  251. index index.php;
  252.  
  253. access_log /var/log/nginx/pterodactyl.app-accress.log;
  254. error_log /var/log/nginx/pterodactyl.app-error.log error;
  255.  
  256. # allow larger file uploads and longer script runtimes
  257. client_max_body_size 100m;
  258. client_body_timeout 120s;
  259.  
  260. sendfile off;
  261.  
  262. # strengthen ssl security
  263. ssl_certificate /etc/letsencrypt/live/'"${SERVNAME}"'/fullchain.pem;
  264. ssl_certificate_key /etc/letsencrypt/live/'"${SERVNAME}"'/privkey.pem;
  265. ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
  266. ssl_prefer_server_ciphers on;
  267. ssl_session_cache shared:SSL:10m;
  268. ssl_ciphers "EECDH+AESGCM:EDH+AESGCM:ECDHE-RSA-AES128-GCM-SHA256:AES256+EECDH:DHE-RSA-AES128-GCM-SHA256:AES256+EDH:ECDHE-RSA-AES256-GCM-SHA384:DHE-RSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-SHA384:ECDHE-RSA-AES128-SHA256:ECDHE-RSA-AES256-SHA:ECDHE-RSA-AES128-SHA:DHE-RSA-AES256-SHA256:DHE-RSA-AES128-SHA256:DHE-RSA-AES256-SHA:DHE-RSA-AES128-SHA:ECDHE-RSA-DES-CBC3-SHA:EDH-RSA-DES-CBC3-SHA:AES256-GCM-SHA384:AES128-GCM-SHA256:AES256-SHA256:AES128-SHA256:AES256-SHA:AES128-SHA:DES-CBC3-SHA:HIGH:!aNULL:!eNULL:!EXPORT:!DES:!MD5:!PSK:!RC4";
  269. ssl_dhparam /etc/ssl/certs/dhparam.pem;
  270.  
  271. # Add headers to serve security related headers
  272. add_header Strict-Transport-Security "max-age=15768000; preload;";
  273. add_header X-Content-Type-Options nosniff;
  274. add_header X-XSS-Protection "1; mode=block";
  275. add_header X-Robots-Tag none;
  276. add_header Content-Security-Policy "frame-ancestors 'self'";
  277.  
  278. location / {
  279. try_files $uri $uri/ /index.php?$query_string;
  280. }
  281.  
  282. location ~ \.php$ {
  283. fastcgi_split_path_info ^(.+\.php)(/.+)$;
  284. fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
  285. fastcgi_index index.php;
  286. include fastcgi_params;
  287. fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
  288. fastcgi_intercept_errors off;
  289. fastcgi_buffer_size 16k;
  290. fastcgi_buffers 4 16k;
  291. fastcgi_connect_timeout 300;
  292. fastcgi_send_timeout 300;
  293. fastcgi_read_timeout 300;
  294. include /etc/nginx/fastcgi_params;
  295. }
  296.  
  297. location ~ /\.ht {
  298. deny all;
  299. }
  300. }
  301. ' | sudo -E tee /etc/nginx/sites-available/pterodactyl.conf >/dev/null 2>&1
  302.  
  303. sudo service nginx restart
  304. }
  305.  
  306. pterodactyl_apache() {
  307. output "Creating webserver initial config file"
  308. echo '
  309. <VirtualHost *:80>
  310. ServerName '"${SERVNAME}"'
  311. DocumentRoot "/var/www/pterodactyl/html/public"
  312. AllowEncodedSlashes On
  313. <Directory "/var/www/pterodactyl/html/public">
  314. AllowOverride all
  315. </Directory>
  316. </VirtualHost>
  317. ' | sudo -E tee /etc/apache2/sites-available/pterodactyl.conf >/dev/null 2>&1
  318.  
  319. sudo ln -s /etc/apache2/sites-available/pterodactyl.conf /etc/apache2/sites-enabled/pterodactyl.conf
  320. sudo a2enmod rewrite
  321. sudo service apache2 restart
  322. output "Install LetsEncrypt and setting SSL"
  323. sudo aptitude -y install letsencrypt
  324. sudo letsencrypt certonly -a webroot --webroot-path=/var/www/pterodactyl/html/public --email $EMAIL --agree-tos -d $SERVNAME
  325.  
  326. echo '
  327. <VirtualHost *:80>
  328. ServerName '"${SERVNAME}"'
  329. DocumentRoot "/var/www/pterodactyl/html/public"
  330. AllowEncodedSlashes On
  331. <Directory "/var/www/pterodactyl/html/public">
  332. AllowOverride all
  333. </Directory>
  334. </VirtualHost>
  335. NameVirtualHost *:443
  336. <VirtualHost *:443>=
  337. DocumentRoot "/var/www/pterodactyl/html/public"
  338. ServerName '"${SERVNAME}"'
  339. <Directory "/var/www/pterodactyl/html/public">
  340. AllowOverride all
  341. </Directory>
  342. SSLEngine on
  343. SSLCertificateFile /etc/letsencrypt/live/'"${SERVNAME}"'/cert.pem
  344. SSLCertificateKeyFile /etc/letsencrypt/live/'"${SERVNAME}"'/privkey.pem
  345. SSLCertificateChainFile /etc/letsencrypt/live/'"${SERVNAME}"'/fullchain.pem
  346. </VirtualHost>
  347. ' | sudo -E tee /etc/apache2/sites-available/pterodactyl_ssl.conf >/dev/null 2>&1
  348. sudo ln -s /etc/apache2/sites-available/pterodactyl_ssl.conf /etc/apache2/sites-enabled/pterodactyl_ssl.conf
  349. sudo a2enmod ssl
  350. sudo service apache2 restart
  351. }
  352.  
  353. pterodactyl_daemon() {
  354. output "Installing the daemon now! Almost done!!"
  355. sudo aptitude -y install linux-image-extra-$(uname -r) linux-image-extra-virtual
  356. sudo aptitude update -y
  357. sudo aptitude upgrade -y
  358. curl -sSL https://get.docker.com/ | sh
  359. sudo usermod -aG docker $whoami
  360. sudo systemctl enable docker
  361. output "Installing Nodejs"
  362. curl -sL https://deb.nodesource.com/setup_6.x | sudo -E bash -
  363. sudo aptitude -y install nodejs
  364. output "Making sure we didnt miss any dependencies "
  365. sudo aptitude -y install tar unzip make gcc g++ python-minimal
  366. output "Ok really installing the daemon files now"
  367. sudo mkdir -p /srv/daemon /srv/daemon-data
  368. sudo chown -R $whoami:$whoami /srv/daemon
  369. cd /srv/daemon
  370. curl -Lo v0.3.7.tar.gz https://github.com/Pterodactyl/Daemon/archive/v0.3.7.tar.gz
  371. tar --strip-components=1 -xzvf v0.3.7.tar.gz
  372. npm install --only=production
  373.  
  374. output "This step requires you to create your first node through your panel, only continue after you get your core code"
  375. output "Paste the code in the file and then hit CTRL + o then CTRL + x."
  376. read -p "Press enter to continue" nothing
  377. sudo nano /srv/daemon/config/core.json
  378. sudo bash -c 'cat > /etc/systemd/system/wings.service' <<-EOF
  379. [Unit]
  380. Description=Pterodactyl Wings Daemon
  381. After=docker.service
  382.  
  383. [Service]
  384. User=root
  385. #Group=some_group
  386. WorkingDirectory=/srv/daemon
  387. LimitNOFILE=4096
  388. PIDFile=/var/run/wings/daemon.pid
  389. ExecStart=/usr/bin/node /srv/daemon/src/index.js
  390. Restart=on-failure
  391. StartLimitInterval=600
  392.  
  393. [Install]
  394. WantedBy=multi-user.target
  395. EOF
  396.  
  397. sudo systemctl daemon-reload
  398. sudo systemctl enable wings
  399. sudo systemctl start wings
  400. sudo service wings start
  401.  
  402. sudo usermod -aG www-data $whoami
  403. sudo chown -R www-data:www-data /var/www/pterodactyl/html
  404. sudo chown -R www-data:www-data /srv/daemon
  405. sudo chmod -R 775 /var/www/pterodactyl/html
  406. sudo chmod -R 775 /srv/daemon
  407. echo '
  408. [client]
  409. user=root
  410. password='"${rootpasswd}"'
  411. [mysql]
  412. user=root
  413. password='"${rootpasswd}"'
  414. ' | sudo -E tee ~/.my.cnf >/dev/null 2>&1
  415. sudo chmod 0600 ~/.my.cnf
  416. output "Setting mysql root password"
  417. sudo mysqladmin -u root password $rootpasswd
  418. (crontab -l ; echo "* * * * * php /var/www/pterodactyl/html/artisan schedule:run >> /dev/null 2>&1")| crontab -
  419.  
  420. output "Please reboot your server to apply new permissions"
  421.  
  422.  
  423. }
  424.  
  425. # Process command line...
  426. while [ $# -gt 0 ]; do
  427. case $1 in
  428. --help | -h)
  429. usage $0
  430. ;;
  431. --install | -i)
  432. shift
  433. action=$1
  434. shift
  435. ;;
  436. *)
  437. usage $0
  438. ;;
  439. esac
  440. done
  441. test -z $action && usage $0
  442. case $action in
  443. "nginx")
  444. server_setup
  445. initial
  446. install_nginx
  447. install_mariadb
  448. install_dependencies
  449. install_timezone
  450. server
  451. pterodactyl
  452. pterodactyl_1
  453. pterodactyl_niginx
  454. pterodactyl_daemon
  455. ;;
  456. "apache")
  457. server_setup
  458. initial
  459. install_apache
  460. install_mariadb
  461. install_dependencies_apache
  462. install_timezone
  463. server
  464. pterodactyl
  465. pterodactyl_1
  466. pterodactyl_apache
  467. pterodactyl_daemon
  468. ;;
  469. *)
  470. usage $0
  471. ;;
  472. esac
  473. exit 1;
Add Comment
Please, Sign In to add comment