Skip to content

Commit

Permalink
local/linux: improve bash scripts readability
Browse files Browse the repository at this point in the history
Fixes #505
  • Loading branch information
Choraden authored and mmatczuk committed Jan 9, 2024
1 parent 645c82c commit d20ce55
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 22 deletions.
20 changes: 10 additions & 10 deletions local/linux/lib.sh
Original file line number Diff line number Diff line change
Expand Up @@ -35,32 +35,32 @@ process_flags() {
function build_image() {
local img="$1"
local dockerfile="$2"
if ! podman image exists "$img" || [ "$FORCE_BUILD_IMAGE" = true ] ; then
podman build --no-cache -t "$img" -f "$dockerfile"
if ! podman image exists ${img} || [ ${FORCE_BUILD_IMAGE} = true ] ; then
podman build --no-cache -t ${img} -f ${dockerfile}
fi
}

# Usage: create_package DIST PACKAGE_NAME
function create_package() {
local dist="$1"
local package_name="$2"
if [[ ! -f "$package_name" || "$FORCE_RELEASE" = true ]] ; then
make -C $ROOT_DIR dist
cp $dist "$package_name"
if [[ ! -f ${package_name} || ${FORCE_RELEASE} = true ]] ; then
make -C ${ROOT_DIR} dist
cp ${dist} ${package_name}
fi
}

# Usage: run_interactive CONTAINER_NAME
function run_interactive() {
local container_name="$1"
podman exec "$container_name" systemctl enable forwarder
podman exec "$container_name" systemctl start forwarder
podman exec "$container_name" systemctl status forwarder
podman exec -it "$container_name" /bin/bash
podman exec ${container_name} systemctl enable forwarder
podman exec ${container_name} systemctl start forwarder
podman exec ${container_name} systemctl status forwarder
podman exec -it ${container_name} /bin/bash
}

# Usage: remove_container CONTAINER_NAME
function remove_container() {
local container_name="$1"
podman rm --force "$container_name"
podman rm --force ${container_name}
}
12 changes: 6 additions & 6 deletions local/linux/run-debian.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ DIST="$ROOT_DIR/dist/forwarder*linux_arm64.deb"

process_flags "$@"

build_image "$IMG" debian-systemd.Dockerfile
create_package "$DIST" forwarder.deb
build_image ${IMG} debian-systemd.Dockerfile
create_package "${DIST}" forwarder.deb

podman run -p 3128:3128 -d -v ./forwarder.deb:/forwarder.deb --name "$CONTAINER" --replace "$IMG"
trap "remove_container $CONTAINER" EXIT
podman run -p 3128:3128 -d -v ./forwarder.deb:/forwarder.deb --name ${CONTAINER} --replace ${IMG}
trap "remove_container ${CONTAINER}" EXIT

podman exec "$CONTAINER" dpkg --force-confdef -i /forwarder.deb
run_interactive "$CONTAINER"
podman exec ${CONTAINER} dpkg --force-confdef -i /forwarder.deb
run_interactive ${CONTAINER}
12 changes: 6 additions & 6 deletions local/linux/run-fedora.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ DIST="$ROOT_DIR/dist/forwarder*_linux.aarch64.rpm"

process_flags "$@"

build_image "$IMG" fedora-systemd.Dockerfile
create_package "$DIST" forwarder.rpm
build_image ${IMG} fedora-systemd.Dockerfile
create_package "${DIST}" forwarder.rpm

podman run -p 3128:3128 -d -v ./forwarder.rpm:/forwarder.rpm --name "$CONTAINER" --replace "$IMG"
trap "remove_container $CONTAINER" EXIT
podman run -p 3128:3128 -d -v ./forwarder.rpm:/forwarder.rpm --name ${CONTAINER} --replace ${IMG}
trap "remove_container ${CONTAINER}" EXIT

podman exec "$CONTAINER" dnf -y install /forwarder.rpm
run_interactive "$CONTAINER"
podman exec ${CONTAINER} dnf -y install /forwarder.rpm
run_interactive ${CONTAINER}

0 comments on commit d20ce55

Please sign in to comment.