-
-
Save kwcto/8ca4c7c6fd6b613b5d42 to your computer and use it in GitHub Desktop.
"Run Script" for React Native automatic IP configuration
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
INFOPLIST="${TARGET_BUILD_DIR}/${INFOPLIST_PATH}" | |
echo "writing to $INFOPLIST" | |
PLISTCMD="Add :SERVER_IP string $(ifconfig | grep -Eo 'inet (addr:)?([0-9]*\.){3}[0-9]*' | grep -Eo '([0-9]*\.){3}[0-9]*' | grep -v '127.0.0.1' | head -1)" | |
echo -n "$INFOPLIST" | xargs -0 /usr/libexec/PlistBuddy -c "$PLISTCMD" || true | |
PLISTCMD="Set :SERVER_IP $(ifconfig | grep -Eo 'inet (addr:)?([0-9]*\.){3}[0-9]*' | grep -Eo '([0-9]*\.){3}[0-9]*' | grep -v '127.0.0.1' | head -1)" | |
echo -n "$INFOPLIST" | xargs -0 /usr/libexec/PlistBuddy -c "$PLISTCMD" || true |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Based on article: http://moduscreate.com/automated-ip-configuration-for-react-native-development/
Fixed an issue where VirtualBox network interface IP was being picked up (first
inet
match is used starting from the bottom). Clipping theifconfig
output to 30 lines before filtering makes sure the correct interface is matched (for me anyway). You may need to tweak the number but the assumption is that the actual interface will appear before any added VirtualBox ones.