Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ##
- ## Please fill in correct info for the below variables
- ##
- NAME=buildOpenWRT.sh
- DIR=/Volumes/OpenWRT/trunk
- IP=192.168.1.1 PRT=22 USR=root
- GCC=gcc47
- OSX=10.8
- MACPORTS=2.1.3
- DEPENDENCIES='coreutils e2fsprogs ossp-uuid asciidoc binutils bzip2 fastjar flex getopt gtk2 intltool jikes zlib openssl p5-extutils-makemaker python26 rsync ruby sdcc unzip gettext libxslt bison gawk autoconf wget gmake ncurses findutils'
- is_xcode_installed () {
- if [ -a /usr/bin/xcodebuild ]
- then
- echo "Xcode installed."
- return 0
- else
- echo "Please install Xcode before continuing."
- return 1
- fi
- }
- is_cmdlinetools_installed () {
- if [ -a /usr/bin/gcc ]
- then
- echo "Commandline Developer Tools installed."
- return 0
- else
- echo "Please install Xcode Commandline Developer Tools from \
- Apple's website before continuing."
- return 1
- fi
- }
- convert_osx_version () {
- case $OSX in
- 10.4)
- BIGCAT=Tiger
- ;;
- 10.5)
- BIGCAT=Leopard
- ;;
- 10.6)
- BIGCAT=SnowLeopard
- ;;
- 10.7)
- BIGCAT=Lion
- ;;
- 10.8)
- BIGCAT=MountainLion
- ;;
- esac
- }
- install_macports () {
- convert_osx_version
- echo "export PATH=/opt/local/bin:/opt/local/sbin:$PATH" >> ~/.profile
- cd ~/Downloads && \
- curl -O https://distfiles.macports.org/MacPorts/MacPorts-$MACPORTS-$OSX-$BIGCAT.pkg
- sudo installer -verbose -pkg MacPorts-$MACPORTS-$OSX-$BIGCAT.pkg -target /
- is_xcode_installed
- is_cmdlinetools_installed
- }
- install_dependencies () {
- sudo port -v install $DEPENDENCIES
- }
- set_compiler () {
- sudo port install $GCC && sudo port select --set gcc mp-$GCC
- }
- create_targetdisk () {
- echo "script.sh create_targetdisk <SIZE> <NAME> <LOCATION>"
- hdiutil create -size $1 -fs "Case-sensitive HFS+" -volname OpenWRT $2/OpenWRT.sparsebundle
- hdiutil attach OpenWRT.sparsebundle
- }
- mount_targetdisk () {
- #if mac use hdiutil
- hdiutil attach OpenWRT.sparsebundle
- #if linux use chroot jail
- }
- prepare_targetdisk () {
- mkdir -p $DIR/{files,staging_dir/host/{lib,include}/e2fsprogs}
- }
- update_remote_pkgs () {
- ssh -p$PRT $USR@$IP opkg list-installed |\
- sed 's/^\(.*\) - [0-9a-z].*$/\1/;' | tr '\n' ' ' | \
- xargs $DIR/scripts/feeds install
- }
- pull_remote_config () {
- prepare_targetdisk
- scp -rP$PRT $USR@$IP:/etc $DIR/files
- }
- pull_sources () {
- cd $DIR/.. && svn co svn://svn.openwrt.org/openwrt/trunk/
- }
- compile_prereq () {
- cd $DIR && \
- make prereq
- make defconfig
- make menuconfig
- }
- compile () {
- cd $DIR && \
- make V=s
- }
- feeds () {
- if [ -z "$2" ]
- then
- echo "Choose an option: update, install, or uninstall."
- fi
- case $2 in
- update)
- $DIR/scripts/feeds update -a
- ;;
- install)
- $DIR/scripts/feeds install $3
- ;;
- uninstall)
- $DIR/scripts/feeds uninstall $3
- ;;
- remote)
- update_remote_packages
- ;;
- esac
- }
- mac_specific_fixes () {
- if [ -z "$1" ]
- then
- echo "Choose a fix: fixMakefile, copyLibraries, or meurig."
- fi
- case $1 in
- fix[mM]akefile)
- sed -i.bak 's/\(^tools.*\)e2fsprogs/\1/;/\/e2fsprogs/s/^/#/' \
- $DIR/tools/Makefile
- ;;
- copy[lL]ibraries)
- prepare_targetdisk
- cp -R /opt/local/include/ossp staging_dir/host/include/e2fsprogs/;
- cp /opt/local/lib/libuuid* staging_dir/host/lib
- ;;
- meurig|[cC][cC])
- export {CC,cc}=/opt/local/bin/gcc
- ;;
- *)
- echo "Invalid. Try running ./$NAME macFixes without options"
- ;;
- esac
- }
- revert_mac_changes () {
- return 0
- }
- return_help () {
- echo -e "Usage: $NAME <ACTION> [OPTION1] [OPTION2]\n"
- echo "Actions that require no input:"
- echo -e "installMacports, installDependecies, mountWorkspace, pullSources, pullRemoteConfig, compile\n"
- echo "Actions requiring user input:"
- echo " createWorkspace - Create case-sensitive HFS+ diskimage."
- echo " syntax: $NAME createWorkspace SIZE LOCATION"
- echo -e " eg $NAME createWorkspace 15g /Users/username/Desktop\n"
- echo " macFixes - Mac-specific fixes to enable building of OpenWRT"
- echo " syntax: $NAME macFixes CHOICE"
- echo -e " eg $NAME macFixes -> will bring up list of fixes\n"
- echo " feeds - Work in progress"
- }
- if [ -z $1 ]
- then
- return_help
- else
- case $1 in
- install[Mm]acports)
- install_macports
- ;;
- install[Dm]ependencies)
- install_dependencies
- ;;
- mount[Ww]orkspace)
- mount_targetdisk
- ;;
- pull[Ss]ources)
- pull_sources
- ;;
- pullRemoteConfig)
- pull_remote_config
- ;;
- mac[Ff]ixes)
- mac_specific_fixes
- ;;
- create[Ww]orkspace)
- [ -z $2 ] || [ -z $3 ] && return_help || create_targetdisk $2 $3
- ;;
- compile)
- compile_prereq
- compile
- ;;
- *)
- return_help
- ;;
- esac
- fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement