Update portfolio.sh
This commit is contained in:
55
portfolio.sh
55
portfolio.sh
@@ -3,26 +3,21 @@ set -e
|
||||
|
||||
# Configuration
|
||||
CTID=120
|
||||
CTNAME="portfolio-ct"
|
||||
STORAGE="local-lvm"
|
||||
TEMPLATE="local:vztmpl/debian-12-standard_12.7-1_amd64.tar.zst"
|
||||
NET="name=eth0,bridge=vmbr0,ip=dhcp"
|
||||
ROOTFS_SIZE="2" # in GB
|
||||
MEMORY=512
|
||||
CPU_CORES=1
|
||||
HOSTNAME="portfolio"
|
||||
ROOTFS_SIZE="2" # In GB
|
||||
MEM=512
|
||||
CORES=1
|
||||
NETWORK="name=eth0,bridge=vmbr0,ip=dhcp"
|
||||
|
||||
# Repo info
|
||||
REPO="https://git.hzwnrw.my/Resume/Portfolio.git"
|
||||
WWW="/var/www/portfolio"
|
||||
|
||||
# Step 1: Check if container already exists
|
||||
if pct status $CTID &>/dev/null; then
|
||||
echo "❌ Container with CTID $CTID already exists. Delete it first or use a different CTID."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Step 2: Create the container
|
||||
echo "📦 Creating container $CTID..."
|
||||
# Step 1: Create container
|
||||
echo "📦 Creating LXC container with ID ${CTID}..."
|
||||
pct create ${CTID} ${TEMPLATE} \
|
||||
--hostname ${HOSTNAME} \
|
||||
--storage ${STORAGE} \
|
||||
@@ -32,13 +27,13 @@ pct create ${CTID} ${TEMPLATE} \
|
||||
--net0 ${NETWORK} \
|
||||
--unprivileged 0
|
||||
|
||||
# Step 3: Start the container
|
||||
# Step 2: Start container
|
||||
echo "🚀 Starting container..."
|
||||
pct start $CTID
|
||||
pct start ${CTID}
|
||||
|
||||
# Step 4: Install Nginx & Git, clone static repo
|
||||
echo "🔧 Installing Nginx and Git, cloning your static site..."
|
||||
pct exec $CTID -- bash -c "
|
||||
# Step 3: Install Nginx and Git, deploy static site
|
||||
echo "🔧 Installing Nginx and Git..."
|
||||
pct exec ${CTID} -- bash -c "
|
||||
apt update &&
|
||||
apt install -y nginx git &&
|
||||
mkdir -p $WWW &&
|
||||
@@ -46,21 +41,21 @@ pct exec $CTID -- bash -c "
|
||||
rm -f /etc/nginx/sites-enabled/default &&
|
||||
cat > /etc/nginx/sites-available/portfolio <<EOF
|
||||
server {
|
||||
listen 80;
|
||||
server_name _;
|
||||
root $WWW;
|
||||
index index.html;
|
||||
location / {
|
||||
try_files \$uri \$uri/ =404;
|
||||
}
|
||||
listen 80;
|
||||
server_name _;
|
||||
root $WWW;
|
||||
index index.html;
|
||||
location / {
|
||||
try_files \$uri \$uri/ =404;
|
||||
}
|
||||
}
|
||||
EOF
|
||||
ln -s /etc/nginx/sites-available/portfolio /etc/nginx/sites-enabled/portfolio &&
|
||||
nginx -t && systemctl reload nginx
|
||||
ln -s /etc/nginx/sites-available/portfolio /etc/nginx/sites-enabled/ &&
|
||||
nginx -t &&
|
||||
systemctl reload nginx
|
||||
"
|
||||
|
||||
# Step 5: Get container IP
|
||||
IP=$(pct exec $CTID -- ip -4 addr show eth0 | grep -oP '(?<=inet\s)\d+(\.\d+){3}')
|
||||
# Step 4: Show IP
|
||||
IP_ADDRESS=$(pct exec ${CTID} -- bash -c "ip -4 -brief addr show eth0 | awk '{print \$3}' | cut -d/ -f1")
|
||||
echo ""
|
||||
echo "✅ Static portfolio is live!"
|
||||
echo "🌐 Access it at: http://$IP"
|
||||
echo "✅ Portfolio container ready! Visit http://$IP_ADDRESS"
|
||||
|
||||
Reference in New Issue
Block a user