Skip to content

Instantly share code, notes, and snippets.

@AhmedAbouelkher
Last active April 4, 2024 23:33
Show Gist options
  • Save AhmedAbouelkher/e59cc74c59fd257848aab8d4dc272b51 to your computer and use it in GitHub Desktop.
Save AhmedAbouelkher/e59cc74c59fd257848aab8d4dc272b51 to your computer and use it in GitHub Desktop.

Revisions

  1. AhmedAbouelkher revised this gist Apr 4, 2024. 1 changed file with 31 additions and 11 deletions.
    42 changes: 31 additions & 11 deletions run.sh
    Original file line number Diff line number Diff line change
    @@ -1,30 +1,50 @@
    #!/bin/sh

    # list all system env variables starting with flutter_ and put them in a array variable
    # list all system env variables starting with flutter_ and put them in an array variable
    values=$(env | grep ^flutter_)

    # check if values is empty
    if [ -z "$values" ]
    then
    if [ -z "$values" ]; then
    echo "No environment variables found starting with flutter_"
    exit 0
    fi
    strippedValues=()

    strippedValues=""
    # loop through all values and strip the flutter_ prefix
    for value in $values
    do
    # strip the prefix
    key=$(echo $value | sed 's/^flutter_//')
    strippedValues+=($key)
    strippedValues="$strippedValues $key"
    done
    envString=""

    # loop through all values and print them
    for envVariable in ${strippedValues[@]}
    for envVariable in $strippedValues
    do
    # split the key and value
    key=$(echo $envVariable | cut -d '=' -f 1)
    value=$(echo $envVariable | cut -d '=' -f 2)
    # split key and value by = (for only the first = in the string)
    key=$(echo $envVariable | cut -d'=' -f1)
    value=$(echo $envVariable | cut -d'=' -f2-)

    # check if value is empty
    if [ -z "$value" ]
    then
    echo "No value found for $key"
    exit 0
    fi

    # if key starts with _secret, then it is a secret and should be decoded from base64
    # example _secret_kAPIKey
    if echo "$key" | grep -q '^secret_'; then
    value=$(echo $value | base64 --decode)
    # remove the _secret_ from the key
    key=$(echo $key | sed 's/secret_//')
    fi

    # add the value to the envString
    envString+="const $key = \"${value}\";\n"
    line="const String $key = '$value';\n"
    envString="$envString$line"
    done

    # write the envString to the env.dart file
    echo $envString > lib/env.dart
    echo "$envString" > $(pwd)/lib/env.dart
  2. AhmedAbouelkher revised this gist Dec 6, 2023. 1 changed file with 6 additions and 5 deletions.
    11 changes: 6 additions & 5 deletions run.sh
    Original file line number Diff line number Diff line change
    @@ -2,19 +2,21 @@

    # list all system env variables starting with flutter_ and put them in a array variable
    values=$(env | grep ^flutter_)

    # check if values is empty
    if [ -z "$values" ]
    then
    echo "No environment variables found starting with flutter_"
    exit 0
    fi
    strippedValues=()

    # loop through all values and strip the flutter_ prefix
    for value in $values
    do
    # strip the prefix
    key=$(echo $value | sed 's/^flutter_//')
    strippedValues+=($key)
    done

    envString=""

    # loop through all values and print them
    for envVariable in ${strippedValues[@]}
    do
    @@ -24,6 +26,5 @@ do
    # add the value to the envString
    envString+="const $key = \"${value}\";\n"
    done

    # write the envString to the env.dart file
    echo $envString > lib/env.dart
  3. AhmedAbouelkher created this gist Dec 6, 2023.
    29 changes: 29 additions & 0 deletions run.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,29 @@
    #!/bin/sh

    # list all system env variables starting with flutter_ and put them in a array variable
    values=$(env | grep ^flutter_)

    strippedValues=()

    # loop through all values and strip the flutter_ prefix
    for value in $values
    do
    # strip the prefix
    key=$(echo $value | sed 's/^flutter_//')
    strippedValues+=($key)
    done

    envString=""

    # loop through all values and print them
    for envVariable in ${strippedValues[@]}
    do
    # split the key and value
    key=$(echo $envVariable | cut -d '=' -f 1)
    value=$(echo $envVariable | cut -d '=' -f 2)
    # add the value to the envString
    envString+="const $key = \"${value}\";\n"
    done

    # write the envString to the env.dart file
    echo $envString > lib/env.dart