Advertisement
s243a

Draft: mv_extracted_stuff.sh (Puppy4 - attackpup)

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