Advertisement
Guest User

Untitled

a guest
May 6th, 2017
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.74 KB | None | 0 0
  1. #! /usr/bin/make -f
  2. # See copyright notice at end of file
  3.  
  4.  
  5. # Base Version - used to extract the firmware
  6. VER1=R1.4.5
  7.  
  8. # New version to create from the extracted root filesystem and base version
  9. # kernel and header
  10. VER2=R1.4.5.M1
  11.  
  12. # Directory where you want to extract the root filesystem, from which you want
  13. # to create it
  14. ROOTFS=$(BUILDDIR)squashfs-root
  15.  
  16. # directory where you want to build files
  17. BUILDDIR=MAIN/
  18.  
  19. # directory where you downloded the original fimware ... where you want to put
  20. # the firmware you create (TFTP root)
  21. FIRMDIR=firm/
  22.  
  23. # mksquashfs utility
  24. MKSQUASKFS=$(HOME)/neufbox/mksquashfs
  25.  
  26. # network interface
  27. IFACE=eth0
  28.  
  29. LN=ln -s
  30. CP=cp
  31. SUDO=
  32.  
  33. NB4_UNSQUASH_PY=nb4-unsquash.py
  34. NB4_UNSQUASH=nb4-unsquash
  35. NB4_UNSQLZMA=nb4-unsqlzma
  36. NB4_GETFIRM=nb4-getfirm
  37. NB4_EXTRACT=nb4-extract
  38. NB4_CONCAT=nb4-concat
  39.  
  40. # Method to extract the root filesystem
  41. #UNSQUASH_ACTION=$(NB4_UNSQUASH_PY) $< $(ROOTFS)
  42. #UNSQUASH_ACTION=$(NB4_UNSQUASH) -d $(ROOTFS) $<
  43. UNSQUASH_ACTION=$(SUDO) $(NB4_UNSQLZMA) -d $(ROOTFS) $<
  44.  
  45. ADMIN_USER=
  46. ADMIN_CRYPTPWD=$1$7L3E4.ch$rrUxKcF0EwU/S9RH0Klo31
  47.  
  48. IPADDR=$(shell ip -f inet addr show dev $(IFACE) | grep inet | sed -r 's/.*inet ([0-9\.]*).*/\1/')
  49.  
  50. TMPFILE1=tmp1
  51.  
  52.  
  53. #################### HELP ####################
  54.  
  55. help:
  56. @echo "make help - This help"
  57. @echo "make download - Download the official firmware in $(FIRMDIR)"
  58. @echo "make extract * - Extract the firmware in $(BUILDDIR)"
  59. @echo "make svnclean * - remove .svn directories from root filesystem"
  60. @echo "make admin * - Create an administrative account"
  61. @echo "make build - Build the new firmware in $(BUILDDIR)"
  62. @echo "make install - Install the new firmware in $(FIRMDIR)"
  63. @echo "make tftp-server - Run a TFTP server in $(FIRMDIR)"
  64. @echo
  65. @echo "* you may want to run these actions with root privileges"
  66. @echo " to do so, just run `make SUDO=sudo <target>' (for example)"
  67. @echo
  68. @echo "extract, build and install target must be run with correct"
  69. @echo "firmware version: "
  70. @echo "Original firmware version (extract, build): VER1=$(VER1)"
  71. @echo "New firmware version (install): VER2=$(VER2)"
  72. .PHONY: help
  73.  
  74.  
  75. #################### DOWNLOAD ####################
  76.  
  77. download:
  78. -test ! -d $(FIRMDIR) && mkdir $(FIRMDIR)
  79. cd $(FIRMDIR); $(NB4_GETFIRM)
  80. $(CP) $(FIRMDIR)/LOSTVersion.general $(FIRMDIR)/LOSTVersion.general.default
  81. .PHONY: download
  82.  
  83.  
  84. #################### EXTRACT ####################
  85.  
  86. extract: $(BUILDDIR)NB4-$(VER1)-ROOTFS
  87. $(UNSQUASH_ACTION)
  88. .PHONY: extract
  89.  
  90. $(BUILDDIR)NB4-$(VER1)-HEADER $(BUILDDIR)NB4-$(VER1)-KERNEL $(BUILDDIR)NB4-$(VER1)-ROOTFS: $(BUILDDIR)NB4-$(VER1)-MAIN
  91. cd $(BUILDDIR) ; $(NB4_EXTRACT) $<
  92.  
  93. $(BUILDDIR)NB4-$(VER1)-MAIN: $(FIRMDIR)NB4-$(VER1)-MAIN
  94. -test ! -d $(BUILDDIR) && mkdir $(BUILDDIR)
  95. $(LN) $< $@
  96.  
  97.  
  98. #################### SVNCLEAN ####################
  99.  
  100. svnclean:
  101. $(SUDO) find $(ROOTFS) -type d -name '.svn' -exec rm -r {} \; -prune -print
  102. .PHONY: svnclean
  103.  
  104.  
  105. #################### ADMIN ####################
  106.  
  107. admin:
  108. @user=$(ADMIN_USER) ; \
  109. pass=$(ADMIN_CRYPTPWD) ; \
  110. echo "Note: You can change the crypted password by setting the" ;\
  111. echo " variable ADMIN_CRYPTPWD on the make command line" ;\
  112. if [ -z "$$pass" ]; then \
  113. echo "Error: You must specify a username in the Makefile" >&2; \
  114. echo " by setting the variable ADMIN_CRYPTPWD" >&2; \
  115. exit 1; \
  116. fi; \
  117. if [ -z "$$user" ]; then \
  118. echo -n "Username: "; \
  119. read user; \
  120. fi; \
  121. $(SUDO) $(CP) $(ROOTFS)/etc/passwd $(ROOTFS)/etc/passwd.bak ; \
  122. $(SUDO) $(CP) $(ROOTFS)/etc/shadow $(ROOTFS)/etc/shadow.bak ; \
  123. echo "$$user:x:0:0:root:/:/bin/sh" > $(TMPFILE1) ; \
  124. $(SUDO) grep -v "^$$user:" $(ROOTFS)/etc/passwd >> $(TMPFILE1) ; \
  125. $(SUDO) $(CP) $(TMPFILE1) $(ROOTFS)/etc/passwd ; \
  126. echo "$$user:$$pass:13367:0:99999:7:::" > $(TMPFILE1) ; \
  127. $(SUDO) grep -v "^$$user:" $(ROOTFS)/etc/shadow >> $(TMPFILE1) ; \
  128. $(SUDO) $(CP) $(TMPFILE1) $(ROOTFS)/etc/shadow ; \
  129. echo "Created user $$user."
  130. .PHONY: admin
  131.  
  132.  
  133. #################### BUILD ####################
  134.  
  135. build: $(BUILDDIR)NB4-$(VER2)-MAIN
  136. .PHONY: build
  137.  
  138. $(FIRMDIR)NB4-$(VER2)-MAIN: $(BUILDDIR)NB4-$(VER2)-MAIN
  139. -test ! -d $(FIRMDIR) && mkdir $(FIRMDIR)
  140. $(CP) $< $@
  141.  
  142. $(BUILDDIR)NB4-$(VER2)-MAIN: $(BUILDDIR)NB4-$(VER2)-HEADER $(BUILDDIR)NB4-$(VER2)-KERNEL $(BUILDDIR)NB4-$(VER2)-ROOTFS
  143. cd $(BUILDDIR) ; $(NB4_CONCAT) NB4-$(VER2)
  144. -chmod a+r $@
  145.  
  146. $(BUILDDIR)NB4-$(VER2)-HEADER: $(BUILDDIR)NB4-$(VER1)-HEADER
  147. $(LN) $< $@
  148.  
  149. $(BUILDDIR)NB4-$(VER2)-KERNEL: $(BUILDDIR)NB4-$(VER1)-KERNEL
  150. $(LN) $< $@
  151.  
  152. $(BUILDDIR)NB4-$(VER2)-ROOTFS:
  153. -test ! -d $(BUILDDIR) && mkdir $(BUILDDIR)
  154. cd $(BUILDDIR) ; $(MKSQUASKFS) $(ROOTFS) $@ -be -lzma -no-fragments -noI -all-root -noappend
  155.  
  156.  
  157. #################### INSTALL ####################
  158.  
  159. install: $(FIRMDIR)NB4-$(VER2)-MAIN
  160. tmp="`cat $(FIRMDIR)/LOSTVersion.general`" ; \
  161. echo "$$tmp" \
  162. | sed -r 's/^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$$/$(IPADDR)/' \
  163. | sed -r 's/^.*\-MAIN$$/NB4-$(VER2)-MAIN/'
  164. .PHONY: install
  165.  
  166.  
  167. #################### TFTP-SERVER ####################
  168.  
  169. tftp-server:
  170. dnsmasq -d -C /dev/null -i $(IFACE) \
  171. --domain-needed \
  172. --enable-tftp \
  173. --tftp-root="$(FIRMDIR)" \
  174. --dhcp-range=192.168.10.2,192.168.10.150,12h \
  175. --dhcp-option=1,255.255.255.0 \
  176. --dhcp-option=6,192.168.10.1 \
  177. --dhcp-option=3,192.168.10.1 \
  178. --dhcp-option=17,"192.168.10.1"
  179. .PHONY: tftp-server
  180.  
  181.  
  182.  
  183. #######################################################################
  184. ## Copyright (c) 2008 Mildred <mildred593(at)online.fr>
  185. ##
  186. ## Permission is hereby granted, free of charge, to any person
  187. ## obtaining a copy of this software and associated documentation
  188. ## files (the "Software"), to deal in the Software without
  189. ## restriction, including without limitation the rights to use,
  190. ## copy, modify, merge, publish, distribute, sublicense, and/or sell
  191. ## copies of the Software, and to permit persons to whom the
  192. ## Software is furnished to do so, subject to the following
  193. ## conditions:
  194. ##
  195. ## The above copyright notice and this permission notice shall be
  196. ## included in all copies or substantial portions of the Software.
  197. ##
  198. ## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  199. ## EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
  200. ## OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  201. ## NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
  202. ## HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
  203. ## WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  204. ## FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  205. ## OTHER DEALINGS IN THE SOFTWARE.
  206. #######################################################################
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement