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.

238 lines
5.3 KiB

  1. #!/bin/sh
  2. set -e
  3. . /usr/share/debconf/confmodule
  4. file="$1"
  5. NL="
  6. "
  7. log() {
  8. logger -t apt-setup "$@"
  9. }
  10. warning() {
  11. log "warning: $@"
  12. }
  13. # Ask if a mirror should be used if the base system can be installed from CD
  14. # Default value and priority vary with the CD type used and number of CDs
  15. # that has been scanned in 41cdset
  16. if [ -e /cdrom/.disk/base_installable ]; then
  17. if ! search-path choose-mirror; then
  18. warning "choose-mirror is not available; cannot offer network mirror"
  19. exit 1
  20. fi
  21. cd_type=unknown
  22. if [ -e /cdrom/.disk/cd_type ]; then
  23. cd_type=$(cat /cdrom/.disk/cd_type)
  24. fi
  25. cd_count=$(grep "^deb cdrom:" $ROOT/etc/apt/sources.list.new | wc -l)
  26. case "$cd_type" in
  27. not_complete)
  28. use_mirror=true
  29. use_prio=medium
  30. db_metaget apt-setup/use/netinst description
  31. db_subst apt-setup/use_mirror EXPLANATION "$RET"
  32. ;;
  33. full_cd*)
  34. use_mirror=true
  35. use_prio=high
  36. if [ $cd_count -le 8 ]; then
  37. if [ $cd_count -eq 1 ]; then
  38. db_metaget apt-setup/use/cd description
  39. elif [ $cd_count -le 3 ]; then
  40. db_metaget apt-setup/use/cd-set1 description
  41. RET="$(printf "$RET" "$cd_count")"
  42. else
  43. use_mirror=false
  44. db_metaget apt-setup/use/cd-set2 description
  45. RET="$(printf "$RET" "$cd_count")"
  46. fi
  47. explanation="$RET"
  48. if [ $cd_count -le 3 ]; then
  49. db_metaget apt-setup/use/inet1 description
  50. explanation="$explanation $RET"
  51. db_metaget apt-setup/use/cd-note description
  52. explanation="$explanation$NL$NL$RET"
  53. else
  54. db_metaget apt-setup/use/inet2 description
  55. explanation="$explanation $RET"
  56. fi
  57. db_subst apt-setup/use_mirror EXPLANATION "$explanation"
  58. else
  59. use_mirror=false
  60. use_prio=low
  61. fi
  62. ;;
  63. dvd*)
  64. use_mirror=false
  65. use_prio=high
  66. if [ $cd_count -eq 1 ]; then
  67. db_metaget apt-setup/use/dvd description
  68. explanation="$RET"
  69. db_metaget apt-setup/use/inet2 description
  70. explanation="$explanation $RET"
  71. db_subst apt-setup/use_mirror EXPLANATION "$explanation"
  72. else
  73. use_prio=low
  74. fi
  75. ;;
  76. *)
  77. use_mirror=true
  78. use_prio=high
  79. ;;
  80. esac
  81. # Default to false if no network selected in netcfg
  82. if db_get netcfg/dhcp_options && \
  83. [ "$RET" = "Do not configure the network at this time" ]; then
  84. use_mirror=false
  85. use_prio=medium
  86. fi
  87. # Only set default if not preseeded or already asked
  88. # Hack alert: for this to work no default is set in template
  89. db_get apt-setup/use_mirror
  90. [ "$RET" ] || db_set apt-setup/use_mirror $use_mirror
  91. db_input $use_prio apt-setup/use_mirror || [ $? -eq 30 ]
  92. db_go || exit 10
  93. db_get apt-setup/use_mirror
  94. if [ "$RET" = false ]; then
  95. exit 1
  96. fi
  97. # Default suite to codename; choose-mirror will determine actual suite
  98. if db_get cdrom/codename && [ "$RET" ]; then
  99. db_set mirror/suite $RET
  100. fi
  101. while true; do
  102. CODE=0
  103. choose-mirror -n || CODE=$? # no progress bar
  104. db_capb backup progresscancel
  105. if [ $CODE -eq 0 ]; then
  106. break
  107. elif [ $CODE -eq 10 ]; then
  108. # User backed out of choose-mirror
  109. db_input critical apt-setup/no_mirror
  110. db_go || exit 10
  111. db_get apt-setup/no_mirror
  112. if [ "$RET" = true ]; then
  113. exit 1
  114. fi
  115. else
  116. logger -t apt-setup "choose-mirror failed with error code $CODE"
  117. exit $CODE
  118. fi
  119. done
  120. fi
  121. # Abort if no mirror is configured.
  122. db_get mirror/protocol
  123. protocol="$RET"
  124. db_get mirror/codename
  125. codename="$RET"
  126. db_get mirror/$protocol/hostname
  127. hostname="$RET"
  128. db_get mirror/$protocol/directory
  129. directory="/${RET#/}"
  130. if [ -z "$hostname" ] || [ -z "$directory" ]; then
  131. exit 1
  132. fi
  133. STATE=1
  134. while true; do
  135. case "$STATE" in
  136. 1)
  137. db_input low apt-setup/non-free || true
  138. ;;
  139. 2)
  140. # If they chose not to use non-free, ask about
  141. # contrib, with a default of no. If they chose to
  142. # use non-free, they get contrib too..
  143. db_get apt-setup/non-free
  144. if [ "$RET" = false ]; then
  145. db_fget apt-setup/contrib seen
  146. if [ "$RET" = false ]; then
  147. db_set apt-setup/contrib false
  148. fi
  149. db_input low apt-setup/contrib || true
  150. else
  151. db_fget apt-setup/contrib seen
  152. if [ "$RET" = false ]; then
  153. db_set apt-setup/contrib true
  154. fi
  155. fi
  156. ;;
  157. *)
  158. break
  159. ;;
  160. esac
  161. if db_go; then
  162. STATE=$(($STATE + 1))
  163. else
  164. STATE=$(($STATE - 1))
  165. fi
  166. done
  167. if [ $STATE -eq 0 ]; then
  168. exit 10
  169. fi
  170. dists="main"
  171. db_get apt-setup/non-free
  172. if [ "$RET" = true ]; then
  173. dists="$dists non-free"
  174. fi
  175. db_get apt-setup/contrib
  176. if [ "$RET" = true ]; then
  177. dists="$dists contrib"
  178. fi
  179. done=""
  180. while [ ! "$done" ]; do
  181. db_get mirror/codename
  182. codename="$RET"
  183. db_get mirror/protocol
  184. protocol="$RET"
  185. db_get mirror/$protocol/hostname
  186. hostname="$RET"
  187. db_get mirror/$protocol/directory
  188. directory="/${RET#/}"
  189. if [ "$protocol" = http ]; then
  190. db_get mirror/$protocol/proxy
  191. proxy="$RET"
  192. if [ -n "$proxy" ]; then
  193. if ! grep -iq "Acquire::$protocol::Proxy" $ROOT/etc/apt/apt.conf.new; then
  194. echo "Acquire::$protocol::Proxy \"$proxy\";" >> $ROOT/etc/apt/apt.conf.new
  195. fi
  196. fi
  197. fi
  198. echo "deb $protocol://$hostname$directory $codename $dists" > $file
  199. if apt-setup-verify --from $PROGRESS_FROM --to $PROGRESS_TO $file; then
  200. done=1
  201. else
  202. db_set apt-setup/mirror/error Retry
  203. db_input critical apt-setup/mirror/error || true
  204. db_go || exit 10
  205. db_get apt-setup/mirror/error
  206. if [ "$RET" = "Change mirror" ]; then
  207. choose-mirror -n || true
  208. db_capb backup progresscancel
  209. elif [ "$RET" = Ignore ]; then
  210. exit 1
  211. fi
  212. fi
  213. done
  214. echo "deb-src $protocol://$hostname$directory $codename $dists" >> $file