blob: 634449d6f88a6f026fa9fdf50d20a428fd41519a (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
|
#!/bin/bash
# Exit on errors
set -e
# Variables
USER_HOME="/data"
SITE_NAME="stg-jekyll"
BARE_REPO="$USER_HOME/repos/$SITE_NAME.git"
SITE_DIR="$USER_HOME/sites/$SITE_NAME"
PUBLIC_DIR="$SITE_DIR/html"
DOMAIN="sanderstechnologygroup.com"
NGINX_CONF="/etc/nginx/sites-available/$DOMAIN.conf"
# Update and install dependencies
sudo apt update
sudo apt install -y ruby-full build-essential zlib1g-dev git nginx
# Setup Ruby environment in .bashrc if not already present
if ! grep -q 'export GEM_HOME' "$USER_HOME/.bashrc"; then
echo 'export GEM_HOME="$HOME/gems"' >> "$USER_HOME/.bashrc"
echo 'export PATH="$HOME/gems/bin:$PATH"' >> "$USER_HOME/.bashrc"
fi
# Load environment
export GEM_HOME="$USER_HOME/gems"
export PATH="$USER_HOME/gems/bin:$PATH"
# Install Jekyll and Bundler
gem install jekyll bundler
# Create directories
mkdir -p "$BARE_REPO" "$SITE_DIR" "$PUBLIC_DIR"
# Setup Git bare repo
cd "$BARE_REPO"
git init --bare
# Create post-receive hook
cat > hooks/post-receive <<EOF
#!/bin/bash
TARGET_DIR="$SITE_DIR"
PUBLIC_DIR="$PUBLIC_DIR"
export GEM_HOME="$USER_HOME/gems"
export PATH="$USER_HOME/gems/bin:$PATH"
GIT_WORK_TREE="\$TARGET_DIR" git checkout -f
cd "\$TARGET_DIR"
bundle install --path vendor/bundle
bundle exec jekyll build -d "\$PUBLIC_DIR"
EOF
chmod +x hooks/post-receive
# Adjust permissions for NGINX access
chmod o+x "$USER_HOME"
chmod -R o+rX "$PUBLIC_DIR"
# Create NGINX config
sudo tee "$NGINX_CONF" > /dev/null <<EOF
server {
listen 80;
server_name $DOMAIN;
root $PUBLIC_DIR;
index index.html;
location / {
try_files \$uri \$uri.html \$uri/ =404;
}
}
EOF
# Enable NGINX site
sudo ln -s "$NGINX_CONF" /etc/nginx/sites-enabled/
# Test and reload NGINX
sudo nginx -t && sudo systemctl reload nginx
echo "✅ Jekyll site deployment setup complete."
echo "➡️ Push your site with: git remote add live ssh://ben@64.42.180.156/$BARE_REPO && git push live master"
|