add script for creating VM image

This commit is contained in:
Artur Gurgul1 2025-08-09 18:10:34 +02:00
parent 9c3189544a
commit 75c3228c5e
8 changed files with 196 additions and 2 deletions

7
bin/certbot Executable file
View file

@ -0,0 +1,7 @@
#!/usr/bin/env zsh
export PYTHONPATH="/pkg/certbot/4.2.0/local/lib/python3.11/dist-packages"
export PATH="/pkg/certbot/4.2.0/local/bin:$PATH"
/pkg/certbot/4.2.0/local/bin/certbot

122
bin/make-winux Executable file
View file

@ -0,0 +1,122 @@
#!/usr/bin/env zsh
export LINUX_DISK_IMG=/home/artur/winux/VM/linux/linux.img
export WINUX_DISK_IMG=./winux.img
# Mount the image of oryginal
#
# Mounting the image
function wxumount {
echo "unmounting :$1"
mkdir -p $1
if mountpoint -q $1; then
echo "Unmounting $1..."
umount /mnt/winux
if [ $? -eq 0 ]; then
echo "Successfully unmounted $1."
else
echo "Failed to unmount $1."
fi
else
echo "$1 is not mounted."
fi
}
wxumount /mnt/winux
wxumount /mnt/linux
# (re)create an empty sparsed file
rm -rf $WINUX_DISK_IMG
dd if=/dev/zero of=$WINUX_DISK_IMG bs=1 count=0 seek=20G
# Check size
# real size: du -h winux.img
# appeared as: ls -lh winux.img
# Copy boot
IMG="/home/artur/winux/VM/linux/linux.img"
SECTOR_SIZE=$(LC_ALL=C sfdisk -d "$LINUX_DISK_IMG" | awk 'match($0,/sector-size:\s*([0-9]+)/,m){print m[1]; exit}')
START=$(LC_ALL=C sfdisk -d "$LINUX_DISK_IMG" | awk 'match($0,/start=\s*([0-9]+)/,m){print m[1]; exit}')
echo "Sector size: $SECTOR_SIZE"
echo "Start sector: $START"
dd if="$LINUX_DISK_IMG" of="$WINUX_DISK_IMG" bs="$SECTOR_SIZE" count="$START" conv=notrunc
# Formatting the disk
# No altering the first 1MB
echo '2048,,83,*' | sudo sfdisk --no-reread $WINUX_DISK_IMG
# List all loops: sudo losetup -a
WINUX_LOOP_DEV=$(sudo losetup --find --show $WINUX_DISK_IMG)
# Scan also for partitions: sudo losetup --find --show --partscan winux.img
echo "Loop device: $WINUX_LOOP_DEV"
export WINUX_LOOP_DEV="$(losetup --find --show -P $WINUX_LOOP_DEV)"
mkfs.ext2 ${WINUX_LOOP_DEV}p1
mount ${WINUX_LOOP_DEV}p1 /mnt/winux
## The image is formatted and ready to copy files over
export LINUX_LOOP_DEV="$(losetup --find --show --partscan $LINUX_DISK_IMG)"
mount ${LINUX_LOOP_DEV}p1 /mnt/linux
# copying files
cd /mnt/linux
tar --numeric-owner --xattrs --acls -cpf - \
--exclude='lost+found' \
--exclude='var/log/*' \
--exclude='var/tmp/*' \
--exclude='tmp/*' \
--exclude='var/cache/*' \
--exclude='swapfile' \
--exclude='dev/*' \
--exclude='proc/*' \
--exclude='sys/*' \
--exclude='run/*' \
. | tar --numeric-owner --xattrs --acls -xpf - -C /mnt/winux
#### TESTTING CODE
losetup -j $WINUX_DISK_IMG
# Clean up after building
wxumount /mnt/winux
wxumount /mnt/linux
for dev in $(losetup -j $WINUX_DISK_IMG | cut -d: -f1); do
losetup -d "$dev"
done
for dev in $(losetup -j $LINUX_DISK_IMG | cut -d: -f1); do
losetup -d "$dev"
done
# Create an archive
#
echo "making the archive"
zstd -T0 --ultra -22 winux.img -o winux.img.zst
# decompression with
# unzstd --sparse winux.img.zst
# or
# zstd -d --sparse winux.img.zst -o winux.img

1
bin/use Normal file
View file

@ -0,0 +1 @@
use python 3.11

13
lib/certbot.rb Normal file
View file

@ -0,0 +1,13 @@
module Certbot
def self.create_certificate(domain, wildcard = false)
command = "/home/artur/.dat/bin/certbot"
if wildcard
system "sudo #{command} certonly --manual --preferred-challenges=dns -d \"*.#{domain}\" -d \"#{domain}\""
else
system "sudo #{command} --nginx -d #{domain}"
end
end
end

View file

@ -119,6 +119,13 @@ module Execute
end
end
def domain(name)
require 'certbot'
wildcard = name.strip.start_with?("*.")
domain = name.strip.delete_prefix("*.")
Certbot.create_certificate(domain, wildcard)
end
def user(*users)
require 'user'
users.each do |name|

View file

@ -0,0 +1,21 @@
environment:
PYTHONPATH: /home/artur/test
dependencies:
- python
packages:
- libffi-dev
- libssl-dev
repository:
url: https://github.com/certbot/certbot
branch: v4.2.0
version: 4.2.0
steps:
- $SUDO pip3 install --prefix=$PREFIX certbot
- $SUDO pip3 install --prefix=$PREFIX certbot-nginx
# can be executed like: pip install --prefix=$PREFIX certbot certbot-nginx
# to see installed plugins: `certbot plugins`

View file

@ -14,6 +14,6 @@ repository:
steps:
- ./contrib/download_prerequisites
- ./configure --prefix=$HOME/.local --enable-languages=c,c++ --disable-multilib
- ./configure --prefix=$PREFIX --enable-languages=c,c++ --disable-multilib
- make -j$(nproc)
- make install
- $SUDO make install

23
recipes/nginx/debian.yml Normal file
View file

@ -0,0 +1,23 @@
packages:
- build-essential
- libpcre3
- libpcre3-dev
- zlib1g
- zlib1g-dev
- libssl-dev
repository:
url: https://github.com/nginx/nginx.git
branch: release-1.29.0
version: 1.29.0
build:
- ./configure \|
--prefix=$PREFIX \|
--with-http_ssl_module \|
--with-http_gzip_static_module
--with-stream
--with-http_v2_module
- make
- $SUDO make install