s243a

copy-basic-into-save.sh

Feb 17th, 2020
408
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 14.34 KB | None | 0 0
  1. #!/bin/bash
  2. ROOT=/initrd/mnt/dev_save/precise/light/5.7.2/precisesave-basic
  3. target_root=/initrd/mnt/dev_save/precise/light/5.7.2/precisesave
  4. DEFAULT_POLICY="exclude_by_blacklist"
  5. cd $ROOT
  6.  
  7. # https://linux.die.net/man/1/cpio
  8. #-u, --unconditional'
  9. #Replace all files, without asking whether to replace existing newer files with older files.
  10. #'-m, --preserve-modification-time'
  11. #Retain previous file modification times when creating files.
  12. #'-0, --null'
  13. #Read a list of filenames terminated by a null character, instead of a newline, so that files whose names contain newlines can be archived. GNU find is one way to produce a list of null-terminated filenames. This option may be used in copy-out and copy-pass modes.
  14. #'-d, --make-directories'
  15. #Create leading directories where needed.
  16. #'-p, --pass-through'
  17. #Run in copy-pass mode. see 'Copy-pass mode'.
  18. DIRS_INCLUDE_ALL=("/etc" "/initrd" "/lib" "/mnt" "/root" "/usr" "/var")
  19. FILES_INCLUDE=("/.wh..wh.orph" "/.wh..wh.aufs" "/.DirIcon" "/tmp")
  20. declare -A DIRS_INCLUDE_ALL
  21. declare -A DIR_CONTENTS_NAME
  22. declare -A PATH_INCLUDE
  23. declare -A PATH_NAME
  24. for prefix in '' '.'; do
  25.   for a_dir in ${DIRS_INCLUDE_ALL[@]}; do
  26.     a_dir="$prefix"$a_dir
  27.     key=md5_$(md5sum < <( echo "$a_dir" ) | cut -f1 -d' ')  
  28.     DIR_CONTENTS_INCLUDE[$key]=yes
  29.     DIR_CONTENTS_NAME[$key]="$a_dir"
  30.   done
  31.   for a_file in ${FILES_INCLUDE[@]}; do
  32.     a_file=$prefix$a_file
  33.     key=md5_$(md5sum < <( echo "$a_file" ) | cut -f1 -d' ')  
  34.     PATH_INCLUDE[$key]=yes
  35.     PATH_NAME[$key]="$a_file"
  36.   done
  37. done
  38. #function do_cmd(){
  39. #  
  40. #}
  41. function get_include_policy(){
  42.   local path1=$1
  43.   local key1=$2;
  44.   local path2=$3  
  45.   local key2=$4
  46.  
  47.   [ -z "$key1" ] && key1=md5_$(md5sum < <( echo "$path2" ) | cut -f1 -d' ')
  48.     if [ -z "${DIR_POLICY[$key1]}" ]; then
  49.       if [ ${#path1} -gt 2 ]; then
  50.       [ -z "$path2" ] && path2="$(dirname "$path1")"
  51.       [ -z "$key2" ] && key2=md5_$(md5sum < <( echo "$path2" ) | cut -f1 -d' ')
  52.          
  53.           get_include_policy "$path2" "$key2"
  54.           DIR_POLICY[$key]="$get_include_policy_rtn"
  55.       else
  56.           DIR_POLICY[$key]="$DEFAULT_POLICY"
  57.       fi
  58.     fi
  59.     get_include_policy_rtn="${DIR_POLICY[$key]}"
  60. }
  61. function get_include_status(){
  62.   local path_arg=$1; shift
  63.   local category=$1; shift
  64.   local opts="$@" #To be determined
  65.   local key=md5_$(md5sum < <( echo "$path_arg" ) | cut -f1 -d' ')  
  66.   local include=maybe
  67.   local policy=maybe
  68.   if [ "${PATH_INCLUDE[$key]}" = yes ]; then
  69.     include=yes
  70.   elif [ "${PATH_INCLUDE[$key]}" = no ]; then
  71.     include=no
  72.   fi
  73.   path_arg2="$(dirname "$path_arg")"
  74.   key2=md5_$(md5sum < <( echo "$(dirname "$path_arg2")" ) | cut -f1 -d' ')
  75.   category2=${CATEGORIES["$key2"]}  
  76.   if [ -d "$path_arg" ]; then
  77.     pkey="$key"
  78.     p_path="$path_arg"
  79.   else
  80.     pkey="$key2"
  81.     p_path="$path_arg2"
  82.   fi
  83.   if [ -z "${DIR_POLICY[$pkey]}" ]; then
  84.     if [ ${#p_path} -gt 2 ]; then
  85.       get_include_policy "$p_path" "$pkey"
  86.       DIR_POLICY[$pkey]="$get_include_policy_rtn"
  87.     else
  88.       DIR_POLICY[$pkey]="$DEFAULT_POLICY"
  89.     fi
  90.   fi
  91.   policy="${DIR_POLICY[$pkey]}"
  92.  
  93.   if [ "$include" = maybe ]; then
  94.     if [ -d $path_arg ]; then
  95.       if [ ${DIR_CONTENTS_INCLUDE[$key]} = yes ]; then
  96.         include=yes
  97.       elif [ ${DIR_CONTENTS_INCLUDE[$key]} = no ]; then
  98.         include=no
  99.       elif [ ${#path_arg} -le 2 ]; then
  100.         DEFAULT_POLICY
  101.       fi
  102.     fi
  103.    
  104.     if [ "$include" = maybe ]; then
  105.       if [ policy = maybe ]; then
  106.         get_include_policy "$eval_mode" "$path_arg2" "$category2"
  107.         policy2="$get_include_policy_rtn"        
  108.       fi
  109.       get_include_status "$eval_mode" "$path_arg2" "$category2"
  110.       include="$get_include_status_rtn"
  111.     fi  
  112.        
  113.   fi
  114.   get_include_status_rtn="$include"
  115.   get_include_status_rtn_policy="$policy"
  116. }
  117. function query_process_path(){
  118.    case "$2" in
  119.    directories:*)
  120.      echo yes; ;;
  121.    directory_contents:*)
  122.      key=md5_$(md5sum < <( echo "$1" ) | cut -f1 -d' ')  
  123.      if [ DIR_CONTENTS_INCLUDE[$key] = yes ]; then
  124.        echo yes
  125.      elif [ DIR_CONTENTS_INCLUDE[$key] = no ]; then
  126.        echo no
  127.      else
  128.        echo maybe
  129.      fi; ;;
  130.    esac  
  131. }
  132. function pre_eval_line(){
  133.   CMD=find
  134.   LAST_OPT="-wholename"
  135.   line="$1"
  136.   line="${line%%#*}" #Strip comments
  137.   #INDENT_NEW=${line##[[:space:]]*}
  138.   LEN_LINE=${#line}
  139.   #line=${line##[[:space:]]*}
  140.   line="$(echo "$line" | sed 's#^[[:space:]]*##')"
  141.  
  142.   LEN_LINE2=${#line}
  143.   INDENT_NEW=$((LEN_LINE-LEN_LINE2)) #Not used yet (See comments below)
  144.   #line=${line:${#INDENT_NEW}}
  145.   set -- $line
  146.   #if [ ${#INDENT_NEW} -le ${#INDENT} ]; then
  147.   #  PROCESS_LINE=yes
  148.   #else
  149.   #  if [ "$PROCESS_LINE" = maybe ]; then
  150.   #    PROCESS_LINE="$(query_process_line "$@")"
  151.   #    if [ $PROCESS_LINE = yes ] || [ $PROCESS_LINE = maybe ]; then
  152.   #      INDENT=$INDENT_NEW
  153.   #    fi
  154.   #  else
  155.   #    PROCESS_LINE=no
  156.   #  fi
  157.   #fi
  158.   #if [ "$PROCESS_LINE" = yes ] || [ "$PROCESS_LINE" = maybe ]; then
  159.     case "${line:0:1}" in #"${line:$LEADING_SPACES:1}" in
  160.   #  [[:space:]])  #https://stackoverflow.com/questions/21623268/check-if-a-given-character-is-whitespace
  161.   #    line=""; ;; #This should never happen
  162.     -)
  163.       PROCESS_OPTIONS=yes; ;;
  164.     *)
  165.       PROCESS_OPTIONS=no
  166.       line=${line:$INDENT}; ;;
  167.     esac
  168.  
  169.     options=(".")
  170.     if [ ! -z "$line" ]; then
  171.       if [ "$PROCESS_OPTIONS" = yes ]; then
  172.         while [ $# -gt 0 ]; do
  173.           case $1 in
  174.           -regextype)
  175.             options+=("$1" "$2")
  176.             shift;
  177.             shift;
  178.             LAST_OPT="-regex"; ;;
  179.           --)
  180.             shift 1
  181.             break; ;;
  182.           esac
  183.         done
  184.       fi
  185.       #do_cmd "$@" && $CMD "${options[@]}" $LAST_OPT "$1"
  186.     fi
  187.   #else
  188.   #  line=''
  189.   #fi
  190.   pre_eval_line_rtn_line="$line"
  191.   eval "pre_eval_line_rtn_pattern=$1"
  192.   eval "pre_eval_line_rtn_category=$2"
  193.   eval "pre_eval_line_rtn_policy=$3"
  194.   pre_eval_line_rtn_CMD="$CMD"
  195.   pre_eval_line_rtn_opt=( "${options[@]}" )
  196.   pre_eval_line_rtn__last_opt="$LAST_OPT"
  197. }
  198. function eval_line(){
  199.   eval_mode=$1; shift
  200.   path=$1; shift
  201.   opts="$@"
  202.  
  203.     if [ ! -z "$processed_line" ]; then
  204.    
  205.     if [ $eval_mode -eq 1 ]; then
  206.       get_include_status_and_policy "$path" ${opts[@]}
  207.         include_status
  208.       include_policy do_cmd "$@"
  209.       $CMD "${options[@]}" $LAST_OPT "$1"
  210.     elif [ $eval_mode -eq 2 ]; then
  211.       do_cmd "$@" && $CMD "${options[@]}" $LAST_OPT "$1"
  212.     fi
  213.     fi
  214. }
  215. INDENT=0
  216. INDENT_STEP=2
  217. for mode in 1 2; do
  218. while IFS="" read -r line || [ -n "$line" ]; do
  219.   result1=query_process_path
  220.   first_char=${line}
  221.   pre_eval_line "$line"
  222.   #line="$pre_eval_line_rtn_line""
  223.   pattern="$pre_eval_line_rtn_pattern"
  224.   category="$pre_eval_line_rtn_category"   
  225.   policy="$pre_eval_line_rtn_policy"   
  226.   #CMD=pre_eval_line_rtn_CMD
  227.   #options=( "${pre_eval_line_rtn_opt[@]}" )
  228.   #LAST_OPT="${pre_eval_line_rtn__last_opt}"
  229.  
  230.   while IFS="" read -r path; do
  231.     get_include_status "$path" "$category" "$policy"
  232.     case $mode in
  233.     2)
  234.       include="$get_include_status_rtn" #returned from get_include_status
  235.       policy="$get_include_status_rtn_policy" #returned from get_include_status
  236.       echo "pre:cpio; path=$path"
  237.       if [ "$include" = yes ] || [ $policy = "$exclude_by_blacklist" ]; then
  238.         cd $ROOT
  239.         echo "$path" | cpio -pdmu "$target_root"
  240.       fi
  241.      ;;
  242.     esac
  243.   done < <($CMD "${options[@]}" $LAST_OPT "$pattern") #These values are set in pre_eval_line
  244. done << 'EOF'
  245. "./usr" "directories:user"
  246. "./usr/*" "directory_contents:user"
  247.   "./usr/lib" "directories:lib"
  248.   "./usr/lib/*" "directories_contents:user/lib"
  249.     -regextype posix-basic -- "\./usr/lib/gdk-pixbuf-[^/]*" "pixbuf"
  250.     -regextype posix-basic -- "\./usr/lib/gdk-pixbuf-[^/]/*" "pixbuf"
  251.   "./usr/share" "directories:share"
  252.   "./usr/share/*" "directory_contents:user/share"
  253.     "./usr/share/icons" "directories:icons"
  254.     "./usr/share/icons/hicolor" "icons:hicolor
  255.     "./usr/share/icons/hicolor/*" "icons:hicolor
  256.     -regextype posix-basic -- "./usr/share/glib-[^/]*" "directories:glib"
  257.     -regextype posix-basic -- "\./usr/share/glib-[^/]*/schemas" "glib:schemas"
  258.     -regextype posix-basic -- "\./usr/share/glib-[^/]*/schemas/.*" "glib:schemas"
  259.     "./usr/share/backgrounds_original*"  "custom:desktop:background"
  260.     "./usr/share/backgrounds_original/*" "custom:desktop:background"
  261.     "./usr/share/i18n" "local:i18n" #Internationalizations
  262.     "./usr/share/i18n/dialog_table_x" "local:i18n" #Internationalizations
  263.   "./usr/bin" "directories:usr/bin"
  264.   "./usr/bin/*" "directory_contents:usr/bin"  
  265.     "./usr/bin/VGA_On.sh" "custon:s243a"
  266.     "./usr/bin/X" "symlinks:X"
  267.   "./usr/local" "directories:usr/local"
  268.   "./usr/local/*" "directory_contents:usr/local"  
  269.     "./usr/local/psync/" "custom:local:timeserver:psync" #Defines the time zone
  270.     "./usr/local/psync/setcountry" "custom:local:timeserver:psync" #Defines the time zone
  271.     "./usr/local/apps" "directories:roxaps"
  272.     "./usr/local/apps/ROX-Filer" "directories:roxaps"
  273.     "./usr/local/apps/ROX-Filer/ROX" "roxaps:rox"
  274.     "./usr/local/apps/ROX-Filer/ROX/*" "roxaps:rox"
  275.     "./usr/local/bin" "directories:defaults:applications"
  276.     "./usr/local/bin/defaultconnect" "custom:applications:defaultconnect"
  277. "./initrd" "directories:initrd"
  278. "./initrd/*" "directories_contents:initrd"
  279.   "./initrd/init" "initrd:init_scripts"
  280.   "./initrd/init_full_install" "initrd:init_scripts"
  281.   "./initrd/README.txt" "initrd:init_scripts"
  282.   "./initrd/mnt" "directories:initrd/mnt"
  283.   "./initrd/mnt/*" "directories_contents:initrd/mnt"
  284.   "./initrd/pup_a" "directories:layers:pup_a"
  285.   "./initrd/files" "directories:layers:files"
  286.   "./initrd/pup_z" "directories:layers:pup_z"
  287.   "./initrd/pup_ro2" "directories:layers:pup_ro2"
  288.   "./initrd/pup_rw" "directories:layers:pup_rw"
  289.   "./initrd/tmp"
  290.   "./initrd/tmp/*" "directories_contents:initrd/tmp"
  291.     "./initrd/tmp/ATADRIVES0" logs:initrd
  292.     "./initrd/tmp/dmesg.txt" logs:initrd
  293.     "./initrd/tmp/sfs_ram_sizek" logs:initrd
  294.     "./initrd/tmp/probedisk.log" logs:initrd
  295.     "./initrd/tmp/probepart.log" logs:initrd
  296.     "./initrd/tmp/ALLDRVS0" logs:initrd
  297.     "./initrd/tmp/HAVE_PARTS" logs:initrd
  298.     "./initrd/tmp/bootinit.log" logs:initrd  
  299. "./initrd/DISTRO_SPECS" "config:DISTRO_SPECS"
  300. "./.wh..wh.aufs" "whitout:type"
  301. "./mnt" "directories:mnt"
  302. "./mnt/home" "symlinks:home"
  303. "./root" "directories:root"
  304. "./root/*" "directories_contents:root"
  305.   "./root/.xinitrc"
  306.   "./root/.getflash"
  307.   "./root/.getflash/getflash-prefs"
  308.   "./root/Startup"
  309.   "./root/Startup/timesync.sh"
  310.   "./root/.local"
  311.   "./root/.local/share"
  312.   "./root/.local/share/recently-used.xbel" "private:recently-used.xbel"
  313.   "./root/.jwmrc-previous"
  314.   "./root/.XLOADED"
  315.   "./root/.icons"
  316.   "./root/.icons/ROX"
  317.   "./root/.pup_event"
  318.   "./root/.thumbnails"
  319.   "./root/.spot-status"
  320.   "./root/.jwmrc-tray"
  321.   "./root/Choices"
  322.   "./root/Choices/ROX-Filer"
  323.   "./root/Choices/ROX-Filer/PuppyPin"
  324.   "./root/.cache"
  325.   "./root/.cache/dconf"
  326.   "./root/.cache/dconf/user"
  327.   "./root/.jwmrc"
  328.   "./root/.connectwizardrc"
  329.   "./root/.config"
  330.   "./root/.config/rox.sourceforge.net"
  331.   "./root/.config/rox.sourceforge.net/ROX-Filer"
  332.   "./root/.config/rox.sourceforge.net/ROX-Filer/panels"
  333.   "./root/.config/rox.sourceforge.net/ROX-Filer/globicons"
  334.   "./root/.config/pmcputemp"
  335.   "./root/.config/pmcputemp/pmcputemprc"
  336.   "./root/.config/pmcputemp/temp.png"
  337.   "./root/.config/geany"
  338.   "./root/.config/geany/filedefs"
  339.   "./root/.config/geany/filedefs/filetypes.README"
  340.   "./root/.config/geany/keybindings.conf"
  341.   "./root/.config/geany/geany.conf"
  342.   "./root/.config/geany/templates"
  343.   "./root/.config/geany/templates/files"
  344.   "./root/.config/geany/templates/templates.README"
  345. "./etc" "directories:etc"
  346. "./etc/*" "directories_contents:etc"
  347.   ./etc/network-wizard
  348.   ./etc/network-wizard/wireless
  349.   ./etc/network-wizard/wireless/profiles
  350.   ./etc/network-wizard/wireless/profiles/??:??:??:??:??:??.*.conf "private:custom"
  351.   ./etc/network-wizard/wireless/wpa_profiles
  352.   ./etc/network-wizard/wireless/wpa_profiles/??:??:??:??:??:??.*.conf "private:custom"
  353.   ./etc/network-wizard/wireless/interfaces
  354.   ./etc/network-wizard/wireless/interfaces/??:??:??:??:??:??.conf "private:custom"
  355.   ./etc/network-wizard/network
  356.   ./etc/network-wizard/network/interfaces
  357.   ./etc/network-wizard/network/interfaces/selected_conf "private:custom"
  358.   ./etc/network-wizard/network/interfaces/??:??:??:??:??:??.conf "private:custom"
  359.   ./etc/asound.state
  360.   ./etc/hostname
  361.   ./etc/mousedevice
  362.   ./etc/keymap
  363.   ./etc/plogin
  364.   ./etc/codepage
  365.   ./etc/printcap
  366.   ./etc/machine-id
  367.   ./etc/issue
  368.   ./etc/cups
  369.   ./etc/cups/cupsd.conf
  370.   ./etc/cups/ssl
  371.   ./etc/cups/printers.conf
  372.   ./etc/cups/printers.conf.O
  373.   ./etc/cups/ppd
  374.   ./etc/services
  375.   ./etc/modprobe.d
  376.   ./etc/modprobe.d/blacklist.conf
  377.   ./etc/modprobe.d/.wh.blacklist-modem.conf
  378.   ./etc/mtab
  379.   ./etc/hosts
  380.   ./etc/xdg
  381.   ./etc/xdg/templates
  382.   ./etc/xdg/templates/_root_.jwmrc
  383.   ./etc/resolv.conf
  384.   ./etc/X11
  385.   ./etc/X11/xorg.conf
  386.   ./etc/localtime
  387.   ./etc/rc.d
  388.   ./etc/rc.d/PUPSTATE
  389.   ./etc/rc.d/MODULESCONFIG
  390.   ./etc/rc.d/BOOTCONFIG.save
  391.   ./etc/rc.d/BOOTCONFIG
  392.   ./etc/rc.d/rc.local
  393.   ./etc/pwf
  394.   ./etc/pwf/pwf.conf
  395.   ./etc/clock
  396.   ./etc/oldmousedevice
  397.   ./etc/DISTRO_SPECS
  398. ./var
  399.   ./var/cache
  400.   ./var/cache/cups
  401.   ./var/cache/cups/job.cache
  402.   ./var/cache/cups/rss
  403.   ./var/cache/cups/CUPS-PDF.pwg3
  404.   ./var/cache/cups/CUPS-PDF.ipp4
  405.   ./var/cache/fontconfig
  406.   ./var/cache/fontconfig/43c5f0feff18dfd82945432563d9d274-le32d4.cache-3
  407.   ./var/run
  408.   ./var/run/dbus
  409.   ./var/run/cups
  410.   ./var/run/cups/certs
  411.   ./var/run/dhcpcd
  412.   ./var/run/dhcpcd/resolv.conf
  413.   ./var/lib
  414.   ./var/lib/dbus
  415.   ./var/lib/dbus/machine-id
  416.   ./var/lib/xkb
  417.   ./var/lib/xkb/server-1E98292D90C4F55FD33B97814F1C19BE08CADA56.xkm
  418.   ./var/lib/xkb/server-5517831893F7E63A5A6D917848C42481F8E4E257.xkm
  419.   ./var/lib/dhcpcd
  420.   ./var/lib/dhcpcd/dhcpcd-wlan0.lease
  421.   ./var/local
  422.   ./var/local/quicksetup-network-check-flag2
  423.   ./var/local/quicksetup-timezone-table-x
  424.   ./var/local/shared
  425.   ./var/local/mscw
  426.   ./var/local/shutdown_date_saved
  427.   ./var/local/quicksetup-network-check-flag1
  428.   ./var/local/quicksetup-timezone-table-cli
  429.   ./var/local/delayedrun_firstboot_flag
  430.   ./var/local/etc_profile_at_shutdown
  431.   ./var/spool
  432.   ./var/spool/cups
  433.   ./var/spool/cups/tmp
  434.   ./var/tmp
  435.   ./var/log
  436.   ./var/log/cups
  437.   ./var/log/cups/error_log
  438.   ./var/log/Xorg.0.log
  439.   ./var/log/Xorg.0.log.old
  440.   ./var/log/previous.messages
  441. ./.DirIcon
  442. ./tmp
  443. EOF
  444.  
  445. done
Advertisement
Add Comment
Please, Sign In to add comment