From fdb61e5949d753b12f9298bd250c036f720557d2 Mon Sep 17 00:00:00 2001 From: pvincent Date: Fri, 19 Dec 2025 13:21:53 +0400 Subject: [PATCH] miaou-create install mandatory packages for miaou-bash --- .vscode/settings.json | 3 +++ bin/pct-destroy | 38 ++++++++++++++++++++++++++------------ install.sh | 1 + tools/miaou-create | 31 ++++++++++++++++--------------- 4 files changed, 46 insertions(+), 27 deletions(-) create mode 100644 .vscode/settings.json diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..23fd35f --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,3 @@ +{ + "editor.formatOnSave": true +} \ No newline at end of file diff --git a/bin/pct-destroy b/bin/pct-destroy index 593aeb7..93dd646 100755 --- a/bin/pct-destroy +++ b/bin/pct-destroy @@ -3,26 +3,41 @@ # CONSTANTS BASEDIR=$(dirname "$0") -CONTAINER_NAME=$1 -FORCE=$2 +CONTAINER_NAME='' +FORCE=false # FUNCTIONS function usage { - echo "$(basename "$0") --force" + echo "$(basename "$0") [--force|-f]" } -function set_force { - if [[ $FORCE == '--force' ]]; then - force=true - else - force=false - fi +function parse_options { + while [[ $# -gt 0 ]]; do + case "$1" in + --help | -h) + usage && exit 0 + ;; + --force | -f) + FORCE=true + ;; + *) + if [[ -z $CONTAINER_NAME ]]; then + CONTAINER_NAME=$1 + else + echo >&2 "Unknown option: $1" && usage && exit 2 + fi + ;; + esac + + shift 1 # Move to the next argument + done + [[ -n $CONTAINER_NAME ]] || (usage && exit 1) } function destroy { if vmid=$($BASEDIR/pct-lookup "$CONTAINER_NAME"); then - [[ $FORCE ]] && pct stop $vmid + [[ $FORCE == true ]] && pct stop $vmid pct destroy $vmid else exit 1 @@ -32,6 +47,5 @@ function destroy { # MAIN set -Eue -[[ "$#" -lt 1 ]] && usage && exit 1 -set_force +parse_options $* destroy diff --git a/install.sh b/install.sh index b3b02e1..c761d77 100755 --- a/install.sh +++ b/install.sh @@ -32,6 +32,7 @@ function install_miaou_proxmox { if [[ ! -d /opt/miaou-proxmox ]]; then echo 'installing miaou-proxmox...' git clone https://git.artcode.re/miaou/miaou-proxmox.git /opt/miaou-proxmox + apt-get install -y shfmt else cd /opt/miaou-proxmox git pull diff --git a/tools/miaou-create b/tools/miaou-create index 7400fd1..009ecf0 100755 --- a/tools/miaou-create +++ b/tools/miaou-create @@ -14,22 +14,21 @@ function usage { function parse_options { while [[ $# -gt 0 ]]; do case "$1" in - --help | -h) - usage && exit 0 - ;; - *) - if [[ -z $CONTAINER ]]; then - CONTAINER=$1 - else - echo >&2 "Unknown option: $1" && usage && exit 2 - fi - ;; + --help | -h) + usage && exit 0 + ;; + *) + if [[ -z $CONTAINER ]]; then + CONTAINER=$1 + else + echo >&2 "Unknown option: $1" && usage && exit 2 + fi + ;; esac shift 1 # Move to the next argument done [[ -n $CONTAINER ]] || (usage && exit 1) - } function before_start { @@ -43,16 +42,18 @@ function before_start { function after_start { # hot changes + pct exec "$CONTAINER_ID" -- apt-get purge -y postfix + pct exec "$CONTAINER_ID" -- apt-get update + pct exec "$CONTAINER_ID" -- apt-get install -y file git bc vim jq sudo bash-completion if [[ -v MIAOU_BASH_DIR ]]; then - pct exec "$CONTAINER_ID" -- /opt/miaou-bash/install.sh + pct exec "$CONTAINER_ID" -- /opt/miaou-bash/init.sh fi - pct exec "$CONTAINER_ID" -- apt-get purge -y postfix - pct exec "$CONTAINER_ID" -- apt-get update - pct exec "$CONTAINER_ID" -- apt-get install -y sudo } function create { CONTAINER_ID=$(pct-create $CONTAINER --no-start | grep "container: $CONTAINER succesfully created" | cut -d= -f2 | cut -d! -f1) + [[ -z $CONTAINER_ID ]] && echo -e "Unable to create container: $CONTAINER\nMight already exists?" && exit 10 + before_start pct start $CONTAINER_ID after_start