-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapplyconfigs
More file actions
executable file
·84 lines (70 loc) · 1.78 KB
/
Copy pathapplyconfigs
File metadata and controls
executable file
·84 lines (70 loc) · 1.78 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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#!/bin/bash
# Takes a number of optional arguments:
# -f or --file: specifies a different file to load the config list from
# -a or --all: makes it link all files in the config source folder
# -s or --source: changes the path to the config source folder
# The final argument is flag-less. This specifies the category of config files to link. Defaults to "standard"
#######################################################################
# What separates the filelist
sepVar=","
# Default file name
filename="filelist"
# Which category of configs to link
category="standard"
# Whether or not to link all configs
all="false"
# Source file path
sourcePath=$(cd ./files; echo $PWD)
sourcePath+="/"
while [ $# -gt 0 ]; do
case "$1" in
-f|--file)
shift
filename="$1"
shift
;;
-a|--all)
all="true"
shift
;;
-s|--source)
shift
sourcePath="$1"
shift
;;
*)
category="$1"
shift
;;
esac
done
mapfile -t array < "$filename"
for index in ${!array[@]}
do
IFS="$sepVar" read -r -a nArray <<< "${array[index]}"
array[$index]=${nArray[@]}
done
# Remove header
unset array[0]
for i in "${array[@]}"
do
IFS=" " read -r -a entry <<< "$i"
# echo "$i"
fileName="${entry[0]}"
IFS="|" read -r -a fileCategory <<< "${entry[1]}"
filePath=${entry[2]/#\~/$HOME}
filePrefix=${entry[3]}
categMatch="false"
for categ in ${fileCategory[@]}
do
if [ "$categ" == "$category" ]
then
categMatch="true"
fi
done
if [ "$categMatch" == "true" ] || [ "$all" == "true" ]
then
echo "ln -sf $sourcePath$fileName $filePath$filePrefix$fileName"
ln -sf $sourcePath$fileName $filePath$filePrefix$fileName
fi
done