101 lines
2.6 KiB
Bash
101 lines
2.6 KiB
Bash
#!/bin/bash
|
|
<% local config = require "config" %>
|
|
<% local secrets = require "secrets" %>
|
|
<% local e = require "express" %>
|
|
|
|
exec 1>>~/message.log 2>&1
|
|
set -x
|
|
|
|
echo "Hello, sidecar!" >> ~/message.log
|
|
cd ~
|
|
|
|
sudo yum install certbot cronie httpd mod_ssl gcc -y
|
|
|
|
cat > /etc/httpd/conf.d/ssl.conf<< EOF
|
|
LoadModule ssl_module modules/mod_ssl.so
|
|
|
|
Listen 443
|
|
<VirtualHost *:443>
|
|
ServerName <%- config.domain %>
|
|
SSLEngine on
|
|
SSLCertificateFile "/etc/letsencrypt/live/<%- config.domain %>/fullchain.pem"
|
|
SSLCertificateKeyFile "/etc/letsencrypt/live/<%- config.domain %>/privkey.pem"
|
|
</VirtualHost>
|
|
EOF
|
|
|
|
aws configure set aws_access_key_id "<%- secrets.aws.access_key %>"
|
|
aws configure set aws_secret_access_key "<%- secrets.aws.secret_key %>"
|
|
|
|
# Scripts that start and stop the main instance
|
|
cat > start.sh<< EOF
|
|
EID=\$(aws ec2 describe-instances | jq -r ".Reservations[].Instances[] | select(.Tags[].Value == \"main instance\").InstanceId")
|
|
aws ec2 start-instances --instance-ids \$EID
|
|
EOF
|
|
chmod +x start.sh
|
|
cat > stop.sh<< EOF
|
|
EID=\$(aws ec2 describe-instances | jq -r ".Reservations[].Instances[] | select(.Tags[].Value == \"main instance\").InstanceId")
|
|
aws ec2 stop-instances --instance-ids \$EID
|
|
EOF
|
|
chmod +x stop.sh
|
|
|
|
|
|
# Download the multimc instance from s3
|
|
aws s3 cp s3://<%- config.bucket_name %>/instance.zip .
|
|
unzip instance.zip
|
|
cd instance/.minecraft/mods
|
|
|
|
# Set up mods, shaders, datapacks, ect.
|
|
<% for _, mod in pairs(config.mods.client) do %>
|
|
URL=<%- mod %>
|
|
if [ ! -e $(basename $URL) ]; then
|
|
echo "Downloading $URL"
|
|
curl -JO $URL
|
|
fi
|
|
<% end %>
|
|
|
|
cd ../resourcepacks
|
|
<% for _, resource_pack in pairs(config.resource_packs.client) do %>
|
|
URL=<%- resource_pack %>
|
|
if [ ! -e $(basename $URL) ]; then
|
|
echo "Downloading $URL"
|
|
curl -JO $URL
|
|
fi
|
|
<% end %>
|
|
|
|
cd ../shaderpacks
|
|
<% for _, shader in pairs(config.shaders.client) do %>
|
|
URL=<%- shader %>
|
|
if [ ! -e $(basename $URL) ]; then
|
|
echo "Downloading $URL"
|
|
curl -JO $URL
|
|
fi
|
|
<% end %>
|
|
|
|
cd ../..
|
|
<% for filename, info in pairs(config.config.client) do %>
|
|
<% if e.is_immediate(info) then %>
|
|
aws s3 cp s3://<%- config.bucket_name %>/<%- filename %> <%- filename %>
|
|
<% elseif e.is_command(info) then %>
|
|
|
|
<%- info[1] %>
|
|
|
|
<% end %>
|
|
<% end %>
|
|
|
|
# Then re-zip the instance, and serve a webpage
|
|
cd ~
|
|
zip -r instance instance
|
|
cp instance.zip /var/www/html
|
|
aws s3 cp s3://<%- config.bucket_name %>/data.zip .
|
|
unzip -j -n data.zip -d /var/www/html
|
|
|
|
service httpd start
|
|
systemctl enable httpd
|
|
|
|
# Set up a crontab to start and stop the main server on a schedule
|
|
cat > cronfile <<EOF
|
|
<%- config.server_starts %> /root/start.sh
|
|
<%- config.server_stops %> /root/stop.sh
|
|
EOF
|
|
crontab cronfile
|