blob: fd6cbc895d35144542d633c12090634db2b7e6aa (
plain) (
blame)
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
|
#! /usr/bin/env dash
# shellcheck source=/dev/null
. %SHELL_LIBRARY_PATH
git_repo_home="$XDG_CONFIG_HOME"/git_repo
[ -d "$git_repo_home" ] || mkdir "$git_repo_home"
launch_dir="$(dirname "$(readlink -f "$0")")"
. "$launch_dir"/utils
add() {
name=$(basename "$1")
while clean files | awk '{print $1}' | grep -w "^$name$" > /dev/null;do
printf "\"%s\" already exists, new name for link: " "$name"
read -r name
done
cp "$1" "$git_repo_home"/"$name"
{
printf "%s " "$name";
printf "%s " "$1";
printf "%s\n" "$(stat -c "%a" "$1")"
} >> "$git_repo_home"/files
}
remove() {
tmp=$(grepw "$1")
if pre_check "$tmp";then
file_path="$(awk '{print $2}' "$tmp")"
file_name="$(awk '{print $1}' "$tmp")"
rm "$git_repo_home"/"$file_name"
grep -v "$1" "$git_repo_home"/files > "$tmp"
cat "$tmp" > "$git_repo_home"/files
fi
}
gitw() {
git --git-dir="$git_repo_home"/.git --work-tree="$git_repo_home" "$@"
}
deploy_files() {
tmp=$(grepw "$1")
if pre_check "$tmp";then
file_path="$(awk '{print $2}' "$tmp")"
file_name="$(awk '{print $1}' "$tmp")"
file_bits="$(awk '{print $3}' "$tmp")"
if [ -e "$file_path" ] && ! cmp "$git_repo_home"/"$file_name" "$file_path" > /dev/null;then
if overwrite_check "$file_path" "$file_name" "file" ;then
cp -f "$git_repo_home"/"$file_name" "$file_path"
fi
elif cmp "$git_repo_home"/"$file_name" "$file_path" > /dev/null;then
[ "$AUTO_GEN" = "Y" ] || msg "File is already deployed"
else
cp "$git_repo_home"/"$file_name" "$file_path"
chmod "$file_bits" "$file_path"
fi
fi
}
update() {
tmp=$(grepw "$1")
if pre_check "$tmp";then
file_path="$(awk '{print $2}' "$tmp")"
file_name="$(awk '{print $1}' "$tmp")"
if [ -e "$file_path" ] && ! cmp "$git_repo_home"/"$file_name" "$file_path" > /dev/null;then
if overwrite_check "$file_path" "$file_name" "backup" ;then
cp -f "$file_path" "$git_repo_home"/"$file_name"
fi
elif cmp "$git_repo_home"/"$file_name" "$file_path" > /dev/null;then
[ "$AUTO_GEN" = "Y" ] || msg "File does not need to be updated"
else
die "File does not exist on the system!"
fi
fi
}
usage() {
cat << EO
This is config, an easy dotfiles backup service!
help Outputs this help
add Adds the specified files
remove Removes the specified files
commit Same as 'config git commit'
git Runs git with the arguments in the backup directory
deploy Copies the specified file, or all files to their location
dump Dumps the 'files' file
update Updates the specified file, or all files if none are supplied
grep Searches for the supplied string in the 'files' file
EO
exit "$1"
}
case "$1" in
"help")
shift 1
usage 0
;;
"add")
shift 1
while [ "$1" != "" ];do
add "$(readlink -f "$1")"
shift 1
done
;;
"remove")
shift 1
shift_througth "remove" "$@"
;;
"commit")
shift 1
gitw commit
;;
"git")
shift 1
gitw "$@"
;;
"deploy")
shift 1
shift_througth "deploy_files" "$@"
;;
"dump")
shift 1
cat "$git_repo_home"/files
;;
"update")
shift 1
shift_througth "update" "$@"
;;
"grep")
shift 1
tmp=$(grepw "$1")
cat "$tmp"
;;
*)
echo "Option $1 not recognized!"
usage 1
;;
esac
if [ -d /tmp/LIB_FILE_TEMP_DIR/ ];then rm -r /tmp/LIB_FILE_TEMP_DIR/; fi
|