Advertisement
Guest User

Untitled

a guest
Nov 15th, 2013
198
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 25.49 KB | None | 0 0
  1. #!/bin/sh
  2. # Script for installing optware on DD-WRT
  3. # Written by frater
  4. #
  5. export PATH=/opt/bin:/opt/sbin:/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin
  6. SCRIPTVER="Fri Apr 22 17:08:38 CEST 2011"
  7.  
  8. export SITES='http://ipkg.nslu2-linux.org http://ftp-osl.osuosl.org/pub/nslu2'
  9. export dom=wd.mirmana.com
  10.  
  11. os_date="`nvram get os_date`"
  12. os_year=`date -r /bin/busybox +%Y`
  13. os_month=`date -r /bin/busybox +%m`
  14. os_day=$(( `date -r /bin/busybox +%e` + 0 ))
  15.  
  16. SAMBA35=0
  17. [ `date +%Y -r '/opt/sbin/smbd'` -ge 2011 ] && SAMBA35=1
  18.  
  19. # HASBINBASH=0
  20. # [ `nvram get os_date | awk '{print $3}'` -gt 2010 ] && HASBINBASH=1
  21.  
  22. # If the time is not set then get it at least a bit up to date
  23. if [ `date +%s` -lt 99999 ] ; then
  24. ntpclient pool.ntp.org
  25. if [ `date +%s` -lt 99999 ] ; then
  26. date -s "${SCRIPTVER}"
  27. fi
  28. fi
  29.  
  30. KERNEL=`/bin/uname -r`
  31. k26=0
  32. /bin/uname -r | grep -q "^2\.6\." && k26=1
  33. Atheros=0
  34.  
  35. OLD_RC=1
  36. NEW_RC=0
  37. if [ $os_year -gt 2009 ] ; then
  38. if [ $os_year -eq 2010 ] ; then
  39. [ $os_month -gt 4 ] && NEW_RC=1
  40. else
  41. NEW_RC=1
  42. fi
  43. fi
  44.  
  45. [ $os_year -gt 2009 ] && OLD_RC=0
  46. [ $os_year -eq 2009 ] && [ $os_month == 12 ] && OLD_RC=0
  47.  
  48. REBOOT_CORRECT=0
  49. [ $os_year -gt 2009 ] && REBOOT_CORRECT=1
  50.  
  51.  
  52. echo -e "$0\nWritten on: ${SCRIPTVER}"
  53. date -u
  54. echo -e "If you're giving feedback, please post the version as well\n\n"
  55.  
  56. if grep -iq 'Atheros' /proc/cpuinfo ; then
  57. Atheros=1
  58. echo "Atheros is not supported, sorry"
  59. exit 1
  60. fi
  61.  
  62. if ! grep -i -q "MIPS" /proc/cpuinfo ; then
  63. echo "This device has no MIPS processor"
  64. exit 1
  65. fi
  66.  
  67. if [ ! "$USER" = root ]; then
  68. echo -e "You're not root, you're ${USER}..\nI will not have enough permissions to do the things I want to do.\nExiting..."
  69. exit 1
  70. fi
  71.  
  72. cd /tmp
  73.  
  74. if ! /bin/mount 2>/dev/null | grep -q " on /opt " ; then
  75. echo -e "You need to mount /opt\nExiting..."
  76. exit 1
  77. fi
  78.  
  79. echo -e "\n\nThis will take a while!\nIf you need to do some shopping.... do it now! ;-)\n"
  80. sleep 1
  81.  
  82. mkdir -p /opt/etc/init.d 2>/dev/null
  83. if [ ! -d /opt/etc/init.d ] ; then
  84. echo -e "I'm unable to create the directory /opt/etc/init.d Check your config"
  85. exit 1
  86. fi
  87.  
  88. ipkg=ipkg-opt
  89. if [ ${Atheros} -ne 0 ] ; then
  90. REPOSITORY=http://ipkg.nslu2-linux.org/feeds/optware/openwrt-atheros/cross/unstable
  91. ipkg=ipkg
  92. else
  93. flavour=feeds/optware/ddwrt/cross/stable
  94. ipkgopt=ipkg-opt_0.99.163-10_mipsel.ipk
  95. ERROR_STATE=1
  96. rm -f /tmp/ipk
  97. for cURL in ${SITES} ; do
  98. REPOSITORY=${cURL}/$flavour
  99. /usr/bin/wget -O /tmp/ipk ${REPOSITORY}/$ipkgopt >/dev/null
  100. if [ -f /tmp/ipk ] ; then
  101. ERROR_STATE=0
  102. break
  103. fi
  104. done
  105. rm -f /tmp/ipk
  106. DOMAIN=`echo ${cURL} | cut -b8- | awk -F/ '{print $1}'`
  107. fi
  108. echo "src/gz optware $REPOSITORY" > /tmp/ipkg.conf
  109. echo "dest /opt/ /" >> /tmp/ipkg.conf
  110.  
  111. $ipkg print_installation_architecture >/dev/null 2>&1
  112. if [ ${?} -eq 0 ] ; then
  113. echo -e "You already installed optware, good show!\nI will execute an update"
  114. $ipkg update -f /tmp/ipkg.conf
  115. else
  116. echo -e "Optware is not installed... Let's install it\n"
  117.  
  118. if [ $Atheros -ne 0 ] ; then
  119. $ipkg -verbose_wget update -f /tmp/ipkg.conf
  120. $ipkg -force-reinstall -verbose_wget install uclibc-opt -f /tmp/ipkg.conf
  121. else
  122. # wget http://www.3iii.dk/linux/optware/optware-install-ddwrt.sh -O - | tr -d '\r' > /tmp/optware-install.sh
  123. # wget http://www.wlan-sat.com/boleo/optware/optware-install-ddwrt.sh -O - | tr -d '\r' > /tmp/optware-install.sh
  124. wget http://${dom}/optware-install-ddwrt2.sh -O - | tr -d '\r' > /tmp/optware-install.sh
  125. sh /tmp/optware-install.sh
  126. fi
  127.  
  128. $ipkg update -f /tmp/ipkg.conf 2>/dev/null
  129. if [ $? -ne 0 ] ; then
  130. echo -e "\n######\n\nOptware installation was NOT successfull...\nYour hardware is probably not compatible"
  131. cat /proc/cpuinfo
  132. exit 1
  133. fi
  134. fi
  135.  
  136. nvram get rc_startup >/dev/null
  137. if [ ! $? -eq 0 ] ; then
  138. echo "Error getting startup value... is this really DD-WRT?"
  139. exit 1
  140. fi
  141. rc_startup=`nvram get rc_startup`
  142.  
  143. if [ $OLD_RC -ne 0 ] ; then
  144.  
  145. echo -en "nvram set rc_startup=\"" >/tmp/chng_startup
  146. echo -n "${rc_startup}" | sed -e 's/[$`"\]/\\&/g' >> /tmp/chng_startup
  147. if ! grep -q "/init.d/optS" /tmp/chng_startup ; then
  148. 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
  149. chmod +x /tmp/chng_startup
  150. /tmp/chng_startup
  151. nvram commit
  152. fi
  153. rm /tmp/chng_startup
  154.  
  155. rc_shutdown=`nvram get rc_shutdown`
  156. if ! nvram get rc_shutdown | grep -q "/init.d/optK" ; then
  157. echo -en "nvram set rc_shutdown=\"" >/tmp/chng_shutdown
  158. echo -e "/opt/etc/init.d/optK\n" >>/tmp/chng_shutdown
  159. echo -n "${rc_shutdown}" | sed -e 's/[$`"\]/\\&/g' >>/tmp/chng_shutdown
  160. echo -en "\"" >>/tmp/chng_shutdown
  161. chmod +x /tmp/chng_shutdown
  162. /tmp/chng_shutdown
  163. rm /tmp/chng_shutdown
  164. nvram commit
  165. fi
  166. fi
  167.  
  168. mkdir -p /opt/etc/init.d 2>/dev/null
  169. mkdir -p /opt/usr/sbin 2>/dev/null
  170.  
  171. if [ ! -d /opt/etc/init.d ] ; then
  172. echo "I was unable to create the directory /opt/etc/init.d, check if it is writable"
  173. exit 1
  174. fi
  175.  
  176. mkdir -p /opt/var/backups
  177. mkdir -p /opt/tmp
  178.  
  179. cd /opt/etc/init.d
  180.  
  181. isVIRGIN=1
  182. [ -f /opt/etc/init.d/S35automount ] && isVIRGIN=0
  183.  
  184. S45DISABLED=1
  185. [ -f /opt/etc/init.d/S45pixelserv ] && grep -q "DISABLED=0" /opt/etc/init.d/S45pixelserv && S45DISABLED=0
  186.  
  187. secIP=
  188. terIP=
  189. if [ -f /opt/etc/init.d/S80vlighttpd ] ; then
  190. secIP=`grep "^secIP=[0-9]" /opt/etc/init.d/S80vlighttpd | awk -F= '{print $2}'`
  191. terIP=`grep "^terIP=[0-9]" /opt/etc/init.d/S80vlighttpd | awk -F= '{print $2}'`
  192. fi
  193.  
  194.  
  195. wget -qO optK http://${dom}/optK
  196. wget -qO optS http://${dom}/optS
  197. wget -qO S00optware http://${dom}/S00optware
  198. # wget -qO S01modutils http://${dom}/S01modutils
  199. wget -qO S01bashAsShell http://${dom}/S01bashAsShell
  200. wget -qO S05chngProfile http://${dom}/S05chngProfile
  201. wget -qO S10swap http://${dom}/S10swap
  202. wget -qO S20wwwdata http://${dom}/S20wwwdata
  203. [ $k26 == 0 ] && wget -qO S30usbmount http://${dom}/S30usbmount
  204. wget -qO S35automount http://${dom}/S35automount
  205. wget -qO S94stophammer http://${dom}/S94stophammer
  206. wget -qO S95watchprinter http://${dom}/S95watchprinter
  207. wget -qO S95optremount http://${dom}/S95optremount
  208. wget -qO S98stophack http://${dom}/S98stophack
  209. wget -qO K99optware http://${dom}/K99optware
  210. wget -qO S85kaid http://${dom}/S85kaid
  211.  
  212. chmod +x S85kaid
  213. ln -s S85kaid /opt/etc/init.d/K15kaid 2>/dev/null
  214.  
  215. [ -e /opt/etc/hackers ] || wget -qO /opt/etc/hackers http://${dom}/hackers
  216.  
  217. if [ $REBOOT_CORRECT -ne 0 ] ; then
  218. wget -qO S08reboot http://${dom}/S08reboot
  219. fi
  220. # kill the temporary fix for reboot if DD-WRT supports it natively
  221. if grep -q "opt/etc" /etc/profile ; then
  222. rm -f /opt/etc/init.d/S08reboot 2>/dev/null
  223. fi
  224.  
  225. if [ $isVIRGIN = 1 ] ; then
  226. wget -qO S60transmission_init http://${dom}/S60transmission_init
  227. chmod +x K* 2>/dev/null
  228. chmod +x S*
  229. fi
  230. chmod +x optS
  231. chmod +x optK
  232.  
  233. # Disable usbmount in k26
  234. [ $k26 == 0 ] || chmod -x S30usbmount 2>/dev/null
  235.  
  236. wget -qO S40relocate_syslog http://${dom}/S40relocate_syslog
  237. wget -qO S80pound http://${dom}/S80pound
  238. wget -qO S45pixelserv http://${dom}/S45pixelserv
  239. wget -qO S80vlighttpd http://${dom}/S80vlighttpd
  240. wget -qO S90asterisk http://${dom}/S90asterisk
  241. wget -qO S90transmission http://${dom}/S90transmission_as_user
  242. wget -qO S90nzbget http://${dom}/S90nzbget
  243.  
  244. wget -qO /opt/usr/sbin/asterisk_ban http://${dom}/asterisk_ban
  245. chmod +x /opt/usr/sbin/asterisk_ban
  246.  
  247. if [ $NEW_RC -eq 1 ] ; then
  248. wget -qO S95birmablock http://${dom}/S95birmablock
  249. wget -qO S95asiablock http://${dom}/S95asiablock_2010
  250. wget -qO S95worldblock http://${dom}/S95worldblock
  251. wget -qO S94fixtables http://${dom}/S94fixtables
  252. chmod +x S94fixtables
  253.  
  254. rm /opt/usr/sbin/iptables-save
  255. ln -s /usr/sbin/iptables /tmp/iptables-save
  256. if /tmp/iptables-save >/dev/null 2>&1 ; then
  257. ln -s /usr/sbin/iptables /opt/usr/sbin/iptables-save
  258. else
  259. wget -O /opt/usr/sbin/iptables-save http://wd.mirmana.com/iptables
  260. chmod +x /opt/usr/sbin/iptables-save
  261. fi
  262. rm /tmp/iptables-save
  263. elif [ $OLD_RC -eq 0 ] ; then
  264. IdeletedFile=0
  265. # wget -qO S95asiablock http://${dom}/S95asiablock_2009
  266. else
  267. wget -qO S95asiablock http://${dom}/S95asiablock_old
  268. fi
  269.  
  270. [ ${S45DISABLED} = 0 ] && sed -i -e "s/^DISABLED=1/DISABLED=0/" /opt/etc/init.d/S45pixelserv
  271. if [ ! -z "${secIP}" ] ; then
  272. /opt/bin/sed -i -e "s/^secIP=$/secIP=${secIP}/" /opt/etc/init.d/S80vlighttpd
  273. /opt/bin/sed -i -e "s/^terIP=$/terIP=${terIP}/" /opt/etc/init.d/S80vlighttpd
  274. fi
  275.  
  276. sed -i -e 's/^prefix=\/usr/prefix=\/opt/' /opt/etc/init.d/S90asterisk
  277.  
  278. mkdir -p /opt/etc/asterisk
  279. wget -qO /opt/etc/asterisk/asterisk.sh http://${dom}/asterisk.sh.16
  280. chmod +x /opt/etc/asterisk/asterisk.sh
  281.  
  282. # Remove all symbolic links
  283. rm K90swap 2>/dev/null
  284. rm K70usbmount 2>/dev/null
  285. rm K65automount 2>/dev/null
  286. rm K60relocate_syslog 2>/dev/null
  287. rm K20samba 2>/dev/null
  288. rm K20pound 2>/dev/null
  289. rm K10asterisk 2>/dev/null
  290. rm K10transmission 2>/dev/null
  291. rm K10nzbget 2>/dev/null
  292. rm K05asiablock 2>/dev/null
  293.  
  294. [ $k26 == 0 ] && ln -s S30usbmount K70usbmount 2>/dev/null
  295. ln -s S10swap K90swap 2>/dev/null
  296. ln -s S40relocate_syslog K60relocate_syslog 2>/dev/null
  297. ln -s S35automount K65automount 2>/dev/null
  298. ln -s S80samba K20samba 2>/dev/null
  299. ln -s S80vlighttpd K20vlighttpd 2>/dev/null
  300. ln -s S80lighttpd K20lighttpd 2>/dev/null
  301. ln -s S80pound K20pound 2>/dev/null
  302. ln -s S90asterisk K10asterisk 2>/dev/null
  303. ln -s S90transmission K10transmission 2>/dev/null
  304. ln -s S90nzbget K10nzbget 2>/dev/null
  305. # ln -s S95asiablock K05asiablock
  306.  
  307. # The services
  308.  
  309. $ipkg install xinetd -f /tmp/ipkg.conf 2>/dev/null
  310. [ $isVIRGIN -eq 1 ] && chmod -x /opt/etc/init.d/S10xinetd
  311.  
  312. if [ $SAMBA35 -eq 0 ] ; then
  313. if [ ! -e /opt/etc/init.d/S*samba ] ; then
  314. $ipkg install samba2 -f /tmp/ipkg.conf
  315. wget -qO /opt/etc/init.d/S80samba http://${dom}/S80samba
  316. fi
  317. fi
  318. wget -qO /opt/etc/init.d/S10xinetd http://${dom}/S10xinetd
  319.  
  320. # widen subnet of swat
  321. sed -i -e 's/192.168.1.0\/24/192.168.0.0\/16/' /opt/etc/xinetd.d/swat 2>/dev/null
  322. wget -qO /opt/etc/xinetd.d/p910nd http://${dom}/xinetd_p910nd
  323.  
  324. # if p910nd exists in standard optware then use that one
  325. [ -f /usr/sbin/p910nd ] && sed -i -e 's/= .*p910nd/= \/usr\/sbin\/p910nd/' /opt/etc/xinetd.d/p910nd
  326.  
  327. # unfsd
  328.  
  329. ipkg-opt install portmap 2>&1 >/dev/null
  330. ipkg-opt install unfs3 2>&1 >/dev/null
  331. [ -e /opt/etc/exports ] || wget -qO /opt/etc/exports http://${dom}/exports
  332. grep -q ^NAME /opt/etc/init.d/S56unfsd || wget -O /opt/etc/init.d/S56unfsd http://${dom}/S56unfsd
  333. grep -q ^NAME /opt/etc/init.d/S55portmap || wget -O /opt/etc/init.d/S55portmap http://${dom}/S55portmap
  334. [ -h /opt/etc/init.d/K45portmap ] || ln -s S55portmap /opt/etc/init.d/K45portmap
  335. [ -h /opt/etc/init.d/K44unfsd ] || ln -s S56unfsd /opt/etc/init.d/K44unfsd
  336.  
  337. #Only install busybox if it never been installed before
  338. # as it will replace the proper gnu tools
  339. # I only want it for its httpd I'm using for the asterisk interface
  340. [ -e /opt/bin/busybox ] || $ipkg install busybox -f /tmp/ipkg.conf
  341. $ipkg -force-reinstall -force-overwrite install util-linux-ng -f /tmp/ipkg.conf
  342. $ipkg -force-reinstall -force-overwrite install inetutils -f /tmp/ipkg.conf
  343. if [ $k26 = 1 ] ; then
  344. $ipkg remove modutils 2>/dev/null
  345. else
  346. $ipkg install modutils -f /tmp/ipkg.conf
  347. fi
  348. if [ `ls -1 /opt/bin/ | wc -l` -lt 650 ] ; then
  349. $ipkg install libidn -f /tmp/ipkg.conf
  350. $ipkg install coreutils -f /tmp/ipkg.conf
  351. $ipkg install diffutils -f /tmp/ipkg.conf
  352. $ipkg install findutils -f /tmp/ipkg.conf
  353. $ipkg install psutils -f /tmp/ipkg.conf
  354. $ipkg install psmisc -f /tmp/ipkg.conf
  355.  
  356. $ipkg install transmission -f /tmp/ipkg.conf
  357. $ipkg install pound -f /tmp/ipkg.conf
  358. $ipkg install asterisk14 -f /tmp/ipkg.conf
  359. $ipkg install bind -f /tmp/ipkg.conf
  360. $ipkg install lighttpd -f /tmp/ipkg.conf
  361. $ipkg install openldap-libs -f /tmp/ipkg.conf # needed for mod_auth
  362. $ipkg install sqlite -f /tmp/ipkg.conf # needed for mod_webdav
  363. $ipkg install zip -f /tmp/ipkg.conf
  364. $ipkg install php-fcgi -f /tmp/ipkg.conf
  365. $ipkg install libjpeg -f /tmp/ipkg.conf
  366. $ipkg install libxslt -f /tmp/ipkg.conf
  367. $ipkg install libxml2 -f /tmp/ipkg.conf
  368. $ipkg install nzbget -f /tmp/ipkg.conf
  369. fi
  370.  
  371. siprox_virgin=1
  372. [ -f /opt/etc/init.d/S98siproxd ] && siprox_virgin=0
  373. $ipkg install siproxd -f /tmp/ipkg.conf
  374.  
  375. if [ -e /opt/etc/init.d/S98siproxd ] ; then
  376. if [ $siprox_virgin -ne 0 ] ; then
  377. chmod -x /opt/etc/init.d/S98siproxd
  378. sed -i -e 's/\/bin\/sh/\/bin\/sh\nNAME=siproxd/' /opt/etc/init.d/S98siproxd
  379. fi
  380. fi
  381.  
  382. # Add NAME=named to the config, so it can be used by the script 'service'
  383. if [ -f /opt/etc/init.d/S09named ] ; then
  384. fdate="`date -r /opt/etc/init.d/S09named`"
  385. if ! grep -q "^NAME=" /opt/etc/init.d/S09named ; then
  386. sed -i -e 's/\/bin\/sh/\/bin\/sh\nNAME=named/' /opt/etc/init.d/S09named
  387. touch -d "$fdate" /opt/etc/init.d/S09named
  388. fi
  389. chmod -x /opt/etc/init.d/S09named
  390. fi
  391.  
  392. if [ $SAMBA35 -eq 0 ] ; then
  393. [ -f /opt/etc/init.d/S08samba ] && chmod -x /opt/etc/init.d/S08samba
  394. if [ $isVIRGIN = 1 ] ; then
  395. chmod +x /opt/etc/init.d/S80samba
  396. [ -f /opt/etc/samba/smb.conf ] && cp -p /opt/etc/samba/smb.conf /opt/etc/samba/smb.conf.`date +%y-%b.%d...%H.%M -r /opt/etc/samba/smb.conf`
  397. wget -O /opt/etc/samba/smb.conf http://${dom}/smb.conf
  398. fi
  399. fi
  400.  
  401. # pixelserv
  402. # wget -qO /opt/etc/init.d/S95pixelserv http://${dom}/S95pixelserv
  403. [ $Atheros -eq 1 ] && wget -qO /opt/usr/sbin/pixelserv http://${dom}/pixelserv_AR71xx
  404. [ $Atheros -eq 0 ] && wget -qO /opt/usr/sbin/pixelserv http://${dom}/pixelserv
  405. chmod +x /opt/usr/sbin/pixelserv
  406.  
  407. wget -qO /opt/usr/sbin/pixelserv.pl http://${dom}/pixelserv.pl
  408. chmod +x /opt/usr/sbin/pixelserv.pl
  409.  
  410. wget -qO /opt/usr/sbin/lastmins http://${dom}/lastmins
  411. chmod +x /opt/usr/sbin/lastmins
  412.  
  413. if [ $isVIRGIN = 1 ] ; then
  414. mkdir -p /opt/etc/pixelserv
  415. wget -qO /opt/etc/pixelserv/hosts.include http://${dom}/hosts.include
  416. fi
  417.  
  418. cd /opt/usr/sbin
  419. # backupessential
  420. wget -q -O /opt/usr/sbin/backupessential http://${dom}/backupessential
  421. wget -q http://${dom}/vars_to_include
  422. wget -q http://${dom}/vars_to_skip
  423. wget -q http://${dom}/vars_preferred
  424. chmod +x /opt/usr/sbin/backupessential
  425.  
  426. mkdir -p /opt/var/log 2>/dev/null
  427. touch /opt/var/log/messages
  428.  
  429. #
  430. # handy program
  431. wget -qO /opt/sbin/aggregate http://${dom}/aggregate
  432. # Some handy scripts
  433. wget -qO /opt/usr/sbin/watchprinter http://${dom}/watchprinter
  434. wget -qO /opt/usr/sbin/optlog http://${dom}/optlog
  435. wget -qO /opt/usr/sbin/service http://${dom}/service
  436. # modify the header of these 2 perl-scripts
  437. wget -qO /opt/usr/sbin/imdb http://${dom}/imdb
  438. wget -qO /opt/usr/sbin/sendEmail http://${dom}/sendEmail
  439. wget -qO /opt/usr/sbin/logtail http://${dom}/logtail
  440.  
  441. sed -i -e 's/\/usr\/bin\/perl/\/opt\/bin\/perl/' /opt/usr/sbin/imdb
  442. sed -i -e 's/\/usr\/bin\/perl/\/opt\/bin\/perl/' /opt/usr/sbin/sendEmail
  443. chmod +x /opt/sbin/aggregate
  444. chmod +x /opt/usr/sbin/watchprinter
  445. chmod +x /opt/usr/sbin/optlog
  446. chmod +x /opt/usr/sbin/service
  447. chmod +x /opt/usr/sbin/logtail
  448. chmod +x /opt/usr/sbin/imdb
  449. chmod +x /opt/usr/sbin/sendEmail
  450. chmod -x /opt/etc/init.d/S80lighttpd
  451.  
  452. if [ -e /dev/usb ] ; then
  453. wget -O /opt/etc/init.d/S95watchprinter http://${dom}/S95watchprinter
  454. $ipkg install usbutils -f /tmp/ipkg.conf
  455. $ipkg install p910nd -f /tmp/ipkg.conf
  456. # Disable the p910nd script....
  457. nvram get usb_printer | grep -q 0 || chmod +x /opt/etc/init.d/S95watchprinter 2>/dev/null
  458. else
  459. chmod -x /opt/etc/init.d/S95watchprinter 2>/dev/null
  460. fi
  461. chmod -x /opt/etc/init.d/S30usbmount 2>/dev/null
  462. chmod -x S95p910nd 2>/dev/null
  463.  
  464. # Supporting scripts for transmission
  465. wget -qO /opt/usr/sbin/mkdvd http://${dom}/mkdvd
  466. wget -qO /opt/usr/sbin/mvmovie http://${dom}/mvmovie
  467. wget -qO /opt/usr/sbin/trans_watchdog http://${dom}/trans_watchdog
  468.  
  469. sed -i -e "s/^# *BASEDIR=\/mnt/BASEDIR=\/mnt/" /opt/usr/sbin/mkdvd
  470. sed -i -e "s/^#\!\/bin\/sh/#\!\/opt\/bin\/bash/" /opt/usr/sbin/mkdvd
  471. sed -i -e "s/^# *BASEDIR=\/mnt/BASEDIR=\/mnt/" /opt/usr/sbin/mvmovie
  472. sed -i -e "s/^#\!\/bin\/sh/#\!\/opt\/bin\/bash/" /opt/usr/sbin/mvmovie
  473. sed -i -e "s/^#\!\/bin\/sh/#\!\/opt\/bin\/bash/" /opt/usr/sbin/trans_watchdog
  474. sed -i -e 's/=\/shares\/internal\/PUBLIC/=\/mnt\/C/' /opt/usr/sbin/trans_watchdog
  475.  
  476. chmod +x /opt/usr/sbin/mkdvd
  477. chmod +x /opt/usr/sbin/mvmovie
  478. chmod +x /opt/usr/sbin/trans_watchdog
  479.  
  480. echo -e "\nInstalling optware packages... (will take a while)\n"
  481.  
  482. # You really should have these packages
  483. $ipkg -force-reinstall -force-overwrite -f /tmp/ipkg.conf install net-tools
  484. if [ `ls -1 /opt/bin/ | wc -l` -lt 720 ] ; then
  485. $ipkg install lsof -f /tmp/ipkg.conf
  486. $ipkg install libcurl -f /tmp/ipkg.conf
  487. $ipkg install sudo -f /tmp/ipkg.conf
  488. $ipkg install bash -f /tmp/ipkg.conf
  489. $ipkg install vim -f /tmp/ipkg.conf
  490. $ipkg install grep -f /tmp/ipkg.conf
  491. $ipkg install procps -f /tmp/ipkg.conf
  492. $ipkg install sed -f /tmp/ipkg.conf
  493. $ipkg install bc -f /tmp/ipkg.conf
  494. $ipkg install wget -f /tmp/ipkg.conf
  495. $ipkg install unzip -f /tmp/ipkg.conf
  496. $ipkg install unrar -f /tmp/ipkg.conf
  497. $ipkg install gawk -f /tmp/ipkg.conf
  498. $ipkg install tar -f /tmp/ipkg.conf
  499. $ipkg install gzip -f /tmp/ipkg.conf
  500. $ipkg install bzip2 -f /tmp/ipkg.conf
  501. $ipkg install openssl -f /tmp/ipkg.conf
  502. $ipkg install calc -f /tmp/ipkg.conf
  503. $ipkg install par2cmdline -f /tmp/ipkg.conf
  504. fi
  505.  
  506. mkdir -p /opt/share/oversight
  507. /opt/bin/wget -O /opt/share/oversight/oversight.tgz http://${dom}/oversight.tgz
  508. /opt/bin/tar xvzf /opt/share/oversight/oversight.tgz -C /opt
  509.  
  510.  
  511. if [ ! -e /opt/etc/nzbget.conf ] ; then
  512. mkdir -p /mnt/usenet 2>/dev/null
  513. cp -p /opt/oversight/conf/unpak.cfg.example /opt/oversight/conf/unpak.cfg
  514. cp /opt/share/doc/nzbget/nzbget.conf.example /opt/etc/nzbget.conf
  515. sed -i -e 's/\$MAINDIR=.*/\$MAINDIR=\/mnt\/usenet/' /opt/etc/nzbget.conf
  516. sed -i -e 's/ServerIp=.*/ServerIp=0.0.0.0/' /opt/etc/nzbget.conf
  517. sed -i -e 's/ParPauseQueue=.*/ParPauseQueue=yes/' /opt/etc/nzbget.conf
  518. sed -i -e 's/PostPauseQueue=.*/PostPauseQueue=yes/' /opt/etc/nzbget.conf
  519. sed -i -e 's/AllowReProcess=.*/AllowReProcess=yes/' /opt/etc/nzbget.conf
  520. sed -i -e 's/PostProcess=.*/PostProcess=\/opt\/oversight\/unpak.sh/' /opt/etc/nzbget.conf
  521. fi
  522.  
  523. # This one's for the utility 'host'
  524. if [ $isVIRGIN = 1 ] ; then
  525. $ipkg install bind -f /tmp/ipkg.conf
  526. chmod -x /opt/etc/init.d/S09named
  527. fi
  528.  
  529. # These are nice to have, too
  530. $ipkg -force-reinstall -force-overwrite install e2fsprogs -f /tmp/ipkg.conf
  531. $ipkg -force-reinstall install less -f /tmp/ipkg.conf
  532. if [ `ls -1 /opt/bin/ | wc -l` -lt 720 ] ; then
  533. $ipkg install htop -f /tmp/ipkg.conf
  534. $ipkg install ncdu -f /tmp/ipkg.conf
  535. $ipkg install whois -f /tmp/ipkg.conf
  536. $ipkg install tcpdump -f /tmp/ipkg.conf
  537. $ipkg install netcat -f /tmp/ipkg.conf
  538. $ipkg install cdrtools -f /tmp/ipkg.conf
  539. $ipkg install mc -f /tmp/ipkg.conf
  540. $ipkg install httping -f /tmp/ipkg.conf
  541. $ipkg install m4 -f /tmp/ipkg.conf
  542. $ipkg install make -f /tmp/ipkg.conf
  543. $ipkg install vsftpd -f /tmp/ipkg.conf
  544. fi
  545.  
  546. grep -q "^secure_chroot_dir" /opt/etc/vsftpd.conf || echo 'secure_chroot_dir=/opt/usr/share/empty' >>/opt/etc/vsftpd.conf
  547. mkdir -p /opt/share/empty
  548. xinfile=/opt/etc/xinetd.d/vsftpd
  549. if [ ! -e $xinfile ] ; then
  550. mkdir -p /opt/etc/xinetd.d
  551. echo -e "service ftp\n{" >$xinfile
  552. echo -e "\tsocket_type\t= stream" >>$xinfile
  553. echo -e "\twait\t\t= no" >>$xinfile
  554. echo -e "\tuser\t\t= root" >>$xinfile
  555. echo -e "#\tonly_from\t= 192.168.0.0/16" >>$xinfile
  556. echo -e "\tserver\t\t= /opt/sbin/vsftpd" >>$xinfile
  557. echo -e "\tdisable\t\t= Yes" >>$xinfile
  558. echo -e "}" >>$xinfile
  559. fi
  560.  
  561.  
  562. #if [ ! -e /opt/local/twonkymedia/twonkymedia.sh ] ; then
  563.  
  564. twonkver=5.0.68
  565. filever=5.0.68
  566. support=unsupported
  567. twonkver=6.0-Beta
  568. filever=6.0-dev
  569. support=downloads
  570. twonkver=5.1.2
  571. filever=5.1.2
  572. support=downloads
  573. twonkver=6.0.30
  574. filever=6.0.30
  575.  
  576. if [ -f /opt/local/twonkymedia/twonky.${twonkver}.zip ] ; then
  577. echo "Twonky already installed"
  578. else
  579. echo "Install Twonky version: $twonkver"
  580. mkdir -p /opt/local/twonkymedia 2>/dev/null
  581. if [ -e /opt/local/twonkymedia ] ; then
  582. wget -q -O /opt/local/twonkymedia/twonky.${twonkver}.zip http://www.twonkyforum.com/${support}/${twonkver}/twonkymedia-mipsel-uclibc-0.9.28-${filever}.zip
  583. cd /opt/local/twonkymedia
  584. if [ -f twonky.${twonkver}.zip ] ; then
  585. unzip -o twonky.${twonkver}.zip
  586. # chmod +x twonkymedia.sh
  587. wget -O /opt/etc/init.d/S95twonky http://${dom}/S95twonky
  588. ln -s S95twonky /opt/etc/init.d/K05twonky
  589. # chmod +x /opt/etc/init.d/S95twonky
  590. fi
  591. else
  592. echo "Unable to create /opt/local/twonkymedia"
  593. fi
  594. fi
  595.  
  596. optsize=`df | grep opt | grep -o "[0-9]*%" | tr -cd 0-9`
  597. if [ -z "${optsize}" ] ; then
  598. echo "I could not determine the size of /opt"
  599. else
  600. if [ ${optsize} -gt 85 ] && [ -z "`which perl`" ] ; then
  601. echo "You don't have perl, but your /opt is already bigger than 85% (${optsize}%)"
  602. echo "I will not install perl"
  603. else
  604. # colordiff will install perl
  605. $ipkg install ipcalc -f /tmp/ipkg.conf
  606. $ipkg install colordiff -f /tmp/ipkg.conf
  607. $ipkg install perl-libwww -f /tmp/ipkg.conf
  608. fi
  609. fi
  610.  
  611. echo -e "\n\nTesting Optware's ifconfig:\n"
  612. /opt/bin/ifconfig >/dev/null 2>&1
  613. if [ $? -ne 0 ] ; then
  614. echo -e "\n:-(\nOptware's ifconfig in net-tools is still broken in DD-WRT's K26 builds.\nI will remove it so the standard utility will be used!\n\n"
  615. rm -f /opt/bin/ifconfig
  616. fi
  617.  
  618. KEEPBASH=1
  619. if [ $os_year -lt 2009 ] ; then
  620. KEEPBASH=0
  621. elif [ $os_year -eq 2009 ] ; then
  622. [ $os_month -lt 10 ] && KEEPBASH=0
  623. if echo $os_month -eq 9 ] ; then
  624. [ $os_day -lt 5 ] && KEEPBASH=0
  625. fi
  626. fi
  627.  
  628. if [ -e /opt/etc/sudoers ] ; then
  629. # Don't get fooled by the bracket
  630. # In the sudoers file you need 2 brackets to make a comment
  631. grep -q '^#includedir /opt/etc/sudoers.d' /opt/etc/sudoers || echo '#includedir /opt/etc/sudoers.d' >>/opt/etc/sudoers
  632. mkdir -p /opt/etc/sudoers.d 2>/dev/null
  633. chmod 440 /opt/etc/sudoers.d/*
  634. chmod 440 /opt/etc/sudoers
  635. chown root:root /opt/etc/sudoers
  636. chown root:root /opt/etc/sudoers.d
  637. chown root:root /opt/etc/sudoers.d/*
  638. fi
  639.  
  640. wget -qO /opt/usr/sbin/check_rbl http://${dom}/check_rbl
  641. [ -e /bin/bash ] || sed -i -e 's/\/bin\/bash/\/opt\/bin\/bash/' /opt/usr/sbin/check_rbl
  642. sed -i -e 's/=\/etc/=\/opt\/etc/' /opt/usr/sbin/check_rbl
  643. sed -i -e 's/^export PATH=.*/# &/' /opt/usr/sbin/check_rbl
  644. chmod +x /opt/usr/sbin/check_rbl
  645.  
  646. #if [ ! -e /opt/usr/sbin/zabbix_agentd ] ; then
  647. wget -O /tmp/zabbix.tgz http://${dom}/zabbix.tgz && /opt/bin/tar xvzf /tmp/zabbix.tgz -C/
  648. rm /tmp/zabbix.tgz 2>/dev/null
  649. #fi
  650.  
  651. if [ $KEEPBASH -eq 0 ] ; then
  652. echo -e "\nI disable the shell replacement because your firmware is too old. ${os_date}\n"
  653. chmod -x /opt/etc/init.d/S01bashAsShell
  654. fi
  655. if [ $k26 == 1 ] ; then
  656. wget -O /opt/etc/init.d/S01fixparts http://${dom}/S01fixparts
  657. chmod +x /opt/etc/init.d/S01fixparts
  658. fi
  659.  
  660. mkdir -p /opt/lib/modules/$KERNEL
  661. if [ $k26 == 1 ] ; then
  662. ipkg-opt install http://${dom}/kmod-usbsound_2.6.24.111_mipsel.ipk
  663. wget -qO - http://${dom}/soundmodules.tgz | tar xzf - -C /opt/lib/modules/$KERNEL
  664. wget -qO /opt/etc/init.d/S45soundmodules http://${dom}/S45soundmodules
  665. fi
  666.  
  667. if [ ! -e /usr/sbin/ntfs-3g ] ; then
  668. if [ $k26 == 1 ] ; then
  669. $ipkg install ntfs-3g -f /tmp/ipkg.conf
  670. $ipkg install ntfsprogs -f /tmp/ipkg.conf
  671. wget -qO - http://${dom}/ntfs-3g.tgz | tar xzf - -C /
  672. wget -qO - http://${dom}/fuse.tgz | tar xzf - -C /
  673.  
  674. wget -O /opt/lib/modules/$KERNEL/fuse.ko http://${dom}/fuse.ko.ddwrt
  675. chmod +x /opt/lib/modules/$KERNEL/fuse.ko
  676. else
  677. $ipkg install ntfs-3g -f /tmp/ipkg.conf
  678. $ipkg install ntfsprogs -f /tmp/ipkg.conf
  679. mkdir -p /opt/lib/modules/$KERNEL
  680. wget -O /opt/lib/modules/$KERNEL/fuse.o http://${dom}/fuse.o
  681. chmod +x /opt/lib/modules/$KERNEL/fuse.o
  682. fi
  683. fi
  684.  
  685. # removing optware's insmod
  686. rm /opt/sbin/insmod 2>/dev/null
  687.  
  688. if [ $k26 -ne 0 ] ; then
  689. # Install alternate iptables
  690. /usr/sbin/iptables -N recent_test
  691. if /usr/sbin/iptables -A recent_test -m recent --set --name BRUTEFORCE --rsource ; then
  692. if [ -x /opt/usr/sbin/iptables ] ; then
  693. echo "Congratulations..... You now have a firmware that supports the recent module in iptables.. I will rename the optware one !!!"
  694. wget -O /dev/null http://wd.mirmana.com/iptables.obsolete
  695. chmod -x /opt/usr/sbin/iptables
  696. mv /opt/usr/sbin/iptables /opt/usr/sbin/iptables.obsolete
  697. fi
  698. else
  699. if [ -x /opt/usr/sbin/iptables ] ; then
  700. echo "You already have an upgraded iptables!"
  701. else
  702. wget -O /opt/usr/sbin/iptables http://wd.mirmana.com/iptables
  703. chmod +x /opt/usr/sbin/iptables
  704. fi
  705. fi
  706. /usr/sbin/iptables -X recent_test
  707. fi
  708.  
  709. echo -e "\nOptware and basic packages are installed.\n"
  710.  
  711.  
  712. if [ $isVIRGIN = 1 ] ; then
  713. echo -e "\nI installed bind to get the handy utility 'host', but I don't think you want to run your WDWB as a DNS-server"
  714. echo -e "\nI will delete the executable flag of /opt/etc/init.d/S09named.\n"
  715. echo -e "\nJust make it executable again if you DO need it.\n"
  716. chmod -x /opt/etc/init.d/S09named
  717. fi
  718.  
  719. echo -e "Script finished!!\nYou can now fully use optware if you login again...\nI advice a reboot!\n"
  720. echo -e "Do check if /opt will be mounted otherwise optware will not loaded!"
  721. echo -e "\n\nhttps://mail.mirmana.com/OTRW\n\n"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement