Advertisement
Guest User

Build Macports on Mac OS X 10.7 & 10.8 Mountain Lion

a guest
Feb 14th, 2013
2,238
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ##
  2. ## Please fill in correct info for the below variables
  3. ##
  4. NAME=buildOpenWRT.sh
  5. DIR=/Volumes/OpenWRT/trunk
  6. IP=192.168.1.1 PRT=22 USR=root
  7. GCC=gcc47
  8. OSX=10.8
  9. MACPORTS=2.1.3
  10. 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'
  11.  
  12. is_xcode_installed () {
  13.     if [ -a /usr/bin/xcodebuild ]
  14.     then
  15.         echo "Xcode installed."
  16.         return 0
  17.     else
  18.         echo "Please install Xcode before continuing."
  19.         return 1
  20.     fi
  21.  
  22. }
  23. is_cmdlinetools_installed () {
  24.    
  25.     if [ -a /usr/bin/gcc ]
  26.     then
  27.         echo "Commandline Developer Tools installed."
  28.         return 0
  29.     else
  30.         echo "Please install Xcode Commandline Developer Tools from \
  31.             Apple's website before continuing."
  32.         return 1
  33.     fi
  34. }
  35.  
  36. convert_osx_version () {
  37.    
  38.     case $OSX in
  39.         10.4)
  40.             BIGCAT=Tiger
  41.             ;;
  42.         10.5)
  43.             BIGCAT=Leopard
  44.             ;;
  45.         10.6)
  46.             BIGCAT=SnowLeopard
  47.             ;;
  48.         10.7)
  49.             BIGCAT=Lion
  50.             ;;
  51.         10.8)
  52.             BIGCAT=MountainLion
  53.             ;;
  54.     esac
  55. }
  56.  
  57. install_macports () {
  58.     convert_osx_version
  59.    
  60.     echo "export PATH=/opt/local/bin:/opt/local/sbin:$PATH" >> ~/.profile
  61.     cd ~/Downloads && \
  62.     curl -O https://distfiles.macports.org/MacPorts/MacPorts-$MACPORTS-$OSX-$BIGCAT.pkg
  63.     sudo installer -verbose -pkg MacPorts-$MACPORTS-$OSX-$BIGCAT.pkg -target /
  64.    
  65.     is_xcode_installed
  66.     is_cmdlinetools_installed
  67. }
  68.  
  69.  
  70. install_dependencies () {
  71.     sudo port -v install $DEPENDENCIES
  72. }  
  73.  
  74. set_compiler () {
  75.     sudo port install $GCC && sudo port select --set gcc mp-$GCC
  76. }
  77.  
  78.  
  79. create_targetdisk () {
  80.     echo "script.sh create_targetdisk <SIZE> <NAME> <LOCATION>"
  81.     hdiutil create -size $1 -fs "Case-sensitive HFS+" -volname OpenWRT $2/OpenWRT.sparsebundle
  82.     hdiutil attach OpenWRT.sparsebundle
  83. }
  84.  
  85. mount_targetdisk () {
  86.     #if mac use hdiutil
  87.     hdiutil attach OpenWRT.sparsebundle
  88.     #if linux use  chroot jail
  89. }
  90.  
  91. prepare_targetdisk () {
  92.     mkdir -p $DIR/{files,staging_dir/host/{lib,include}/e2fsprogs}
  93. }
  94.  
  95. update_remote_pkgs ()  {
  96.     ssh -p$PRT $USR@$IP opkg list-installed |\
  97.      sed 's/^\(.*\) - [0-9a-z].*$/\1/;' | tr '\n' ' ' | \
  98.     xargs $DIR/scripts/feeds install
  99. }
  100.  
  101. pull_remote_config () {
  102.     prepare_targetdisk
  103.         scp -rP$PRT $USR@$IP:/etc $DIR/files
  104. }
  105.  
  106. pull_sources () {
  107.     cd  $DIR/.. && svn co svn://svn.openwrt.org/openwrt/trunk/
  108. }
  109.  
  110. compile_prereq () {
  111.     cd $DIR && \
  112.     make prereq
  113.     make defconfig
  114.     make menuconfig
  115. }
  116.  
  117. compile () {
  118.     cd $DIR && \
  119.     make V=s
  120. }
  121.  
  122. feeds () {
  123.     if [ -z "$2" ]
  124.     then
  125.         echo "Choose an option: update, install, or uninstall."
  126.     fi
  127.     case  $2 in
  128.         update)
  129.             $DIR/scripts/feeds update -a
  130.             ;;
  131.         install)
  132.             $DIR/scripts/feeds install $3
  133.             ;;
  134.         uninstall)
  135.             $DIR/scripts/feeds uninstall $3
  136.             ;;
  137.         remote)
  138.             update_remote_packages
  139.             ;;
  140.     esac
  141. }
  142.  
  143. mac_specific_fixes () {
  144.     if [ -z "$1" ]
  145.     then
  146.         echo "Choose a fix: fixMakefile, copyLibraries, or meurig."
  147.     fi
  148.     case  $1 in
  149.         fix[mM]akefile)
  150.             sed -i.bak 's/\(^tools.*\)e2fsprogs/\1/;/\/e2fsprogs/s/^/#/' \
  151.                 $DIR/tools/Makefile
  152.             ;;
  153.         copy[lL]ibraries)
  154.             prepare_targetdisk
  155.             cp -R /opt/local/include/ossp  staging_dir/host/include/e2fsprogs/;
  156.             cp /opt/local/lib/libuuid* staging_dir/host/lib
  157.             ;;
  158.         meurig|[cC][cC])
  159.             export {CC,cc}=/opt/local/bin/gcc
  160.             ;;
  161.         *)
  162.             echo "Invalid. Try running ./$NAME macFixes without options"
  163.             ;;
  164.     esac
  165. }
  166.  
  167. revert_mac_changes () {
  168.     return 0
  169. }
  170.  
  171. return_help () {
  172.     echo -e "Usage: $NAME <ACTION> [OPTION1] [OPTION2]\n"
  173.     echo "Actions that require no input:"
  174.     echo -e "installMacports, installDependecies, mountWorkspace, pullSources, pullRemoteConfig, compile\n"
  175.     echo "Actions requiring user input:"
  176.     echo "  createWorkspace - Create case-sensitive HFS+ diskimage."
  177.     echo "      syntax: $NAME createWorkspace SIZE LOCATION"
  178.     echo -e "       eg $NAME createWorkspace 15g /Users/username/Desktop\n"
  179.     echo "  macFixes - Mac-specific fixes to enable building of OpenWRT"
  180.     echo "      syntax: $NAME macFixes CHOICE"
  181.     echo -e "       eg $NAME macFixes -> will bring up list of fixes\n"
  182.     echo "  feeds - Work in progress"
  183. }
  184. if [ -z $1 ]
  185. then
  186.     return_help
  187. else
  188.     case $1 in
  189.         install[Mm]acports)
  190.             install_macports
  191.             ;;
  192.         install[Dm]ependencies)
  193.             install_dependencies
  194.             ;;
  195.         mount[Ww]orkspace)
  196.             mount_targetdisk
  197.             ;;
  198.         pull[Ss]ources)
  199.             pull_sources
  200.             ;;
  201.         pullRemoteConfig)
  202.             pull_remote_config
  203.             ;;
  204.         mac[Ff]ixes)
  205.             mac_specific_fixes
  206.             ;;
  207.         create[Ww]orkspace)
  208.             [ -z $2 ] || [ -z $3 ] && return_help || create_targetdisk $2 $3
  209.             ;;
  210.         compile)
  211.             compile_prereq
  212.             compile
  213.             ;;
  214.         *)
  215.             return_help
  216.             ;;
  217.     esac
  218. fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement