mirror of the now-defunct rocklinux.org
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

278 lines
9.3 KiB

  1. #!/bin/bash
  2. # --- ROCK-COPYRIGHT-NOTE-BEGIN ---
  3. #
  4. # This copyright note is auto-generated by ./scripts/Create-CopyPatch.
  5. # Please add additional copyright information _after_ the line containing
  6. # the ROCK-COPYRIGHT-NOTE-END tag. Otherwise it might get removed by
  7. # the ./scripts/Create-CopyPatch script. Do not edit this copyright text!
  8. #
  9. # ROCK Linux: rock-src/target/tor/fixedfiles/mod_rockate.sh
  10. # ROCK Linux is Copyright (C) 1998 - 2007 Clifford Wolf
  11. #
  12. # This program is free software; you can redistribute it and/or modify
  13. # it under the terms of the GNU General Public License as published by
  14. # the Free Software Foundation; either version 2 of the License, or
  15. # (at your option) any later version. A copy of the GNU General Public
  16. # License can be found at Documentation/COPYING.
  17. #
  18. # Many people helped and are helping developing ROCK Linux. Please
  19. # have a look at http://www.rocklinux.org/ and the Documentation/TEAM
  20. # file for details.
  21. #
  22. # --- ROCK-COPYRIGHT-NOTE-END ---
  23. #
  24. # ROCKate network setup
  25. rockate_add_bootmenu() {
  26. read VERSION < /etc/ROCKATE_VERSION
  27. disk="${1}"
  28. installon="${2}"
  29. mount ${disk} /mnt/generic
  30. path=/
  31. [ -d /mnt/generic/boot ] && path=/boot
  32. read menulst < <( find /mnt/generic$path -name menu.lst | head -n 1)
  33. read devicemap < <( find /mnt/generic$path -name device.map | head -n 1)
  34. read physical < <( readlink -f ${installon} )
  35. physical=${physical%[0-9]}
  36. if ! grep -q ${physical} ${devicemap} ; then
  37. for x in /dev /proc /sys /tmp ; do
  38. mount --bind $x /mnt/generic$x
  39. done
  40. chroot /mnt/generic stone -text grub create_device_map
  41. for x in /dev /proc /sys /tmp ; do
  42. umount /mnt/generic$x
  43. done
  44. fi
  45. read grubdevice linuxdevice < <( grep ${physical} ${devicemap} )
  46. if [ -z "${grubdevice}" ] ; then
  47. echo "WTF?"
  48. return
  49. fi
  50. cat >> ${menulst} <<-EOF
  51. title ROCKate ${VERSION} 1024
  52. kernel ${grubdevice%)},$(( ${installon##*part} - 1 )))/boot/vmlinuz root=/dev/ram init=/linuxrc video=vesa:ywrap,mtrr vga=0x317 rw
  53. initrd ${grubdevice%)},$(( ${installon##*part} - 1 )))/boot/initrd.img
  54. title ROCKate ${VERSION} 1280
  55. kernel ${grubdevice%)},$(( ${installon##*part} - 1 )))/boot/vmlinuz root=/dev/ram init=/linuxrc video=vesa:ywrap,mtrr vga=0x31A rw
  56. initrd ${grubdevice%)},$(( ${installon##*part} - 1 )))/boot/initrd.img
  57. title ROCKate ${VERSION} 800
  58. kernel ${grubdevice%)},$(( ${installon##*part} - 1 )))/boot/vmlinuz root=/dev/ram init=/linuxrc video=vesa:ywrap,mtrr vga=0x314 rw
  59. initrd ${grubdevice%)},$(( ${installon##*part} - 1 )))/boot/initrd.img
  60. title ROCKate ${VERSION} 640
  61. kernel ${grubdevice%)},$(( ${installon##*part} - 1 )))/boot/vmlinuz root=/dev/ram init=/linuxrc video=vesa:ywrap,mtrr vga=0x311 rw
  62. initrd ${grubdevice%)},$(( ${installon##*part} - 1 )))/boot/initrd.img
  63. title ROCKate ${VERSION} Text only
  64. kernel ${grubdevice%)},$(( ${installon##*part} - 1 )))/boot/vmlinuz root=/dev/ram init=/linuxrc vga=0 rw 3
  65. initrd ${grubdevice%)},$(( ${installon##*part} - 1 )))/boot/initrd.img
  66. EOF
  67. umount /mnt/generic
  68. }
  69. rockate_install_on() {
  70. disk="${1}"
  71. mount ${disk} /mnt/generic || return
  72. cp -arv /mnt/cowfs_ro/* /mnt/generic/
  73. find /mnt/cowfs_rw/ -type f | while read file ; do
  74. target="${file#/mnt/cowfs_rw/}"
  75. mkdir -p /mnt/generic/$( dirname ${target} )
  76. cp -v ${file} /mnt/generic/${target}
  77. done
  78. touch /mnt/generic/etc/HDINSTALL
  79. for x in /dev /proc /sys /tmp ; do
  80. mount --bind $x /mnt/generic$x
  81. done
  82. echo -n > /mnt/generic/etc/ld.so.preload
  83. tmp="$(mktemp)"
  84. grep -v ' / ' /mnt/generic/etc/fstab > $tmp
  85. echo "${disk} / auto defaults 0 0" >> $tmp
  86. mv $tmp /mnt/generic/etc/fstab
  87. chmod 0644 /mnt/generic/etc/fstab
  88. chown rocker.users /mnt/generic/home/rocker -R
  89. chroot /mnt/generic mkinitrd
  90. for x in /dev /proc /sys /tmp ; do
  91. umount /mnt/generic$x
  92. done
  93. umount /mnt/generic
  94. }
  95. rockate_install() {
  96. unset bootparts menu
  97. mkdir -p /mnt/generic
  98. for disk in /dev/disk/by-id/* ; do
  99. mount ${disk} /mnt/generic >/dev/null 2>&1 || continue
  100. if [ -f /mnt/generic/menu.lst -o -f /mnt/generic/boot/menu.lst -o \
  101. -f /mnt/generic/boot/grub/menu.lst -o -f /mnt/generic/grub/menu.lst ] ; then
  102. bootparts="${bootparts} ${disk}"
  103. fi
  104. menu="${menu} 'Install on ${disk##*/} (contains: $( ls -d /mnt/generic/* 2>/dev/null | sed -e 's,^/mnt/generic/,,g' | sed -e 's/^\(.{,80}\).*$/\1/g' ))' 'installon=${disk}; rockate_install_on ${disk}'"
  105. umount /mnt/generic >/dev/null 2>&1
  106. done
  107. eval gui_menu FOO "'ROCKate installation'" ${menu} || return
  108. unset menu
  109. if [ -n "${bootparts}" ] ; then
  110. for x in ${bootparts} ; do
  111. mount $x /mnt/generic
  112. menu="${menu} 'Add ROCKate to $x (contains:"
  113. while read y title ; do
  114. menu="${menu} ${title}"
  115. done < <( grep -i title $( find /mnt/generic -name menu.lst ) )
  116. umount /mnt/generic
  117. menu="${menu})' 'rockate_add_bootmenu ${x} ${installon}'"
  118. done
  119. eval gui_menu FOO "'ROCKate installation'" ${menu} || return
  120. else
  121. mount $disk /mnt/generic
  122. for x in /dev /proc /sys /tmp ; do
  123. mount --bind $x /mnt/generic$x
  124. done
  125. chroot /mnt/generic stone -text grub grub_setup
  126. for x in /dev /proc /sys /tmp ; do
  127. umount /mnt/generic$x
  128. done
  129. umount $disk
  130. fi
  131. }
  132. rockate_configure() {
  133. local device="${1}"
  134. read inet ip rest < <( ip addr show ${device} | grep 'inet ' )
  135. gui_input "Enter IP address for ${device}" "${ip}" newip
  136. if [ -n "${newip}" -a "${newip}" != "${ip}" ] ; then
  137. ip addr del "${ip}" dev "${device}"
  138. ip addr add "${newip}" dev "${device}"
  139. fi
  140. }
  141. rockate_defaultroute(){
  142. local gw="${1}"
  143. gui_input "Enter IP Address for the default router" "${gw}" newgw
  144. if [ -n "${newgw}" -a "${gw}" != "${newgw}" ] ; then
  145. route del -net default ${gw}
  146. route add -net default ${newgw}
  147. fi
  148. }
  149. rockate_update(){
  150. read version < /etc/ROCKATE_VERSION
  151. tmp="/tmp/update.${$}"
  152. echo "Downloading Updatelist"
  153. wget -O ${tmp} http://xsanr2oqmett7ovm.onion/UPDATES_${version}
  154. if [ ! -s "${tmp}" ] ; then
  155. echo "No updates available for version ${version}."
  156. rm -f ${tmp}
  157. return
  158. fi
  159. while read url description ; do
  160. echo "Downloading update: ${description}"
  161. wget -O /tmp/update.tar.bz2 "${url}"
  162. cd /
  163. echo "Installing update: ${description}"
  164. tar xf /tmp/update.tar.bz2
  165. cd -
  166. rm -f /tmp/update.tar.bz2
  167. if [ -f /tmp/postupdate.sh ] ; then
  168. chmod +x /tmp/postupdate.sh
  169. /tmp/postupdate.sh
  170. rm -f /tmp/postupdate.sh
  171. fi
  172. done < ${tmp}
  173. rm -f ${tmp}
  174. }
  175. rockate_transparent_tor(){
  176. # based on http://wiki.noreply.org/noreply/TheOnionRouter/TransparentProxy
  177. # destinations you don't want routed through Tor
  178. NON_TOR=""
  179. while read inet addr brd bcast rest ; do
  180. # inet 127.0.0.1/8 scope host lo
  181. # inet 213.239.220.170/27 brd 213.239.220.191 scope global eth0
  182. [ "${addr:0:3}" == "127" ] && continue
  183. read addr1 addr2 addr3 addr4 subnet <<< "${addr//[.\/]/ }"
  184. read bcast1 bcast2 bcast3 bcast4 <<< "${bcast//./ }"
  185. unset netaddr
  186. for x in 1 2 3 4 ; do
  187. eval a="\${addr${x}}"
  188. eval b="\${bcast${x}}"
  189. if [ ${subnet} -ge 8 ] ; then
  190. # the simple case
  191. netaddr="${netaddr}${netaddr:+.}${a}"
  192. subnet=$(( ${subnet} - 8 ))
  193. elif [ ${subnet} -eq 0 ] ; then
  194. # the other simple case
  195. netaddr="${netaddr}${netaddr:+.}0"
  196. else
  197. # 0 < subnet < 8
  198. b="$(( ( ${b} + 1 ) - ( 2 ** ( 8 - ${subnet} ) ) ))"
  199. netaddr="${netaddr}${netaddr:+.}${b}"
  200. subnet=0
  201. fi
  202. done
  203. NON_TOR="${NON_TOR} ${netaddr}/${addr##*/}"
  204. done < <( ip a | grep inet | grep -v inet6 )
  205. # the UID Tor runs as
  206. TOR_UID="79"
  207. # Tor's TransPort
  208. TRANS_PORT="9040"
  209. lsmod | grep ipt_owner || modprobe ipt_owner
  210. iptables -F
  211. iptables -t nat -F
  212. iptables -t nat -A OUTPUT -m owner --uid-owner $TOR_UID -j RETURN
  213. for NET in $NON_TOR 127.0.0.0/9 127.128.0.0/10; do
  214. iptables -t nat -A OUTPUT -d $NET -j RETURN
  215. done
  216. iptables -t nat -A OUTPUT -p tcp --syn -j DNAT --to-dest 127.0.0.1:$TRANS_PORT
  217. iptables -A OUTPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
  218. for NET in $NON_TOR 127.0.0.0/8; do
  219. iptables -A OUTPUT -d $NET -j ACCEPT
  220. done
  221. iptables -A OUTPUT -m owner --uid-owner $TOR_UID -j ACCEPT
  222. iptables -A OUTPUT -j REJECT
  223. }
  224. main() {
  225. #eth0 Link encap:Ethernet HWaddr 00:10:DC:7C:EE:8A
  226. while
  227. menu=""
  228. while read name a b c mac ; do
  229. read inet ip rest < <( ip addr show ${name} | grep 'inet ' )
  230. menu="${menu} 'Device ${name} (${mac})' ''"
  231. menu="${menu} ' IP Address: ${ip}' ''"
  232. menu="${menu} ' Configure via dhcp' 'dhclient -v ${name}'"
  233. menu="${menu} ' Configure manually' 'rockate_configure ${name}'"
  234. done < <( ifconfig -a | grep HWaddr ) # we only want 'real' interfaces
  235. menu="${menu} '' ''"
  236. read dest gw msk fl met ref use dev < <( route -n | grep ^0.0.0.0 )
  237. menu="${menu} 'Default Route: ${gw} (via ${dev})' 'rockate_defaultroute ${gw}'"
  238. menu="${menu} '' ''"
  239. menu="${menu} 'Setup transparent Tor proxy (use after network setup)' 'rockate_transparent_tor'"
  240. if [ ! -e /etc/HDINSTALL ] ; then
  241. menu="${menu} 'The following option can be used to update the ROCKate environment at' ''"
  242. menu="${menu} 'runtime if an update file has been provided. These changes will be' ''"
  243. menu="${menu} 'gone after reboot, so please use only if you really want to.' ''"
  244. fi
  245. menu="${menu} 'Update ROCKate' 'rockate_update'"
  246. if [ -f /etc/ULTIMATE -a ! -e /etc/HDINSTALL ] ; then
  247. menu="${menu} '' ''"
  248. menu="${menu} 'Install ROCKate to disk' 'rockate_install'"
  249. menu="${menu} 'See http://xsanr2oqmett7ovm.onion/wiki/show/PostInstall for steps' ''"
  250. menu="${menu} 'to do after installation!' ''"
  251. fi
  252. eval gui_menu FOO "'ROCKate Configuration'" ${menu}
  253. do : ; done
  254. }