Compare commits
11 commits
v0.1.0-alp
...
master
Author | SHA1 | Date | |
---|---|---|---|
580c9ceba5 | |||
ce339b69d2 | |||
|
d172c755e6 | ||
|
d4c06eda43 | ||
21404908d8 | |||
|
15fc39a355 | ||
|
1aaaf60b2d | ||
|
442ff6bcbc | ||
|
f95c0e5bfc | ||
|
75420d0f32 | ||
|
9048475efd |
3 changed files with 98 additions and 50 deletions
3
.sources
Normal file
3
.sources
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
# Sources list
|
||||||
|
debian=""
|
||||||
|
openbsd="test"
|
2
Makefile
2
Makefile
|
@ -1,4 +1,6 @@
|
||||||
install:
|
install:
|
||||||
cp $PWD/shemum /usr/bin/shemum
|
cp $PWD/shemum /usr/bin/shemum
|
||||||
|
cp $PWD/.env $HOME/.env
|
||||||
|
cp $PWD/.sources $HOME/.sources
|
||||||
clean:
|
clean:
|
||||||
rm -f /usr/bin/shemum
|
rm -f /usr/bin/shemum
|
||||||
|
|
143
shemum
143
shemum
|
@ -4,12 +4,11 @@
|
||||||
# Date: 9.18.2024
|
# Date: 9.18.2024
|
||||||
|
|
||||||
# Debug mode
|
# Debug mode
|
||||||
# To enable debug mode remove the comment.
|
|
||||||
# Default: true
|
# Default: true
|
||||||
DEBUG=true
|
DEBUG=true
|
||||||
|
|
||||||
# Debug mode check
|
# Debug mode check
|
||||||
if [$DEBUG -eq true]
|
if [ $DEBUG ]; then
|
||||||
set +x
|
set +x
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
@ -22,68 +21,112 @@ ROOT_PATH="$HOME/Machines"
|
||||||
ISO_PATH="$ROOT_PATH/$OS_NAME/$OS_NAME.iso"
|
ISO_PATH="$ROOT_PATH/$OS_NAME/$OS_NAME.iso"
|
||||||
IMG_PATH="$ROOT_PATH/$OS_NAME/$OS_NAME.img"
|
IMG_PATH="$ROOT_PATH/$OS_NAME/$OS_NAME.img"
|
||||||
|
|
||||||
# Sources defualt values
|
# Sources default values
|
||||||
. ".env"
|
#. ".env"
|
||||||
|
|
||||||
# Sources virtual machine specific values
|
# Sources virtual machine specific values
|
||||||
. "$ROOT_PATH/$OS_NAME/.env"
|
#. "$ROOT_PATH/$OS_NAME/.env"
|
||||||
|
|
||||||
# Defines install image repository.
|
# Functions
|
||||||
case $OS_NAME in
|
|
||||||
"openbsd")
|
|
||||||
INSTALL_IMG="https://cdn.openbsd.org/pub/OpenBSD/7.5/i386/cd75.iso"
|
|
||||||
;;
|
|
||||||
"debian")
|
|
||||||
INSTALL_IMG=""
|
|
||||||
;;
|
|
||||||
*)
|
|
||||||
echo "$OS_NAME is not an option" >&2
|
|
||||||
exit 1
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
|
|
||||||
# Options
|
# Defines install image source
|
||||||
case $OPTION in
|
source() {
|
||||||
# Initializes the VM and starts the installer image.
|
while read LINE; do
|
||||||
"init")
|
if [ $LINE == $OS_NAME* ]; then
|
||||||
mkdir -p "$ROOT_PATH/$OS_NAME"
|
$OS_NAME=$LINE
|
||||||
qemu-img create $IMG_PATH $DISK_SIZE
|
|
||||||
if [ ! -f $ISO_PATH ] && [ ! -z $INSTALL_IMG ]; then
|
|
||||||
echo $INSTALL_IMG
|
|
||||||
curl -o $ISO_PATH $INSTALL_IMG
|
|
||||||
elif [ ! -z $INSTALL_IMG ]; then
|
|
||||||
echo "Current INSTALL_IMG for $OS_NAME: $ISO_PATH"
|
|
||||||
else:
|
|
||||||
echo "Install image path is missing" >&2
|
|
||||||
exit 1
|
|
||||||
fi
|
fi
|
||||||
qemu-system-x86_64 -boot d \
|
done < .sources
|
||||||
-display curses \
|
}
|
||||||
-drive file=$ISO_PATH,media=cdrom \
|
|
||||||
-drive file=$IMG_PATH,format=raw \
|
check() {
|
||||||
-m $RAM -smp $CPU
|
if [ -z $OS_NAME ]; then
|
||||||
;;
|
error "Operating system is not defined"
|
||||||
"console")
|
fi
|
||||||
qemu-system-x86_64 -boot c \
|
if [ -z $INSTALL_IMG ]; then
|
||||||
|
info "$OS_NAME source not set, please update your .sources file"
|
||||||
|
fi
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
error() {
|
||||||
|
printf "$@" >&2
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
|
warn() {
|
||||||
|
printf "$@" >&2
|
||||||
|
}
|
||||||
|
|
||||||
|
info() {
|
||||||
|
printf "$@" >&1
|
||||||
|
}
|
||||||
|
|
||||||
|
# Virtual machine removal
|
||||||
|
remove() {
|
||||||
|
rm -r $ROOT_PATH/$OS_NAME
|
||||||
|
}
|
||||||
|
|
||||||
|
# Virtual machine start without a console
|
||||||
|
start() {
|
||||||
|
qemu-system-x86_64 -boot c \
|
||||||
|
-display none \
|
||||||
|
-drive file=$IMG_PATH,format=raw \
|
||||||
|
-m $RAM -smp $CPU
|
||||||
|
}
|
||||||
|
|
||||||
|
# Virtual machine start with a console
|
||||||
|
console() {
|
||||||
|
qemu-system-x86_64 -boot c \
|
||||||
-display curses \
|
-display curses \
|
||||||
-drive file=$IMG_PATH,format=raw \
|
-drive file=$IMG_PATH,format=raw \
|
||||||
-m $RAM -smp $CPU
|
-m $RAM -smp $CPU
|
||||||
|
}
|
||||||
|
|
||||||
|
# Virtual machine initialization with a console
|
||||||
|
init() {
|
||||||
|
def_os_source
|
||||||
|
mkdir -p "$ROOT_PATH/$OS_NAME"
|
||||||
|
qemu-img create $IMG_PATH $DISK_SIZE
|
||||||
|
if [ ! -f $ISO_PATH ] && [ ! -z $INSTALL_IMG ]; then
|
||||||
|
info "Fetching $OSNAME installer at: $INSTALL_IMG"
|
||||||
|
curl -o $ISO_PATH $INSTALL_IMG
|
||||||
|
elif [ ! -z $INSTALL_IMG ]; then
|
||||||
|
info "Current INSTALL_IMG for $OS_NAME: $ISO_PATH"
|
||||||
|
else
|
||||||
|
error "Install image path is missing"
|
||||||
|
fi
|
||||||
|
qemu-system-x86_64 -boot d \
|
||||||
|
-display curses \
|
||||||
|
-drive file=$ISO_PATH,media=cdrom \
|
||||||
|
-drive file=$IMG_PATH,format=raw \
|
||||||
|
-m $RAM -smp $CPU
|
||||||
|
}
|
||||||
|
|
||||||
|
# Display usage
|
||||||
|
usage() {
|
||||||
|
printf "Usage: shemum [init] <virtual machine name> <disk size>"
|
||||||
|
printf " init initialize a virtual machine"
|
||||||
|
printf " start start a QEMU virtual machine without console output"
|
||||||
|
printf " console start a QEMU virtual machine with console output"
|
||||||
|
printf " remove remove virtual machine directory and all it's contents"
|
||||||
|
}
|
||||||
|
|
||||||
|
# Options
|
||||||
|
case $OPTION in
|
||||||
|
"init")
|
||||||
|
init
|
||||||
|
;;
|
||||||
|
"console")
|
||||||
|
console
|
||||||
;;
|
;;
|
||||||
"start")
|
"start")
|
||||||
qemu-system-x86_64 -boot c \
|
start
|
||||||
-display none \
|
|
||||||
-drive file=$IMG_PATH,format=raw \
|
|
||||||
-m $RAM -smp $CPU
|
|
||||||
;;
|
;;
|
||||||
"remove")
|
"remove")
|
||||||
rm -r $ROOT_PATH/$OS_NAME
|
remove
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
echo "Usage: shemum [init] <virtual machine name> <disk size>"
|
usage
|
||||||
echo " init initialize a virtual machine"
|
|
||||||
echo " start start a QEMU virtual machine without console output"
|
|
||||||
echo " console start a QEMU virtual machine with console output"
|
|
||||||
echo " remove remove virtual machine directory and all it's contents"
|
|
||||||
esac
|
esac
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue