4 changed files with 152 additions and 0 deletions
@ -0,0 +1,8 @@ |
|||
{ |
|||
"recommendations": [ |
|||
"mads-hartmann.bash-ide-vscode", |
|||
"waderyan.gitblame", |
|||
"jgclark.vscode-todo-highlight", |
|||
"yzhang.markdown-all-in-one" |
|||
] |
|||
} |
|||
@ -0,0 +1,10 @@ |
|||
{ |
|||
"bashIde.shfmt.caseIndent": true, |
|||
"bashIde.shfmt.funcNextLine": false, |
|||
"bashIde.shfmt.simplifyCode": true, |
|||
"editor.formatOnSave": true, |
|||
"editor.defaultFormatter": "mads-hartmann.bash-ide-vscode", |
|||
"bashIde.shfmt.binaryNextLine": true, |
|||
"bashIde.shfmt.languageDialect": "bash", |
|||
"bashIde.shfmt.spaceRedirects": true |
|||
} |
|||
@ -0,0 +1,76 @@ |
|||
#!/usr/bin/env bash |
|||
|
|||
# CONSTANTS |
|||
|
|||
BASEDIR=$(dirname "$0") |
|||
DEBIAN='images:debian/13' |
|||
CONTAINER='' |
|||
|
|||
# FUNCTIONS |
|||
|
|||
function usage { |
|||
echo "$(basename "$0") <CONTAINER_NAME>" |
|||
} |
|||
|
|||
|
|||
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 |
|||
;; |
|||
esac |
|||
|
|||
shift 1 # Move to the next argument |
|||
done |
|||
[[ -n $CONTAINER ]] || ( usage && exit 1 ) |
|||
|
|||
} |
|||
|
|||
function before_start { |
|||
# cold changes |
|||
incus config device add $CONTAINER MIAOU-BASH disk source=/opt/miaou-bash path=/opt/miaou-bash readonly=true | grep -q 'Device MIAOU-BASH added' |
|||
incus config set $CONTAINER environment.PATH /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/opt/miaou-bash/tools |
|||
cat <<EOF | incus file push --uid 0 --gid 0 --mode 644 --create-dirs - $CONTAINER/etc/systemd/resolved.conf.d/10-disable-ipv4-listener.conf |
|||
[Resolve] |
|||
LLMNR=no |
|||
DNSStubListener=no |
|||
EOF |
|||
|
|||
|
|||
} |
|||
|
|||
function after_start { |
|||
# hot changes |
|||
incus exec "$CONTAINER" -- /opt/miaou-bash/init.sh |
|||
|
|||
local domain=$(incus network get incusbr0 dns.domain) |
|||
domain=${domain:-incus} |
|||
cat <<EOF | incus file push --uid 0 --gid 0 --mode 644 --create-dirs - $CONTAINER/etc/hosts |
|||
127.0.1.1 $CONTAINER.$domain $CONTAINER |
|||
127.0.0.1 localhost |
|||
EOF |
|||
} |
|||
|
|||
function create { |
|||
incus create $DEBIAN $CONTAINER |
|||
before_start |
|||
incus start $CONTAINER |
|||
after_start |
|||
} |
|||
|
|||
|
|||
# MAIN |
|||
|
|||
set -Eue |
|||
parse_options $* |
|||
create |
|||
echo Success |
|||
|
|||
@ -0,0 +1,58 @@ |
|||
#!/usr/bin/env bash |
|||
|
|||
# CONSTANTS |
|||
|
|||
BASEDIR=$(dirname "$0") |
|||
CONTAINER='' |
|||
SCRIPT='' |
|||
DEBUG=false |
|||
|
|||
# FUNCTIONS |
|||
|
|||
function usage { |
|||
echo "$(basename "$0") {CONTAINER_NAME} {PATH_TO_SCRIPT} [[--debug|-d]]" |
|||
} |
|||
|
|||
function parse_options { |
|||
while [[ $# -gt 0 ]]; do |
|||
case "$1" in |
|||
--help | -h) |
|||
usage && exit 0 |
|||
;; |
|||
--debug | -d) |
|||
DEBUG=true |
|||
;; |
|||
*) |
|||
if [[ -z $CONTAINER ]]; then |
|||
CONTAINER=$1 |
|||
elif [[ -z $SCRIPT ]]; then |
|||
SCRIPT=$1 |
|||
else |
|||
echo >&2 "Unknown option: $1" && usage && exit 2 |
|||
fi |
|||
;; |
|||
esac |
|||
|
|||
shift 1 # Move to the next argument |
|||
done |
|||
[[ -n $CONTAINER ]] && [[ -n $SCRIPT ]] || (usage && exit 1) |
|||
} |
|||
|
|||
function debug_option { |
|||
[[ $DEBUG == 'true' ]] && echo "-x" || true |
|||
} |
|||
|
|||
function recipe { |
|||
[[ ! -f $SCRIPT ]] && echo >&2 "Script not found: $SCRIPT" && exit 3 |
|||
|
|||
# hot changes |
|||
cat "$SCRIPT" | incus exec "$CONTAINER" -- bash $(debug_option) |
|||
|
|||
} |
|||
|
|||
# MAIN |
|||
|
|||
set -Eue |
|||
parse_options $* |
|||
recipe |
|||
echo "Recipe <$(basename "$SCRIPT")> successfully performed on container <$CONTAINER>" |
|||
Write
Preview
Loading…
Cancel
Save
Reference in new issue