edit-initramfs 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. #!/bin/sh
  2. #(c) Copyright Barry Kauler 2012, bkhome.org
  3. #License GPL3 (/usr/share/doc/legal)
  4. #shared-mime-info pkg has assigned initrd.gz mime-type application/initramfs-gz (by me).
  5. #Click on initrd.gz in ROX-Filer, this script will run (see /root/Choices/MIME-types/application_initramfs-gz).
  6. #note: script not internationalized, as this is a developer's tool.
  7. [ ! $1 ] && exit 1
  8. [ ! -f "$1" ] && exit 1
  9. BASEFILE="`basename "$1"`"
  10. [ "$BASEFILE" != "initrd.gz" ] && exit 1
  11. compr_func() {
  12. #find out compression type...
  13. UNCOMPREXE=gunzip; COMPREXE=gzip; EXT=gz
  14. gunzip -t "$1"
  15. if [ $? -ne 0 ];then
  16. UNCOMPREXE=bunzip2; COMPREXE=bzip2; EXT=bz2
  17. bunzip2 -t "$1"
  18. if [ $? -ne 0 ];then
  19. UNCOMPREXE=unxz; COMPREXE=xz; EXT=xz
  20. unxz -t "$1"
  21. if [ $? -ne 0 ];then
  22. return 1
  23. fi
  24. fi
  25. fi
  26. return 0
  27. }
  28. cd /root
  29. [ -f initrd ] && rm -f initrd
  30. [ -f /tmp/initrd.gz ] && rm -f /tmp/initrd.gz
  31. [ "$1" = "/root/initrd.gz" ] && cp -f /root/initrd.gz /tmp/
  32. if [ -d initrd-expanded ];then
  33. pupdialog --background "yellow" --backtitle "initrd.gz: update?" --yesno "An initrd.gz is already expanded at /root/initrd-expanded. Is this correct, do you want to use /root/initrd-expanded to update ${1}?" 0 0
  34. if [ $? -eq 0 ];then
  35. compr_func "$1"
  36. if [ $? -ne 0 ];then
  37. pupdialog --background '#FF8080' --backtitle "initrd.gz: fail" --msgbox "Sorry, could not recognise compression type, unable to update initrd.gz." 0 0
  38. else
  39. cd initrd-expanded
  40. find . | cpio -o -H newc > ../initrd
  41. sync
  42. cd ..
  43. ${COMPREXE} initrd
  44. sync
  45. mv -f initrd.${EXT} "$1"
  46. pupdialog --background '#80FF80' --backtitle "initrd.gz: success" --msgbox "File ${1} has been updated with the contents of /root/initrd-expanded." 0 0
  47. fi
  48. fi
  49. pupdialog --background "yellow" --backtitle "initrd.gz: finished" --yesno "Do you want to delete /root/initrd-expanded? If in doubt, please choose Yes" 0 0
  50. if [ $? -eq 0 ];then
  51. rox -D /root/initrd-expanded 2>/dev/null
  52. rm -rf /root/initrd-expanded
  53. fi
  54. else
  55. pupdialog --background "yellow" --backtitle "initrd.gz: expand?" --yesno "Do you want to open up initrd.gz, and optionally edit it?" 0 0
  56. if [ $? -eq 0 ];then
  57. compr_func "$1"
  58. if [ $? -ne 0 ];then
  59. pupdialog --background '#FF8080' --backtitle "initrd.gz: fail" --msgbox "Sorry, could not recognise compression type of ${1}, unable to expand it." 0 0
  60. else
  61. [ "$1" != "/root/initrd.gz" ] && cp -f "$1" /root/
  62. mv -f initrd.gz initrd.${EXT}
  63. ${UNCOMPREXE} initrd.${EXT}
  64. [ -f /tmp/initrd.gz ] && mv -f /tmp/initrd.gz /root/
  65. mkdir initrd-expanded
  66. cd initrd-expanded
  67. cat ../initrd | cpio -i -d -m
  68. sync
  69. rm -f ../initrd
  70. cd ..
  71. pupdialog --colors --background '#80FF80' --backtitle "initrd.gz: expanded" --msgbox "File initrd.gz has been expanded at \Zb/root/initrd-expanded\ZB. You may edit the contents if you wish. \Zb\Z1\n\nAfterward, if you click on ${1} again\Zn\ZB, it will be updated with the contents of /root/initrd-expanded." 0 0
  72. rox -d /root/initrd-expanded -x /root/initrd-expanded
  73. fi
  74. fi
  75. fi
  76. [ -f /tmp/initrd.gz ] && rm -f /tmp/initrd.gz
  77. ###END###