Last active
September 8, 2023 08:53
-
-
Save epatel/bd27d27a4f8fe50fc9195b0efb257af4 to your computer and use it in GitHub Desktop.
Create template script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# | |
# Create a template script. | |
# | |
# Add files containing "{Name}" to a script that will extract and change "{Name}" to something else | |
# | |
# Example: | |
# | |
#. NAME=mbench | |
# FILES="pubspec.yaml lib/*.dart lib/*/*.dart Makefile scripts/*" | |
# sed -i "" "s/$NAME/{Name}/g" $FILES | |
# templater $NAME $FILES | |
NAME=$1 | |
if [ "$NAME" == "" ] | |
then | |
echo "Usage: $0 <name> <files>" | |
exit 1 | |
fi | |
shift 1 | |
echo "Output: $NAME.sh" | |
for fn in $@ | |
do | |
if [[ ! -f $fn ]] | |
then | |
echo "File: '$fn' missing or not a file!" | |
exit 2 | |
fi | |
done | |
cat <<EOF > $NAME.sh | |
#!/bin/bash | |
NAME=\$1 | |
if [ "\$NAME" == "" ] | |
then | |
NAME="\`awk '/^name: [a-zA-Z0-9_]*/ {print \$2}' pubspec.yaml\`" | |
fi | |
function filter() { | |
sed -i "" "s/{Name}/\$NAME/g" \$1 | |
} | |
EOF | |
cat <<EOF00 >> $NAME.sh | |
base64 -d <<__EOF | tar xvfz - | |
EOF00 | |
tar cvfz - $@ | base64 -b 70 >> $NAME.sh | |
cat <<EOF00 >> $NAME.sh | |
__EOF | |
EOF00 | |
for fn in $@ | |
do | |
cat <<EOF00 >> $NAME.sh | |
filter $fn | |
EOF00 | |
done | |
chmod a+x $NAME.sh |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment