-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·37 lines (33 loc) · 1.06 KB
/
Copy pathinstall.sh
File metadata and controls
executable file
·37 lines (33 loc) · 1.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#!/bin/bash -e
cd "$(dirname "$0")"
THIS="$(basename "$0")"
# Define the files to skip
SKIP_FILES=("." ".." ".git" ".gitignore" "bin" ".ssh" "$THIS")
# Iterate over files in the directory, including dotfiles
shopt -s dotglob nullglob
for FILE in *; do
# Check if the file is in the skip list
SKIP=false
for SKIP_FILE in "${SKIP_FILES[@]}"; do
if [[ "$FILE" == "$SKIP_FILE" ]]; then
SKIP=true
break
fi
done
# If the file is not to be skipped, do something with it
if [[ "$SKIP" == false ]]; then
SOURCE="$(realpath $FILE)"
DEST="$(realpath ~)/$FILE"
if [ -e "$DEST" ] || [ -h "$DEST" ]; then
if [ -e "${DEST}.old" ] || [ -h "${DEST}.old" ]; then
echo "${DEST}.old already exists, aborting!"
exit 1
fi
echo "Moving $DEST to ${DEST}.old"
mv "$DEST" "${DEST}.old"
fi
echo "Linking $SOURCE to $(realpath ~)/$FILE"
ln -s "$SOURCE" "$DEST"
fi
done
shopt -u dotglob nullglob # not sure this is needed