Skip to content

Instantly share code, notes, and snippets.

@kwcto
Forked from mschwartz/Run Script.sh
Last active February 20, 2016 23:16
Show Gist options
  • Save kwcto/8ca4c7c6fd6b613b5d42 to your computer and use it in GitHub Desktop.
Save kwcto/8ca4c7c6fd6b613b5d42 to your computer and use it in GitHub Desktop.
"Run Script" for React Native automatic IP configuration
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
@kwcto
Copy link
Author

kwcto commented Jan 7, 2016

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 the ifconfig 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment