M .local/bin/libs/hugo.sh => .local/bin/libs/hugo.sh +17 -39
@@ 1,58 1,36 @@
-#!/bin/sh
-
-get_state() (
- incus list name=hugo -c s --format csv
-)
-
+#!/bin/sh -eux
get_ip_address() (
incus list name=hugo -c 4 --format csv | awk '{print $1}'
)
-wait_until_container_is_running() (
- state=$(get_state)
-
- if [ "${state}" != "RUNNING" ]; then
- printf "Instance not running. Starting now..."
-
- incus start hugo
-
- while [ "$(get_state)" != "RUNNING" ];
- do
- printf "..."
- done
-
- echo ""
- fi
-)
-
-
wait_until_container_has_ip_address() (
- ip_address=$(get_ip_address)
+ msg="Instance doesn't have an IP address. Waiting..."
- if [ -z "${ip_addresss}" ]; then
- printf "Instance doesn't have an IP address. Waiting..."
+ while [ -z "$(get_ip_address)" ];
+ do
+ printf "%s" "${msg}"
+ msg="..."
+ done
- while [ -z "${ip_address}" ];
- do
- sleep 1
- printf "..."
- ip_address="$(get_ip_address)"
- done
-
- echo ""
- fi
+ echo ""
)
main() (
- wait_until_container_is_running
-
wait_until_container_has_ip_address
ip_address=$(get_ip_address)
- incus exec hugo -- hugo "${@}" -s /root/chromic.org/ --bind 0.0.0.0 -b http://"${ip_address}"/
+
+ action="${1-}"
+
+ if [ "${action}" = 'serve' ]; then
+ incus exec hugo -- hugo serve -s /root/chromic.org/ --bind 0.0.0.0 \
+ -b http://"${ip_address}"/
+ else
+ incus exec hugo -- hugo "${@}" -s /root/chromic.org/
+ fi
)