home · contact · privacy
af5bfc0c5efc2ab4557803b15f0276d0bb552073
[config] / buster / setup_scripts / copy_dirtree.sh
1 #!/bin/sh
2 # Copy files in argument-selected subdirectories of $1 to subdirectories
3 # of $2 (which may be an empty string), e.g. with $1 of "etc_files", $2
4 # of "" and $3 of "all", copy files below etc_files/all such as
5 # etc_files/all/etc/foo/bar to equivalent locations below / such as
6 # /etc/foo/bar. Create directories as necessary. Multiple arguments after
7 # $3 are possible.
8 #
9 # CAUTION: This removes original files at the affected paths.
10 set -e
11
12 if [ "$#" -lt 3 ]; then
13     echo 'Need arguments: source root, target root, modules.'
14     false
15 fi
16 source_root="$1"
17 target_root="$2"
18 shift 2
19
20 config_tree_prefix="${HOME}/config/buster"
21 etc_files_dir="${config_tree_prefix}/etc_files"
22
23 for target_module in "$@"; do
24     cd "${source_root}/${target_module}"
25     for path in $(find . -type f); do
26         target_path="${target_root}"$(echo "${path}" | cut -c2-)
27         source_path=$(realpath "${path}")
28         dir=$(dirname "${target_path}")
29         mkdir -p "${source_path}"
30         mkdir -p "${dir}"
31         cp "${source_path}" "${target_path}"
32     done
33 done