Skip to content

Instantly share code, notes, and snippets.

@mvsde
Last active May 4, 2021 10:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mvsde/1fefc8521abea9e60f4ab5815fe9067a to your computer and use it in GitHub Desktop.
Save mvsde/1fefc8521abea9e60f4ab5815fe9067a to your computer and use it in GitHub Desktop.
Under-engineered multi-package management script. Uses only basic shell commands for compatibility with Docker alpine images.
#!/bin/sh
# Usage:
# -e: Exclude folders
# -p: Prioritize folders
# -c: Run this command
# execute.sh -e "folder1 folder2" -p "folder3 folder4" -c "command"
while getopts "e:p:c:" OPTION; do
case "$OPTION" in
e) EXCLUDE=$OPTARG;;
p) PRIORITY=$OPTARG;;
c) COMMAND=$OPTARG;;
esac
done
if [ "$EXCLUDE" ]; then
echo "Excluding folders $EXCLUDE."
echo ""
fi
if [ "$PRIORITY" ]; then
echo "Prioritizing folders $PRIORITY."
echo ""
fi
FOLDERS=$(ls packages)
for ITEM in $EXCLUDE; do
FOLDERS=$(echo $FOLDERS | sed "s/$ITEM//")
done
for ITEM in $PRIORITY; do
FOLDERS=$(echo $FOLDERS | sed "s/$ITEM//")
done
FOLDERS="$PRIORITY $FOLDERS"
echo $FOLDERS | xargs -n 1 sh -c "cd packages/\$0 && pwd && $COMMAND"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment