diff --git a/podman/files/container.sh.jinja b/podman/files/container.sh.jinja index c990687..a7f9337 100644 --- a/podman/files/container.sh.jinja +++ b/podman/files/container.sh.jinja @@ -19,27 +19,32 @@ function create_container() { if ! podman container exists {{ container }};then podman container create \ --name {{ container }} \ - {%- if args['volumes'] is defined %} + {%- if args['podman_options'] is defined %} + {%- for option, value in args['podman_options'].items() %} + --{{ option }} {{ value }} \ + {%- endfor %} + {%- endif %} + {%- if args['volumes'] is defined %} {%- for volume, mount in args['volumes'].items() %} -v {{ container }}-{{ volume }}:{{ mount }} \ - {%- endfor %} - {%- endif %} - {%- if args['ports'] is defined %} - {%- for ports in args['ports'] %} - -p {{ ports['host'] }}:{{ ports['container'] }}{% if ports['protocol'] is defined %}/{{ ports['protocol'] }}{% endif %} \ {%- endfor %} - {%- endif %} - {%- if args['env'] is defined %} - {%- for key, value in args['env'].items() %} - -e {{ key }}={{ value }} \ - {%- endfor %} - {%- endif %} - {%- if args['devices'] is defined %} - {%- for key, value in args['devices'].items() %} - --device {{ key }}:{{ value}} \ - {%- endfor %} {%- endif %} - {{ args['image'] }}:{{ args['tag'] }} + {%- if args['ports'] is defined %} + {%- for ports in args['ports'] %} + -p {{ ports['host'] }}:{{ ports['container'] }}{% if ports['protocol'] is defined %}/{{ ports['protocol'] }}{% endif %} \ + {%- endfor %} + {%- endif %} + {%- if args['env'] is defined %} + {%- for key, value in args['env'].items() %} + -e {{ key }}={{ value }} \ + {%- endfor %} + {%- endif %} + {%- if args['devices'] is defined %} + {%- for key, value in args['devices'].items() %} + --device {{ key }}:{{ value}} \ + {%- endfor %} + {%- endif %} + {{ args['image'] }}:{{ args['tag'] }} fi } @@ -52,10 +57,10 @@ function check_update() { podman pull {{ args['image'] }}:{{ args['tag'] }} if [[ "$(podman image inspect {{ args['image'] }}:{{ args['tag'] }} --format "{% raw %}{{.Id}}{% endraw %}")" == "$(podman inspect {{ container }} --format "{% raw %}{{ .Image }}{% endraw %}")" ]];then echo "No image updates available" - return 0 + return 0 else echo "Image update available" - return 1 + return 1 fi } @@ -67,7 +72,7 @@ function update() { systemctl --user daemon-reload systemctl --user enable --now {{ container }}.service } - + function printHelp(){ @@ -105,31 +110,31 @@ while :; do create_container shift ;; - -s|--start) - systemctl --user enable --now {{ container }}.service - shift - ;; - -S|--stop) - systemctl --user stop {{ container }}.service - shift - ;; - -i|--is-running) + -s|--start) + systemctl --user enable --now {{ container }}.service + shift + ;; + -S|--stop) + systemctl --user stop {{ container }}.service + shift + ;; + -i|--is-running) systemctl --user is-active {{ container }}.service - exit $? - shift - ;; + exit $? + shift + ;; -g|--generate-systemd) - generate_systemd_unit_file - shift - ;; - -u|--check-update) - check_update - shift - ;; - --update) - update - shift - ;; + generate_systemd_unit_file + shift + ;; + -u|--check-update) + check_update + shift + ;; + --update) + update + shift + ;; --) #End of all options shift break @@ -143,4 +148,3 @@ while :; do esac shift done -