mirror of
https://github.com/pratiktri/dotfiles.git
synced 2026-02-04 08:41:43 +05:30
Create target directory if required
Remove hardcoded target directory
This commit is contained in:
17
bootstrap.sh
17
bootstrap.sh
@@ -1,6 +1,5 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
|
||||
usage() {
|
||||
if [ -n "$1" ]; then
|
||||
echo ""
|
||||
@@ -52,23 +51,25 @@ main () {
|
||||
TS=$(date '+%d_%m_%Y-%H_%M_%S')
|
||||
SCRIPT_DIR="$( cd -P "$( dirname "$SOURCE")" > /dev/null 2>&1 && pwd)"
|
||||
|
||||
find . -type f ! -name "$0" ! -path '*/.idea/*' ! -path '*/.git/*' ! -name 'LICENSE' ! -name 'README.md' -print0 | while IFS= read -r -d '' file
|
||||
do
|
||||
find . -type f ! -name "$0" ! -path '*/.idea/*' ! -path '*/.git/*' ! -name 'LICENSE' ! -name 'README.md' -print0 | while IFS= read -r -d '' file; do
|
||||
# Replaces `.` with `~` in the found file names
|
||||
# target_file="${file/./~}"
|
||||
target_file="${file/.//media/pratik/Projects/Code/dotfiles-test}"
|
||||
target_file="${file/./~}"
|
||||
|
||||
if [[ -f "${target_file}" ]]
|
||||
then
|
||||
if [[ -f "${target_file}" ]]; then
|
||||
mv "$target_file" "${target_file}_${TS}" && [[ "$QUIET" == "n" ]] && echo "Existing setting renamed to ${target_file}_${TS}"
|
||||
fi
|
||||
|
||||
target_directory=$(dirname "${target_file}")
|
||||
if [[ ! -d "${target_directory}" ]]; then
|
||||
mkdir -p "${target_directory}" && [[ "$QUIET" == "n" ]] && echo "Directory ${target_directory} created"
|
||||
fi
|
||||
|
||||
if [[ "$CREATE_LINKS" == "y" ]]; then
|
||||
ln -s "${file/./${SCRIPT_DIR}}" "${target_file}" && [[ "$QUIET" == "n" ]] && echo "Linked ${target_file}"
|
||||
else
|
||||
cp "${file/./${SCRIPT_DIR}}" "${target_file}" && [[ "$QUIET" == "n" ]] && echo "Copied ${target_file}"
|
||||
fi
|
||||
done;
|
||||
done
|
||||
}
|
||||
|
||||
main "$@"
|
||||
|
||||
Reference in New Issue
Block a user