diff --git a/LICENSE b/LICENSE index 74984cb..2ae2f2f 100644 --- a/LICENSE +++ b/LICENSE @@ -1,4 +1,4 @@ -Copyright (c) 2023 Samuel 'sk4nz' AUBERTIN sk4nz@www.sk4.nz +Copyright (c) 2023 Samuel 'sk4nz' AUBERTIN sk4nz@sk4.nz Permission to use, copy, modify, and distribute this software for any purpose with or without fee is hereby granted, provided that the above diff --git a/Makefile b/Makefile index 5603aed..1f82a30 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,3 @@ OPACK_TARGET= demo -OPACK_SYS_HEADLESS= false - +OPACK_SYS_HEADLESS= false include src/opack.mk - -all: opack - diff --git a/README.md b/README.md index 0bb23af..1480723 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,12 @@ -# skz-opack -Sk4nZ OpenBSD Packer + ██████ ██ ▄█▀▒███████▒ ▒█████ ██▓███ ▄▄▄ ▄████▄ ██ ▄█▀ + ▒██ ▒ ██▄█▒ ▒ ▒ ▒ ▄▀░ ▒██▒ ██▒▓██░ ██ ▒████▄ ▒██▀ ▀█ ██▄█▒ + ░ ▓██▄ ▓███▄░ ░ ▒ ▄▀▒ ▓▒█ ▒██░ ██▒▓██░ ██▓▒▒██ ▀█▄ ▒▓█ ▄ ▓███▄░ + ▒ ██▒▓██ █▄ ▄▀▒ ░▒ ▒██ ██░▒██▄█▓▒ ▒░██▄▄▄▄██ ▒▓▓▄ ▄██▒▓██ █▄ + ▒██████▒▒▒██▒ █▄▒███████▒░ ████▓▒░▒██▒ ░ ░ ▓█ ▓██▒▒ ▓███▀ ░▒██▒ █▄ + ▒ ▒▓▒ ▒ ░▒ ▒▒ ▓▒░▒▒ ▓░▒░▒░ ░ ▒░▒░▒░ ▒▓▒░ ░ ░ ▒▒ ▓▒█░░ ░▒ ▒ ░▒ ▒▒ ▓▒ + ░ ░▒ ░ ░░ ░▒ ▒░░░ https://git.sk4.nz/sk4nz/skz-opack ▒▒ ░ ░ ▒ ░ ░▒ ▒░ + ░ ░ ░ ░ ░ ░ ░ ░ ░░ ░ ░ ░ + ░ ░ ----- *Samuel 'sk4nz' AUBERTIN* @@ -28,8 +35,10 @@ To get started with **skz-opack**, follow these steps: ## Available make targets Available make target are: - `opack` -- `clean` -- `cleancache` +- `opack-cloud` +- `opack-clean` +- `opack-cleancache` +- `opack-cleanall` ## Examples ### Quick example diff --git a/TODOs b/TODOs deleted file mode 100644 index 94b8970..0000000 --- a/TODOs +++ /dev/null @@ -1,8 +0,0 @@ -tests: -local - -gcp - -dependencies: -vagrant -libvirt ? diff --git a/src/opack.mk b/src/opack.mk index 1cee610..e3ac6f1 100644 --- a/src/opack.mk +++ b/src/opack.mk @@ -1,16 +1,22 @@ .PHONY: clean cleancache cleanall opack .DEFAULT_GOAL := opack - OPACK_DIR := $(dir $(abspath $(lastword $(MAKEFILE_LIST)))) define OPACK_BANNER -________ __ -\_____ \ ___________ ____ | | __ - / | \\____ \__ \ _/ ___\| |/ / -/ | \ |_> > __ \\ \___| < -\_______ / __(____ /\___ >__|_ \ - \/|__| \/ \/ \/ + ██████ ██ ▄█▀▒███████▒ ▒█████ ██▓███ ▄▄▄ ▄████▄ ██ ▄█▀ + ▒██ ▒ ██▄█▒ ▒ ▒ ▒ ▄▀░ ▒██▒ ██▒▓██░ ██ ▒████▄ ▒██▀ ▀█ ██▄█▒ + ░ ▓██▄ ▓███▄░ ░ ▒ ▄▀▒ ▓▒█ ▒██░ ██▒▓██░ ██▓▒▒██ ▀█▄ ▒▓█ ▄ ▓███▄░ + ▒ ██▒▓██ █▄ ▄▀▒ ░▒ ▒██ ██░▒██▄█▓▒ ▒░██▄▄▄▄██ ▒▓▓▄ ▄██▒▓██ █▄ + ▒██████▒▒▒██▒ █▄▒███████▒░ ████▓▒░▒██▒ ░ ░ ▓█ ▓██▒▒ ▓███▀ ░▒██▒ █▄ + ▒ ▒▓▒ ▒ ░▒ ▒▒ ▓▒░▒▒ ▓░▒░▒░ ░ ▒░▒░▒░ ▒▓▒░ ░ ░ ▒▒ ▓▒█░░ ░▒ ▒ ░▒ ▒▒ ▓▒ + ░ ░▒ ░ ░░ ░▒ ▒░░░ https://git.sk4.nz/sk4nz/skz-opack ▒▒ ░ ░ ▒ ░ ░▒ ▒░ + ░ ░ ░ ░ ░ ░ ░ ░ ░░ ░ ░ ░ + ░ ░ +endef +define spinner +echo -n "$(2) " +($(1)) & pid=$$!; i=0; while ps -a | awk '{print $$1}' | grep -q "$${pid}"; do c=`expr $${i} % 4`; case $${c} in 0) echo -e "◐\c" ;; 1) echo -e "◓\c" ;; 2) echo -e "◑\c" ;; 3) echo -e "◒\c" ;; esac; i=`expr $${i} + 1`; sleep 0.2; echo -e "\b\c"; done; echo; wait $${pid}; ret=$$?; exit $${ret}; endef $(info $(OPACK_BANNER)) @@ -21,6 +27,7 @@ include $(OPACK_DIR)/packerfile.mk include $(OPACK_DIR)/packerfile-gcp.mk include $(OPACK_DIR)/vagrantfile.mk + $(OPACK_PACKER_HTTP_DIR) $(OPACK_PACKER_DIR) ../$(OPACK_CACHE_DIR): @mkdir -p $@ @@ -54,25 +61,21 @@ $(OPACK_PROVISION_FILE): @echo you need to write $@ && exit 1 ../id_ed25519: - @echo you need to generate the ssh key with 'make sshkey' && exit 1 + @ssh-keygen -q -t ed25519 -f $@ -N '""' $(OPACK_BOX_FILE): | $(OPACK_PACKER_DIR)/opack.json $(OPACK_PACKER_DIR)/vagrant.key $(OPACK_PROVISION_FILE) $(OPACK_PACKER_HTTP_DIR)/install.conf $(OPACK_PACKER_HTTP_DIR)/autodisklabel - @cd $(OPACK_PACKER_DIR) &&\ - CHECKPOINT_DISABLE=1 PACKER_CACHE_DIR=../../$(OPACK_CACHE_DIR)\ - packer build\ - -timestamp-ui opack.json &&\ - rm -rf $(OPACK_PACKER_DIR) + @$(call spinner,cd $(OPACK_PACKER_DIR) && CHECKPOINT_DISABLE=1 PACKER_CACHE_DIR=../../$(OPACK_CACHE_DIR) packer build -timestamp-ui opack.json > opack.log || echo Error Autoinstalling: check $(OPACK_PACKER_DIR)/opack.log,█ Autoinstalling $(OPACK_BOX_TAG) with Packer) $(OPACK_META_FILE): $(OPACK_BOX_FILE) @printf '$(subst $(OPACK_BOX_FILE_SHA256),$(shell sha256sum $(OPACK_BOX_FILE) | awk '{print $$1}'),$(subst $(newline),\n,$(OPACK_METADATA_CONTENT)))' > $@ - @vagrant box add -f --name $(OPACK_BOX_TAG) $(OPACK_META_FILE) + @$(call spinner,vagrant box add -f --name $(OPACK_BOX_TAG) $(OPACK_META_FILE) > /dev/null,█ Adding $(OPACK_BOX_FILE) to Vagrant) $(OPACK_VAGRANT_FILE): @printf '$(subst $(newline),\n,$(OPACK_VAGRANT_CONTENT))' > $@ opack: $(OPACK_META_FILE) $(OPACK_VAGRANT_FILE) - @vagrant up + @$(call spinner,vagrant up > /dev/null,█ Starting $(OPACK_HOSTNAME)-$(OPACK_TARGET) with Vagrant) opack-cloud: | $(OPACK_PACKER_DIR)/opack-cloud.json ../id_ed25519 $(OPACK_PROVISION_FILE) $(OPACK_PACKER_HTTP_DIR)/install.conf $(OPACK_PACKER_HTTP_DIR)/autodisklabel @cd $(OPACK_PACKER_DIR) &&\ @@ -81,13 +84,10 @@ opack-cloud: | $(OPACK_PACKER_DIR)/opack-cloud.json ../id_ed25519 $(OPACK_PROVIS -timestamp-ui opack-cloud.json | tee -a ../$@ &&\ rm -rf $(OPACK_PACKER_DIR) -clean: - @-vagrant destroy -f 2>/dev/null - @-cd terraform_??????? 2>/dev/null && terraform destroy -auto-approve && cd .. && rm -rf terraform_??????? - @-rm -rf $(OPACK_VAGRANT_FILE) opack_build_$(OPACK_SHORT_REV) *.log ssh-config .vagrant *.json +opack-clean: + @-$(call spinner,vagrant destroy -f >/dev/null; cd terraform_??????? 2>/dev/null && terraform destroy -auto-approve && cd .. && rm -rf terraform_???????; rm -rf $(OPACK_VAGRANT_FILE) opack_build_$(OPACK_SHORT_REV) *.log ssh-config .vagrant *.json,█ Cleaning up) -cleancache: - @-vagrant box remove -f --all $(OPACK_BOX_TAG) 2>/dev/null - @-rm -rf $(OPACK_CACHE_DIR) +opack-cleancache: + @-$(call spinner,vagrant box remove -f --all $(OPACK_BOX_TAG) 2>/dev/null; rm -rf $(OPACK_CACHE_DIR),█ Cleaning up cache) -cleanall: clean cleancache +opack-cleanall: clean cleancache diff --git a/src/options.mk b/src/options.mk index fe30181..b007366 100644 --- a/src/options.mk +++ b/src/options.mk @@ -1,5 +1,5 @@ -OPACK_DEBUG=yes # Enable debugging mode if OPACK_DEBUG is set to 'yes' +OPACK_DEBUG=yes ifndef OPACK_DEBUG .SILENT: @@ -7,38 +7,39 @@ $(info OPACK_DEBUG) else endif -OPACK_SYS_HOSTNAME?= opack # Set the hostname of the virtual machine to 'opack' if not specified +OPACK_SYS_HOSTNAME?= opack -OPACK_SYS_USER?= opack # Set the username for the virtual machine to 'opack' if not specified +OPACK_SYS_USER?= opack -OPACK_SYS_PASSWORD?= opack # Set the password for the virtual machine to 'opack' if not specified +OPACK_SYS_PASSWORD?= opack -OPACK_SYS_DISK_SIZE?= 4096 # Set the disk size of the virtual machine to 4096 MB if not specified +OPACK_SYS_DISK_SIZE?= 4096 -OPACK_SYS_MEMORY?= 512 # Set the memory (RAM) size of the virtual machine to 512 MB if not specified +OPACK_SYS_MEMORY?= 512 -OPACK_SYS_CPU?= 1 # Set the number of CPUs for the virtual machine to 1 if not specified +OPACK_SYS_CPU?= 1 -OPACK_SYS_SERVER?=cdn.openbsd.org # Set the OpenBSD package server to 'cdn.openbsd.org' if not specified +OPACK_SYS_SERVER?=cdn.openbsd.org -OPACK_SYS_ARCHITECTURE?=amd64 # Set the architecture for the virtual machine to 'amd64' if not specified +OPACK_SYS_ARCHITECTURE?=amd64 -OPACK_SYS_RELEASE?=$(shell basename -s .html $(shell curl -s https://www.openbsd.org/ | grep released | cut -d '"' -f 2)) # Automatically determine the OpenBSD release based on the OpenBSD website +OPACK_SYS_RELEASE?=$(shell basename -s .html $(shell curl -s https://www.openbsd.org/ | grep released | cut -d '"' -f 2)) +# Extract major and minor version components from the release and construct the version string OPACK_SYS_VERSION_MAJOR=$(shell echo $(OPACK_SYS_RELEASE) | cut -c 1) OPACK_SYS_VERSION_MINOR=$(shell echo $(OPACK_SYS_RELEASE) | cut -c 2) OPACK_SYS_VERSION?=$(OPACK_SYS_VERSION_MAJOR).$(OPACK_SYS_VERSION_MINOR) -# Extract major and minor version components from the release and construct the version string +# Check if the OpenBSD version is 'snapshots' and automatically increment it if needed ifeq ($(OPACK_SYS_VERSION), snapshots) ifeq ($(shell (curl -s https://$(OPACK_SYS_SERVER)/pub/OpenBSD/snapshots/$(OPACK_SYS_ARCHITECTURE)/SHA256 | grep cd$(OPACK_SYS_RELEASE).iso > /dev/null && echo OK) || echo KO), KO) $(eval OPACK_SYS_RELEASE=$(shell echo $$(($(OPACK_SYS_RELEASE)+1)))) @@ -46,83 +47,91 @@ OPACK_SYS_VERSION_MAJOR=$(shell echo $(OPACK_SYS_RELEASE) | cut -c 1) OPACK_SYS_VERSION_MINOR=$(shell echo $(OPACK_SYS_RELEASE) | cut -c 2) endif endif -# Check if the OpenBSD version is 'snapshots' and automatically increment it if needed -OPACK_SYS_XENOCARA?=no # Set whether to include Xenocara (X Window System) in the virtual machine to 'no' by default +OPACK_SYS_XENOCARA?=no -OPACK_SYS_SETS?=+* -x* +xbase* -game* -comp* -man* -bsd.rd # Define the sets of files/packages to install in the virtual machine +OPACK_SYS_SETS?=+* -x* +xbase* -game* -comp* -man* -bsd.rd -OPACK_SYS_TIMEZONE?=Europe/Paris # Set the timezone for the virtual machine to 'Europe/Paris' by default +OPACK_SYS_TIMEZONE?=Europe/Paris -OPACK_SYS_SSH_KEY?=$(shell curl -s https://raw.githubusercontent.com/hashicorp/vagrant/master/keys/vagrant.pub) # Automatically fetch the Vagrant SSH key +OPACK_SYS_SSH_KEY?=$(shell curl -s https://raw.githubusercontent.com/hashicorp/vagrant/master/keys/vagrant.pub) -OPACK_PACKER_VERSION?=$$(curl -s https://checkpoint-api.hashicorp.com/v1/check/packer | jq -r .current_version) # Automatically fetch the latest Packer version +OPACK_PACKER_VERSION?=$$(curl -s https://checkpoint-api.hashicorp.com/v1/check/packer | jq -r .current_version) -OPACK_PACKER_HTTP_DIR?=$(OPACK_PACKER_DIR)/http # Define the Packer HTTP directory +OPACK_PACKER_HTTP_DIR?=$(OPACK_PACKER_DIR)/http -OPACK_SYS_ISO_URL?=https://$(OPACK_SYS_SERVER)/pub/OpenBSD/$(OPACK_SYS_VERSION)/$(OPACK_SYS_ARCHITECTURE)/cd$(OPACK_SYS_RELEASE).iso # Define the URL to fetch the OpenBSD ISO image +OPACK_SYS_ISO_URL?=https://$(OPACK_SYS_SERVER)/pub/OpenBSD/$(OPACK_SYS_VERSION)/$(OPACK_SYS_ARCHITECTURE)/cd$(OPACK_SYS_RELEASE).iso -OPACK_SYS_ISO_SHA256SUM?=$(shell curl -s https://$(OPACK_SYS_SERVER)/pub/OpenBSD/$(OPACK_SYS_VERSION)/$(OPACK_SYS_ARCHITECTURE)/SHA256 | grep cd$(OPACK_SYS_RELEASE).iso | cut -d"=" -f2 | tr -d ' ') # Calculate the SHA256 sum of the OpenBSD ISO image +OPACK_SYS_ISO_SHA256SUM?=$(shell curl -s https://$(OPACK_SYS_SERVER)/pub/OpenBSD/$(OPACK_SYS_VERSION)/$(OPACK_SYS_ARCHITECTURE)/SHA256 | grep cd$(OPACK_SYS_RELEASE).iso | cut -d"=" -f2 | tr -d ' ') +# Obtain Git commit information OPACK_COMMIT?=$(shell git log --oneline -n 1 --abbrev-commit --date=short --pretty=format:"%h %ad %s" 2&>/dev/null || echo latest) OPACK_SHORT_REV?=$(shell git rev-parse --short HEAD 2&>/dev/null || echo latest) -# Obtain Git commit information -OPACK_SYS_SETS_LOCATION?=http # Set the location to fetch the sets from to 'http' +OPACK_SYS_SETS_LOCATION?=http +# Set whether to skip file sets signature checking to 'no' by default OPACK_NO_SIGCHK?=no -# Set whether to skip signature checking to 'no' by default -OPACK_SYS_HEADLESS?=true # Set whether the virtual machine runs in headless mode to 'true' by default +OPACK_SYS_HEADLESS?=true -OPACK_CACHE_DIR?=$(OPACK_DIR)cache # Define the directory for caching +OPACK_CACHE_DIR?=$(OPACK_DIR)cache -OPACK_BOX_FILE?=$(OPACK_CACHE_DIR)/$(OPACK_TARGET).box -$(info BOX $(OPACK_BOX_FILE)) # Define the path to the Vagrant box file and output info +OPACK_BOX_FILE?=$(OPACK_CACHE_DIR)/$(OPACK_TARGET).box -OPACK_META_FILE?=$(OPACK_TARGET).json # Define the metadata file for the Vagrant box +OPACK_META_FILE?=$(OPACK_TARGET).json -OPACK_BOX_VERSION?=1.$(shell date +%s).$(OPACK_SHORT_REV) # Define the version of the Vagrant box +OPACK_BOX_VERSION?=1.$(shell date +%s).$(OPACK_SHORT_REV) -OPACK_BOX_FILE_SHA256?=XXXtoreplaceXXX # Define the SHA256 sum for the Vagrant box file +OPACK_BOX_FILE_SHA256?=XXXwillbereplacedXXX +# Define the tag for the Vagrant box OPACK_BOX_TAG?=opack/$(OPACK_TARGET) -# Define the Docker image tag for the Vagrant box -OPACK_PACKER_DIR?=opack_build_$(OPACK_SHORT_REV) # Define the directory for Packer build +OPACK_PACKER_DIR?=opack_installer_$(OPACK_SHORT_REV) -OPACK_PROVISION_FILE?=$(OPACK_DIR)opack-provision.sh # Define the provisioning script for Packer +OPACK_PROVISION_FILE?=$(OPACK_DIR)opack-provision.sh -OPACK_AUTODISKLABEL_FILE?=$(OPACK_DIR)autodisklabel # Define the autodisklabel file +OPACK_AUTODISKLABEL_FILE?=$(OPACK_DIR)autodisklabel -OPACK_VAGRANT_FILE=Vagrantfile # Define the Vagrantfile +OPACK_VAGRANT_FILE=Vagrantfile -OPACK_RUNTIME_PROVISION_FILE?=$(OPACK_DIR)vagrant-provision.sh # Define the runtime provisioning script for Vagrant +OPACK_RUNTIME_PROVISION_FILE?=$(OPACK_DIR)vagrant-provision.sh ifdef OPACK_DEBUG -$(info HOSTNAME = $(OPACK_SYS_HOSTNAME) USER = $(OPACK_SYS_USER) PASSWORD = $(OPACK_SYS_PASSWORD)) -$(info DISK-SIZE = $(OPACK_SYS_DISK_SIZE)m ARCH = $(OPACK_SYS_ARCHITECTURE) CPU = $(OPACK_SYS_CPU) MEMORY = $(OPACK_SYS_MEMORY)m) -$(info RELEASE = $(OPACK_SYS_RELEASE) VERSION = $(OPACK_SYS_VERSION) SERVER = $(OPACK_SYS_SERVER)) -$(info X = $(OPACK_SYS_XENOCARA) SETS = $(OPACK_SYS_SETS) NO-SIGNATURE = $(OPACK_NO_SIGCHK) HEADLESS = $(OPACK_SYS_HEADLESS)) +$(info ░ BOX $(OPACK_BOX_FILE)) +$(info ▒ HOSTNAME $(OPACK_SYS_HOSTNAME)-$(OPACK_TARGET)) +$(info ░ USER $(OPACK_SYS_USER)) +$(info ▒ PASSWORD $(OPACK_SYS_PASSWORD)) +$(info ░ DISK-SIZE $(OPACK_SYS_DISK_SIZE)m) +$(info ▒ ARCH $(OPACK_SYS_ARCHITECTURE)) +$(info ░ CPU COUNT $(OPACK_SYS_CPU)) +$(info ▒ MEMORY $(OPACK_SYS_MEMORY)m) +$(info ░ RELEASE $(OPACK_SYS_RELEASE)) +$(info ▒ VERSION $(OPACK_SYS_VERSION)) +$(info ░ SERVER $(OPACK_SYS_SERVER)) +$(info ▒ XENOCARA $(OPACK_SYS_XENOCARA)) +$(info ░ SETS $(OPACK_SYS_SETS)) +$(info ▒ IGNORE-SIG $(OPACK_NO_SIGCHK)) +$(info ░ HEADLESS $(OPACK_SYS_HEADLESS)) endif - diff --git a/src/vagrant-provision.sh b/src/vagrant-provision.sh index 059f3d9..930807c 100644 --- a/src/vagrant-provision.sh +++ b/src/vagrant-provision.sh @@ -1,4 +1,4 @@ #!/bin/sh -echo OPACK: Sucess > /opack -echo To run your own script, override OPACK_RUNTIME_PROVISION_FILE >> /opack +echo OPACK: Sucessfully deployed | tee opack +echo To run your own script, override OPACK_RUNTIME_PROVISION_FILE | tee -a opack