Advertisement
s243a

mv_extracted_stuff.sh (kali - Draft#2)

Feb 16th, 2021
1,233
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 12.62 KB | None | 0 0
  1. #!/bin/bash
  2. CWD="$PWD"
  3. clean=true
  4. OVERWRITE_TARGET=yes
  5. USE_NON_FULL_VERSIONS=yes
  6. USE_BB_FOR_nonFULL=yes
  7. FULL_UTILS=(tar realpath)
  8. HARDLINKED_SFS_unextracted="$(realpath ../puppy_upupgg+d_20.10.sfs)"
  9. EXTRACTED_SFS=puppy_upupgg+d_20.10.sfs.extracted
  10. NEW_SFS=puli7.3_x86_64-ungoogled-hardlinked-new.sfs
  11.  
  12. FR_SOURCE_ARCHIVE="$(realpath ../kalipup_CLI_0.0002.sfs)"
  13. FR_SOURCE_ORIG="$(realpath ./chroot-kali-rolling-i386.extracted)"
  14. [ "$clean" = true ] && rm -rf "$EXTRACTED_SFS"
  15.  
  16. EXTRACTED_SFS_FP="$CWD"/"$EXTRACTED_SFS"
  17. FR_SOURCE="$CWD"/"$EXTRACTED_SFS"/kali/cli
  18.  
  19. if [ ! -d $EXTRACTED_SFS ] ||  [ ! "$(ls -A $EXTRACTED_SFS)" ] ; then
  20.   #mkdir -p "$EXTRACTED_SFS"
  21.   uextract -o . $HARDLINKED_SFS_unextracted || { echo "failed to extract $HARDLINKED_SFS_unextracted" && exit; }
  22.   if [[ "$(basename ${HARDLINKED_SFS_unextracted}.extracted)" != "$EXTRACTED_SFS" ]]; then
  23.     mv ${HARDLINKED_SFS_unextracted}.extracted $EXTRACTED_SFS
  24.   fi
  25. fi
  26. EXTRACTED_SFS="$(realpath "$EXTRACTED_SFS")" || { echo "failed realpath \"$HARDLINKED_SFS\"" && exit; }
  27.  
  28. TARGET="$EXTRACTED_SFS"/kali; mkdir -p "$TARGET"
  29.  
  30. #See: https://forum.puppylinux.com/viewtopic.php?f=53&t=1397&p=15016&hilit=hardlinked#p15016
  31. HL_LOC="$EXTRACTED_SFS"; mkdir -p "$HL_LOC"
  32. USE_MULTI_ARCH_DIRS=yes
  33.  
  34. WARN_MV_ARCH=true
  35.  
  36. [ ! -d "$TARGET" ] && mkdir -p "$TARGET"  
  37. [ ! "$(ls -A "$TARGET")" ] && rsync -rltDv --exclude /kali --link-dest="${HL_LOC}/" "${HL_LOC}/" "${TARGET}/"
  38.  
  39. MV_LOC="$TARGET/GG-moved"; mkdir -p $MV_LOC
  40.  
  41. #set +x
  42. #read -p "press enter to continue"
  43. #set -x
  44.  
  45. if [ ! -d "$FR_SOURCE_ORIG" ]; then
  46.   uextract -o "$FR_SOURCE_ORIG" "$FR_SOURCE_ARCHIVE" || { echo "failed to extract $HARDLINKED_SFS_unextracted" && exit; }
  47. fi
  48. if [ ! -d "$FR_SOURCE_ORIG" ]; then
  49.   cp -Ra "$FR_SOURCE_ORIG" "$FR_SOURCE"
  50. fi
  51. if [ ! -d "$FR_SOURCE" ]; then
  52.   cp -Ra "$FR_SOURCE_ORIG" "$FR_SOURCE"
  53. fi
  54.  
  55. CHROOT_DIR="$TARGET" ./remove_builtin.sh --pkg-list uninstallsfs "TARGET"
  56.  
  57. #FR_SOURCE=/mnt/+mnt+sda5+test_save+ext2/firstRIB_lego/01firstrib_rootfs.sfs.extracted
  58. #Move no longer needed core libs
  59.  
  60. #if [ "$USE_MULTI_ARCH_DIRS" = yes ]; then
  61.   #while read arch_dir_rel; do
  62.      #target_arch_dir="$TARGET/$arch_dir_rel"
  63.      #arch_dir="$(basename "$arch_dir_rel")"
  64.      #parent_dir_rel="$(dirname "${arch_dir_rel}")"
  65.      #target_arch_parent="$TARGET/$parent_dir_rel"
  66.      #parent_of_arch_dir="$TARGET/$parent_dir_rel"
  67.      #fp_arch_dir="$parrent_dir/arch_dir"
  68.      ##if [ ! -d "$target_arch_dir" ]; then
  69.       ##source_dir="$FR_SOURCE/$a_dir"
  70.       #source_arch_dir="$FR_SOURCE/$arch_dir_rel"
  71.       #if [ ! -d "$source_arch_dir" ]; then
  72.         #[ -e "$target_arch_dir" ] && rm "$target_arch_dir" ;
  73.         #mkdir -p "$target_arch_dir"
  74.       #else
  75.  
  76. ##the read in this warn section causes the outer loop to be skipped so comment out until fixed.      
  77.         ##if [ "$WARN_MV_ARCH" = true ]; then #Debugging code      
  78.           ##set +x
  79.           ##echo "about to:"
  80.           ##echo "
  81.           ##cd \"$FR_SOURCE\"
  82.             ##echo ./\"${arch_dir_rel}\" | \
  83.               ##cpio -pdu \"$TARGET\" )"
  84.           ##read -p "Press enter to continue"
  85.           ##set -x
  86.          ##fi
  87.            
  88.         #( cd "$FR_SOURCE"
  89.           #echo "./${arch_dir_rel}" | \
  90.             #cpio -pdu "$TARGET" )    
  91.        #fi
  92.      ##fi
  93.  
  94.      #while read b_name; do
  95.  
  96. ##the read in this warn section causes the outer loop to be skipped so comment out until fixed.
  97.       ##if [ "$WARN_MV_ARCH" = true ]; then #Debugging code
  98.         ##set +x        
  99.         ##echo "about to:"
  100.         ##echo "
  101.          ##mv \"$target_arch_parent/$b_name\" \"$target_arch_dir/$b_name\"
  102.        ##( cd \"$target_arch_parent\"; ln -s \"$b_name\" \"$arch_dir/$b_name\" ) "
  103.          ##read -p "Press enter to continue"      
  104.         ##set -x
  105.        ##fi
  106.        #rel_path="$(dirname "$arch_dir_rel")/$b_name"
  107.        #case "$rel_path" in
  108.        #lib/lsb|lib/systemd|lib/terminfo) continue; ;;
  109.        #usr/lib/apt|usr/lib/debootstrap|usr/lib/dpkg) continue; ;;    
  110.        #usr/lib/locale|usr/lib/mime|usr/lib/NetworkManager) continue; ;;
  111.        #usr/lib/pm-utils|usr/lib/ssl|usr/lib/tmpfiles.d) continue; ;;
  112.        #esac
  113.        #[[ "$target_arch_parent/$b_name" = "$target_arch_dir" ]] && continue
  114.        #mv "$target_arch_parent/$b_name" "$target_arch_dir/$b_name"
  115.        #( cd "$target_arch_parent"; ln -s "$arch_dir/$b_name" "$b_name" )
  116.      #done < <(find $target_arch_parent -mindepth 1 -maxdepth 1 -type d | xargs -n 1 basename)
  117.   #done <<EOF
  118. #usr/local/lib/x86_64-linux-gnu
  119. #lib/x86_64-linux-gnu
  120. #usr/lib/x86_64-linux-gnu  
  121. #EOF
  122.  
  123. #fi
  124.  
  125. #if [ "$WARN_MV_ARCH" = true ]; then #Debugging code
  126.   #set +x
  127.   #echo "finished moving files to multi-arch dirs"
  128.   #read -p "Press enter to continue"
  129.   #set -x
  130. #fi
  131.  
  132.  
  133. #mkdir -p "$TARGET"/lib/glib23
  134. #while read line; do
  135.   #mv "$TARGET"/lib/$line "$TARGET"/lib/glib23/$line
  136. #done <<EOF
  137. #ld-2.23.so
  138. #ld-linux-x86-64.so.2
  139. #libanl-2.23.so
  140. #libanl.so.1
  141. #libaudit.so.1
  142. #libaudit.so.1.0.0
  143. #libBrokenLocale-2.23.so
  144. #libBrokenLocale.so.1
  145. #libbz2.so.1
  146. #libbz2.so.1.0
  147. #libbz2.so.1.0.4
  148. #libc-2.23.so
  149. #libcrypt-2.23.so
  150. #libcrypt.so.1
  151. #libc.so.6
  152. #libdbus-1.so.3
  153. #libdbus-1.so.3.14.6
  154. #libdl-2.23.so
  155. #libdl.so.2
  156. #libgpg-error.so.0
  157. #libgpg-error.so.0.17.0
  158. #libhistory.so.5
  159. #libhistory.so.6
  160. #libhistory.so.6.3
  161. #liblzma.so.0
  162. #liblzma.so.5
  163. #liblzma.so.5.0.0
  164. #libm-2.23.so
  165. #libmemusage.so
  166. #libm.so.6
  167. #libmvec-2.23.so
  168. #libmvec.so.1
  169. #libnl-3.so
  170. #libnl-3.so.200
  171. #libnl-3.so.200.22.0
  172. #libnl-genl-3.so
  173. #libnl-genl-3.so.200
  174. #libnl-genl-3.so.200.22.0
  175. #libnsl-2.23.so
  176. #libnsl.so.1
  177. #libnss_compat-2.23.so
  178. #libnss_compat.so.2
  179. #libnss_dns-2.23.so
  180. #libnss_dns.so.2
  181. #libnss_files-2.23.so
  182. #libnss_files.so.2
  183. #libnss_hesiod-2.23.so
  184. #libnss_hesiod.so.2
  185. #libnss_nis-2.23.so
  186. #libnss_nisplus-2.23.so
  187. #libnss_nisplus.so.2
  188. #libnss_nis.so.2
  189. #libpamc.so.0
  190. #libpamc.so.0.82.1
  191. #libpam_misc.so.0
  192. #libpam_misc.so.0.82.0
  193. #libpam.so.0
  194. #libpam.so.0.83.1
  195. #libpcprofile.so
  196. #libpthread-2.23.so
  197. #libpthread.so.0
  198. #libreadline.so.5
  199. #libreadline.so.6
  200. #libreadline.so.6.3
  201. #libresolv-2.23.so
  202. #libresolv.so.2
  203. #librt-2.23.so
  204. #librt.so.1
  205. #libSegFault.so
  206. #libselinux.so.1
  207. #libsepol.so.1
  208. #libsystemd.so.0
  209. #libsystemd.so.0.14.0
  210. #libthread_db-1.0.so
  211. #libthread_db.so.1
  212. #libudev.so.0
  213. #libudev.so.1
  214. #libudev.so.1.6.3
  215. #libutil-2.23.so
  216. #libutil.so.1
  217. #libz.so.1
  218. #libz.so.1.2.8
  219. #EOF
  220.  
  221. if [ 1 -ne 1 ]; then #TODO: We likely need to do something like this.
  222.   cd "$TARGET"/lib
  223.   rm ld-linux.so.2
  224. ln -s ../lib32/ld-linux.so.2 ld-linux.so.2
  225. fi
  226. #CWD="$PWD"
  227. #HARDLINKED_SFS=puli7.3_x86_64-ungoogled-hardlinked.sfs.extracted
  228. #FR_SOURCE=/mnt/+mnt+sda5+test_save+ext2/firstRIB_lego/01firstrib_rootfs.sfs.extracted
  229. #TARGET="$CWD"/"$HARDLINKED_SFS"/cont
  230.  
  231. #for folder in bin sbin usr/bin usr/sbin usr/local/bin usr/local/sbin
  232.   #for a_file in $(ls -1 $FR_SOURCE/"$folder");  do
  233.     #mkdir -p $TARGET/${folder}2
  234.     #if [[ "$(readlink "$TARGET/$folder/$a_file")" = */busybox  ]]; then
  235.       #if [ ! -h "$FR_SOURCE/$folder/$a_file" ]; then
  236.         #mv "$TARGET/$folder/$a_file" "$TARGET/${folder}2/$a_file"
  237.       #fi
  238.     #done
  239.   #done
  240. #done
  241.  
  242.  
  243. while read a_folder; do
  244.    
  245.   for a_file in $(ls -1A $FR_SOURCE/"$a_folder");  do
  246.  
  247.     #if [[ "$(readlink "$TARGET/$folder/$a_file")" = */busybox  ]]; then
  248.     #  if [ ! -h "$FR_SOURCE/$folder/$a_file" ]; then
  249.     source_file="$FR_SOURCE/$a_folder/$a_file"
  250.     target_file="$TARGET/$a_folder/$a_file"
  251.     if [ -d "$source_file" ] && [ ! -e "$target_file" ]; then
  252.       ( cd "$(dirname "$source_file")";
  253.         echo "$(basename "$source_file")" | \
  254.           cpio -pdu "$(dirname "$target_file")" )
  255.     else
  256.       if [ ! -e "$target_file" ] || [ $(stat -c %s "$source_file") -gt  $(stat -c %s "$target_file") ] || ! cmp --silent "$source_file" "$target_file"; then
  257.         if [ -d "$source_file" ]; then
  258.           if [ ! -e "$target_file" ]; then
  259.                ( cd "$FR_SOURCE";
  260.                  echo "./${a_folder}" | \
  261.                  cpio -pdu "$TARGET" )          
  262.             #mv "$target_file" "$MV_LOC/${a_folder}/$a_file"
  263.           fi
  264.         elif [ -e "$source_file" ]; then
  265.           if [ -e "$target_file" ] && [ "$OVERWRITE_TARGET" != yes ]; then
  266.             mkdir -p "$MV_LOC/${a_folder}"
  267.             mv "$target_file" "$MV_LOC/${a_folder}/$a_file"            
  268.           fi
  269.           if [ ! -d "$TARGET/${a_folder}" ]; then
  270.                ( cd "$FR_SOURCE";
  271.                  echo "./${a_folder}" | \
  272.                  cpio -pdu "$TARGET" )            
  273.           fi
  274.           ln "$source_file" "$target_file"
  275.         fi
  276.       fi
  277.       #  fi
  278.       #done
  279.     fi
  280.   done
  281.  
  282. done <<EOF
  283. $(cd "$FR_SOURCE"; find ./lib64 -type d | sed -r s#^[.]/##)
  284. $(cd "$FR_SOURCE"; find ./opt -type d | sed -r s#^[.]/##)
  285. $(cd "$FR_SOURCE"; find ./var -type d | sed -r s#^[.]/##)
  286. $(cd "$FR_SOURCE"; find ./opt -type d | sed -r s#^[.]/##)
  287. $(cd "$FR_SOURCE"; find ./usr -type d | sed -r s#^[.]/##)
  288. $(cd "$FR_SOURCE"; find ./home -type d | sed -r s#^[.]/##)
  289. $(cd "$FR_SOURCE"; find ./tmp -type d | sed -r s#^[.]/##)
  290. $(cd "$FR_SOURCE"; find ./opt -type d | sed -r s#^[.]/##)
  291. $(cd "$FR_SOURCE"; find ./sbin -type d | sed -r s#^[.]/##)
  292. $(cd "$FR_SOURCE"; find ./lib -type d | sed -r s#^[.]/##)
  293. $(cd "$FR_SOURCE"; find ./bin -type d | sed -r s#^[.]/##)
  294. $(cd "$FR_SOURCE"; find ./etc -mindepth 2 -type d | sed -r s#^[.]/##)
  295. EOF
  296.  
  297. #We don't need to copy these directories from firstribrootfs
  298. #dev
  299. #dev/pts
  300. #boot
  301. #root
  302. #sys
  303. #proc
  304. #mnt
  305. #media
  306. #run
  307. #etc
  308.  
  309. echo "include /etc/ld.so.conf.d/*.conf" >> "$TARGET/etc/ld.so.conf"
  310. export $PATH="$PATH":/usr/local/firstrib/bin >> /etc/profile #maybe do this in /root/.profile
  311.  
  312. while read a_file; do
  313.  cp -af "$FR_SOURCE/etc/$a_file" "$TARGET/etc/$a_file"
  314. done <<EOF
  315. xattr.conf
  316. environment
  317. deluser.conf
  318. ca-certificates.conf
  319. pam.conf
  320. adduser.conf
  321. debconf.conf
  322. gai.conf
  323. bindresvport.blacklist
  324. EOF
  325. #Don't need from /etc:
  326. #.pwd.lock
  327. #group-
  328. #Duplicate in /etc
  329. #gshadow
  330. #inittab
  331. #passwd
  332. #passwd-
  333. #gshadow-
  334. #inputrc
  335. #ld.so.cache
  336. #libaudit.conf
  337. #nsswitch.conf
  338. #resolv.conf
  339. #shells
  340. #shadow
  341. set -x
  342. mkdir -p "$TARGET"/full-utils
  343. if [ "$USE_NON_FULL_VERSIONS" = yes ]; then
  344.   while read a_file_rel_path; do #EXTRACTED_SFS_FP
  345.     if [[ $(file "$TARGET/${a_file_rel_path}") != *ASCII* ]]; then
  346.       #mv "$TARGET/${a_file_rel_path}-FULL" "$MV_LOC/${a_file_rel_path}-FULL"
  347.       #mv "$TARGET/${a_file_rel_path}" "$TARGET/${a_file_rel_path}-FULL"
  348.       #mv "$MV_LOC/${a_file_rel_path}" "$TARGET/${a_file_rel_path}"
  349.    
  350.       #mv "$TARGET/${a_file_rel_path}-FULL" "$MV_LOC/${a_file_rel_path}-FULL"
  351.       [[ ! -e "$EXTRACTED_SFS_FP/${a_file_rel_path}-FULL"  ]] && continue
  352.       if [[ $(file "$EXTRACTED_SFS_FP/${a_file_rel_path}") != *ASCII* ]]; then
  353.         if [[ $(readlink "$EXTRACTED_SFS_FP/${a_file_rel_path}") = *busybox* ]] || [[ $(realpath "$EXTRACTED_SFS_FP/${a_file_rel_path}") = *busybox* ]]; then
  354.           [ ! "$USE_BB_FOR_nonFULL" = yes ] && continue
  355.         else
  356.           continue #TODO think of a case where we might not want to continue here.
  357.         fi
  358.       fi  
  359.       [ -e "$TARGET/${a_file_rel_path}-FULL" ] && rm "$TARGET/${a_file_rel_path}-FULL"
  360.       mv "$TARGET/${a_file_rel_path}" "$TARGET/${a_file_rel_path}-FULL"
  361.       cp -aP "$EXTRACTED_SFS_FP/${a_file_rel_path}" "$TARGET/${a_file_rel_path}"
  362.       util_name="$(basename "$TARGET/${a_file_rel_path}")"
  363.       for a_util in "${FULL_UTILS[@]}"; do
  364.         if [ "$util_name" = "$a_util" ]; then
  365.           ( cd "${TARGET}/full-utils"; ln -s ../"${a_file_rel_path}" "$a_util" )
  366.         #else
  367.         #  ( cd "${TARGET}/full-utils"; ln -s ../"${a_file_rel_path}-FULL" "${a_util}-NOTUSED" )
  368.         fi
  369.       done
  370.       [ ! -e  "${TARGET}/full-utils/$util_name" ] && \
  371.         [ ! -e  "${TARGET}/full-utils/${util_name}-NOTUSED" ] && \
  372.           ( cd "${TARGET}/full-utils"; ln -s ../"${a_file_rel_path}-FULL" "${util_name}-NOTUSED" )
  373.     fi
  374. done <<EOF
  375. sbin/losetup
  376. sbin/pivot_root
  377. sbin/sulogin
  378. sbin/switch_root
  379. bin/df
  380. bin/echo
  381. bin/false
  382. bin/more
  383. bin/mount
  384. bin/ps
  385. bin/sleep
  386. bin/su
  387. bin/sync
  388. bin/true
  389. bin/umount
  390. usr/bin/basename
  391. usr/bin/env
  392. usr/bin/expr
  393. usr/bin/[
  394. usr/bin/logger
  395. usr/bin/mesg
  396. usr/bin/realpath
  397. usr/bin/sha1sum
  398. usr/bin/sha256sum
  399. usr/bin/tee
  400. usr/bin/tr
  401. usr/bin/unlink
  402. usr/bin/whoami
  403. usr/bin/who
  404. usr/bin/yes
  405. usr/sbin/chroot
  406. usr/sbin/fdformat
  407. usr/sbin/readprofile
  408. usr/sbin/rtcwake
  409. EOF
  410. fi
  411.  
  412. if [ 1 -ne 1 ]; then
  413.   cd "$TARGET"/lib
  414.   rm ld-linux-x86-64.so.2
  415.   ln -s ./x86_64-linux-gnu/ld-linux-x86-64.so.2 ld-linux-x86-64.so.2
  416.   ln -s ./x86_64-linux-gnu/ld-linux-x86-64.so.2 ld-linux-x86-64.so.1
  417. fi
  418. echo "export PATH=/full-utils:$PATH" > /etc/profile
  419. cd "$CWD"
  420. ./sync_file_lists.sh
  421.  
  422. #mksquashfs "$EXTRACTED_SFS" "$NEW_SFS"
  423.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement