Advertisement
Guest User

Optware minimal install for Tomato

a guest
May 15th, 2013
318
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.48 KB | None | 0 0
  1. #!/bin/sh
  2. # Script for installing optware on DD-WRT
  3. # Written by frater
  4. #
  5. # Modified for Minimized install
  6.  
  7. export PATH=/opt/bin:/opt/sbin:/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin
  8. SCRIPTVER="Mon Feb 21 13:43:19 CET 2011 (rev 22nd Feb 2011)"
  9.  
  10. export SITES='http://ipkg.nslu2-linux.org http://ftp-osl.osuosl.org/pub/nslu2'
  11. export dom=wd.mirmana.com
  12.  
  13. os_date="`nvram get os_date`"
  14. os_year=`date -r /bin/busybox +%Y`
  15. os_month=`date -r /bin/busybox +%m`
  16. os_day=$(( `date -r /bin/busybox +%e` + 0 ))
  17.  
  18. # HASBINBASH=0
  19. # [ `nvram get os_date | awk '{print $3}'` -gt 2010 ] && HASBINBASH=1
  20.  
  21. # If the time is not set then get it at least a bit up to date
  22. if [ `date +%s` -lt 99999 ] ; then
  23. ntpclient pool.ntp.org
  24. if [ `date +%s` -lt 99999 ] ; then
  25. date -s "${SCRIPTVER}"
  26. fi
  27. fi
  28.  
  29. KERNEL=`/bin/uname -r`
  30. k26=0
  31. /bin/uname -r | grep -q "^2\.6\." && k26=1
  32. Atheros=0
  33.  
  34. OLD_RC=1
  35. NEW_RC=0
  36. if [ $os_year -gt 2009 ] ; then
  37. if [ $os_year -eq 2010 ] ; then
  38. [ $os_month -gt 4 ] && NEW_RC=1
  39. else
  40. NEW_RC=1
  41. fi
  42. fi
  43.  
  44. [ $os_year -gt 2009 ] && OLD_RC=0
  45. [ $os_year -eq 2009 ] && [ $os_month == 12 ] && OLD_RC=0
  46.  
  47. REBOOT_CORRECT=0
  48. [ $os_year -gt 2009 ] && REBOOT_CORRECT=1
  49.  
  50.  
  51. echo -e "$0\nWritten on: ${SCRIPTVER}"
  52. date -u
  53. echo -e "If you're giving feedback, please post the version as well\n\n"
  54.  
  55. if grep -iq 'Atheros' /proc/cpuinfo ; then
  56. Atheros=1
  57. echo "Atheros is not supported, sorry"
  58. exit 1
  59. fi
  60.  
  61. if ! grep -i -q "MIPS" /proc/cpuinfo ; then
  62. echo "This device has no MIPS processor"
  63. exit 1
  64. fi
  65.  
  66. if [ ! "$USER" = root ]; then
  67. echo -e "You're not root, you're ${USER}..\nI will not have enough permissions to do the things I want to do.\nExiting..."
  68. exit 1
  69. fi
  70.  
  71. cd /tmp
  72.  
  73. if ! /bin/mount 2>/dev/null | grep -q " on /opt " ; then
  74. echo -e "You need to mount /opt\nExiting..."
  75. exit 1
  76. fi
  77.  
  78. echo -e "\n\nThis will take a while!\nIf you need to do some shopping.... do it now! ;-)\n"
  79. sleep 1
  80.  
  81. mkdir -p /opt/etc/init.d 2>/dev/null
  82. if [ ! -d /opt/etc/init.d ] ; then
  83. echo -e "I'm unable to create the directory /opt/etc/init.d Check your config"
  84. exit 1
  85. fi
  86.  
  87. ipkg=ipkg-opt
  88. if [ ${Atheros} -ne 0 ] ; then
  89. REPOSITORY=http://ipkg.nslu2-linux.org/feeds/optware/openwrt-atheros/cross/unstable
  90. ipkg=ipkg
  91. else
  92. flavour=feeds/optware/ddwrt/cross/stable
  93. ipkgopt=ipkg-opt_0.99.163-10_mipsel.ipk
  94. ERROR_STATE=1
  95. rm -f /tmp/ipk
  96. for cURL in ${SITES} ; do
  97. REPOSITORY=${cURL}/$flavour
  98. /usr/bin/wget -O /tmp/ipk ${REPOSITORY}/$ipkgopt >/dev/null
  99. if [ -f /tmp/ipk ] ; then
  100. ERROR_STATE=0
  101. break
  102. fi
  103. done
  104. rm -f /tmp/ipk
  105. DOMAIN=`echo ${cURL} | cut -b8- | awk -F/ '{print $1}'`
  106. fi
  107. echo "src/gz optware $REPOSITORY" > /tmp/ipkg.conf
  108. echo "dest /opt/ /" >> /tmp/ipkg.conf
  109.  
  110. $ipkg print_installation_architecture >/dev/null 2>&1
  111. if [ ${?} -eq 0 ] ; then
  112. echo -e "You already installed optware, good show!\nI will execute an update"
  113. $ipkg update -f /tmp/ipkg.conf
  114. else
  115. echo -e "Optware is not installed... Let's install it\n"
  116.  
  117. if [ $Atheros -ne 0 ] ; then
  118. $ipkg -verbose_wget update -f /tmp/ipkg.conf
  119. $ipkg -force-reinstall -verbose_wget install uclibc-opt -f /tmp/ipkg.conf
  120. else
  121. # wget http://www.3iii.dk/linux/optware/optware-install-ddwrt.sh -O - | tr -d '\r' > /tmp/optware-install.sh
  122. # wget http://www.wlan-sat.com/boleo/optware/optware-install-ddwrt.sh -O - | tr -d '\r' > /tmp/optware-install.sh
  123. wget http://${dom}/optware-install-ddwrt2.sh -O - | tr -d '\r' > /tmp/optware-install.sh
  124. sh /tmp/optware-install.sh
  125. fi
  126.  
  127. $ipkg update -f /tmp/ipkg.conf 2>/dev/null
  128. if [ $? -ne 0 ] ; then
  129. echo -e "\n######\n\nOptware installation was NOT successfull...\nYour hardware is probably not compatible"
  130. cat /proc/cpuinfo
  131. exit 1
  132. fi
  133. fi
  134.  
  135. nvram get rc_startup >/dev/null
  136. if [ ! $? -eq 0 ] ; then
  137. echo "Error getting startup value... is this really DD-WRT?"
  138. exit 1
  139. fi
  140. rc_startup=`nvram get rc_startup`
  141.  
  142. if [ $OLD_RC -ne 0 ] ; then
  143.  
  144. echo -en "nvram set rc_startup=\"" >/tmp/chng_startup
  145. echo -n "${rc_startup}" | sed -e 's/[$`"\]/\\&/g' >> /tmp/chng_startup
  146. if ! grep -q "/init.d/optS" /tmp/chng_startup ; then
  147. echo -e "\nn=1\nwhile [ ! -d /opt/etc/init.d ] ; do\n sleep 3\n [ \\\$n -gt 30 ] && break\n let n+=1\ndone\n/opt/etc/init.d/optS\n\"" >>/tmp/chng_startup
  148. chmod +x /tmp/chng_startup
  149. /tmp/chng_startup
  150. nvram commit
  151. fi
  152. rm /tmp/chng_startup
  153.  
  154. rc_shutdown=`nvram get rc_shutdown`
  155. if ! nvram get rc_shutdown | grep -q "/init.d/optK" ; then
  156. echo -en "nvram set rc_shutdown=\"" >/tmp/chng_shutdown
  157. echo -e "/opt/etc/init.d/optK\n" >>/tmp/chng_shutdown
  158. echo -n "${rc_shutdown}" | sed -e 's/[$`"\]/\\&/g' >>/tmp/chng_shutdown
  159. echo -en "\"" >>/tmp/chng_shutdown
  160. chmod +x /tmp/chng_shutdown
  161. /tmp/chng_shutdown
  162. rm /tmp/chng_shutdown
  163. nvram commit
  164. fi
  165. fi
  166.  
  167. mkdir -p /opt/etc/init.d 2>/dev/null
  168. mkdir -p /opt/usr/sbin 2>/dev/null
  169.  
  170. if [ ! -d /opt/etc/init.d ] ; then
  171. echo "I was unable to create the directory /opt/etc/init.d, check if it is writable"
  172. exit 1
  173. fi
  174.  
  175. mkdir -p /opt/var/backups
  176. mkdir -p /opt/tmp
  177.  
  178. cd /opt/etc/init.d
  179.  
  180. isVIRGIN=1
  181. [ -f /opt/etc/init.d/S35automount ] && isVIRGIN=0
  182.  
  183. ##
  184. ## Stuff removed including and after the line: S45DISABLED=1
  185. ##
  186.  
  187. echo -e "Script finished!!\nYou can now fully use optware if you login again...\nI advice a reboot!\n"
  188. echo -e "Do check if /opt will be mounted otherwise optware will not loaded!"
  189. echo -e "\n\nhttps://mail.mirmana.com/OTRW\n\n"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement