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.

187 lines
5.4 KiB

  1. #!/bin/bash
  2. type_encrypted="encrypted"
  3. entrosource="${LVP_ENTROPY_SOURCE}"
  4. process_encrypted(){
  5. target="livesystem"
  6. echo -n "Checking necessary filesystem size ... "
  7. filesize=0
  8. while read file ; do
  9. [ ! -f "${file}" ] && continue
  10. thisfilesize=`ls -l "${file}" | sed 's,[ \t][ \t]*, ,g' | cut -f5 -d' '`
  11. filesize=$(( ${filesize} + ${thisfilesize} ))
  12. done < ${moviefiles}
  13. echo "${filesize} Byte (`human_readable ${filesize}`)"
  14. echo -n "Checking Livesystem size ... "
  15. livesize=`du -sb ${target} --exclude=lvp.data? | cut -f1`
  16. echo "`human_readable ${livesize}`"
  17. filesize=$(( $filesize + $livesize ))
  18. echo
  19. echo "Total space needed: $(( ${filesize} / 1024 / 1024 )) MB"
  20. if [ $(( ${filesize} / 1024 / 1024 )) -gt $size ] ; then
  21. echo
  22. echo "This may be more than fits onto your medium."
  23. echo "You specified ${size} MB to fit onto your medium."
  24. echo "If you are sure that this is okay, please continue."
  25. echo "If not, please truncate your filelist."
  26. confirm "Continue"
  27. [ ${?} -eq 1 ] && exit 1
  28. fi
  29. echo "Searching for free loopdevices ..."
  30. filesize=$(( ( ${size} * 1048576 ) - ${livesize} ))
  31. needed_pseudofs=$(( (${filesize} / 2147481600) + 1 ))
  32. needed_loopdevices=${needed_pseudofs}
  33. for loopdevice in /dev/loop/* ; do
  34. [ ${needed_loopdevices} -eq 0 ] && continue
  35. if losetup ${loopdevice} ${moviefiles} 2>/dev/null ; then
  36. # I reuse the ${moviefiles} tmpfile here since associating it
  37. # with a loopdevice doesn't do any harm
  38. echo "Using ${loopdevice}"
  39. eval "loopdevice_${needed_loopdevices}=\"${loopdevice}\""
  40. losetup -d ${loopdevice}
  41. needed_loopdevices=$(( ${needed_loopdevices} - 1 ))
  42. fi
  43. done
  44. echo "Okay, Now creating files that will hold the pseudo filesystems"
  45. unset ddparam
  46. [ `dd --help | grep -c stat` -eq 1 ] && ddparam="conv=stat"
  47. if [ -e livesystem/lvp.data1 ] ; then
  48. for x in livesystem/lvp.data* ; do
  49. if [ ${x##*lvp.data} -gt ${needed_pseudofs} ] ; then\
  50. echo "Found ${x##*/}, but we don't need it. Deleting it."
  51. rm -f ${x}
  52. fi
  53. done
  54. fi
  55. filesystem=0
  56. while [ ${filesystem} -lt ${needed_pseudofs} ] ; do
  57. filesystem=$(( ${filesystem} + 1 ))
  58. echo "Filesystem ${filesystem} of ${needed_pseudofs}"
  59. file="livesystem/lvp.data${filesystem}"
  60. if [ ${filesystem} -lt ${needed_pseudofs} ] ; then
  61. size=2147481600
  62. else
  63. size=$(( ${filesize} - ( ${filesystem} - 1 ) * 2147481600 ))
  64. size=$(( ( ${size} / 2048 ) * 2048 ))
  65. fi
  66. if [ -f ${file} ] ; then
  67. thisfilesize=`ls -l "${file}" | sed 's, *, ,g' | cut -f5 -d' '`
  68. if [ ${thisfilesize} -eq ${size} ] ; then
  69. echo "lvp.data${filesystem} already exists and has correct filesize. Using it."
  70. else
  71. echo "lvp.data${filesystem} already exists but has wrong filesize. Deleting it"
  72. rm -f livesystem/lvp.data${filesystem}
  73. fi
  74. fi
  75. [ -f livesystem/lvp.data${filesystem} ] && continue
  76. dd if=/dev/${entrosource} of=livesystem/lvp.data${filesystem} \
  77. bs=2k count=$(( $size / 2048 )) ${ddparam}
  78. done
  79. echo "Creating mountpoints"
  80. rm -rf livesystem/mnt*
  81. filesystem=1
  82. while [ ${filesystem} -le ${needed_pseudofs} ] ; do
  83. mkdir -p livesystem/mnt${filesystem}
  84. filesystem=$(( ${filesystem} + 1 ))
  85. done
  86. echo "Using ${LVP_ENCRYPTION} encryption."
  87. echo "Now I need a passphrase for encrypting the filesystems."
  88. passphrase="MEEP"
  89. passphrase_confirm="MOOP"
  90. while [ "${passphrase}" != "${passphrase_confirm}" ] ; do
  91. read -p "Enter passphrase: " -s passphrase
  92. echo
  93. read -p "Confirm: " -s passphrase_confirm
  94. echo
  95. if [ "${passphrase:20}" = "" ] ; then
  96. echo "The Passphrase must be at lest 20 characters!"
  97. passphrase="MEEP"
  98. passphrase_confirm="MOOP"
  99. fi
  100. if [ "${passphrase}" != "${passphrase_confirm}" ] ; then
  101. echo "The passphrases do not match."
  102. fi
  103. done
  104. echo "Creating filesystems and mounting pseudo-filesystems"
  105. lvpdata=1
  106. while [ ${lvpdata} -le ${needed_pseudofs} ] ; do
  107. eval "lodev=\${loopdevice_${lvpdata}}"
  108. file="livesystem/lvp.data${lvpdata}"
  109. echo "Setting up loopdevice ${lvpdata}"
  110. echo "${passphrase}" | losetup -p 0 -e ${LVP_ENCRYPTION}256 ${lodev} ${file}
  111. echo "Creating Filesystem ${lvpdata}"
  112. mkfs.ext2 -m 0 ${lodev} >/dev/null 2>&1
  113. echo "Mounting Filesystem ${lvpdata}"
  114. mount ${lodev} livesystem/mnt${lvpdata}
  115. rm -rf livesystem/mnt${lvpdata}/*
  116. lvpdata=$(( ${lvpdata} + 1 ))
  117. done
  118. continue=0
  119. while read file ; do
  120. [ ! -f "${file}" ] && continue
  121. [ ${continue} -eq 1 ] && continue
  122. unset target
  123. thisfile=`ls -l "${file}" | sed 's, *, ,g' | cut -f5 -d' '`
  124. for dir in livesystem/mnt? ; do
  125. avail=`df -P ${dir} | grep / | sed 's, *, ,g' | cut -f4 -d' '`
  126. avail=$(( ${avail} * 1024 ))
  127. [ -z "${target}" -a ${avail} -gt ${thisfile} ] && target=${dir}
  128. done
  129. if [ -z "${target}" ] ; then
  130. echo "Not enough space available for ${file}. Skipping remaining files." >&2
  131. continue=1
  132. fi
  133. [ ${continue} -eq 1 ] && continue
  134. echo "Copying ${file} to ${target}/${file##*/}"
  135. if [ -z "${ddparam}" ] ; then
  136. cp "${file}" "${target}/${file##*/}"
  137. else
  138. dd "if=${file}" "of=${target}/${file##*/}" bs=1k ${ddparam}
  139. fi
  140. environment="`echo ${file} | tr '[. \-!]' '_'`"
  141. eval "export file_${environment##*/}=\"${target#*livesystem}/${file##*/}\""
  142. done < ${moviefiles}
  143. lvpxml=livesystem/mnt1/lvp.xml
  144. process_create_lvpxml
  145. lvpdata=${needed_pseudofs}
  146. while [ ${lvpdata} -ge 1 ] ; do
  147. echo "Umounting Filesystem ${lvpdata}"
  148. umount livesystem/mnt${lvpdata}
  149. eval "lodev=\${loopdevice_${lvpdata}}"
  150. echo "Shutting down loopdevice ${lodev}"
  151. losetup -d ${lodev}
  152. lvpdata=$(( ${lvpdata} - 1 ))
  153. done
  154. exit 0
  155. }