This commit is contained in:
joachimschmidt557 2020-03-08 17:49:13 +01:00
parent 3684533903
commit 990c3d437b

48
src
View file

@ -15,6 +15,7 @@ Commands:
ls, list List managed directories ls, list List managed directories
a, add Add a source a, add Add a source
rm, remove Remove a source directory rm, remove Remove a source directory
i, install Install a copy of this script into the current directory
Flags: Flags:
--help, -h Displays this help --help, -h Displays this help
@ -74,7 +75,7 @@ update_zipfile() {
update_item() { update_item() {
## Updates an individual item ## Updates an individual item
echo "Updating: $3" echo "src: Updating: $3"
case "$1" in case "$1" in
"git") "git")
update_gitrepo "$2" "$3" update_gitrepo "$2" "$3"
@ -86,7 +87,7 @@ update_item() {
update_zipfile "$2" "$3" update_zipfile "$2" "$3"
;; ;;
*) *)
echo "Not a valid source type: $1" echo "src: Not a valid source type: $1"
errors="$errors $3" errors="$errors $3"
;; ;;
esac esac
@ -95,7 +96,7 @@ update_item() {
preproc() { preproc() {
## Preprocess the srcfile (remove comments etc.) ## Preprocess the srcfile (remove comments etc.)
if ! [ -f "$srcfile" ] ; then if ! [ -f "$srcfile" ] ; then
echo ".srcfile not found!" echo "src: .srcfile not found!"
exit 1 exit 1
fi fi
@ -116,28 +117,22 @@ update_all() {
update_item "$type" "$url" "$path" update_item "$type" "$url" "$path"
done < "$tmp" done < "$tmp"
case "$errors" in if [ -n "$errors" ]; then
"") echo "src: Errors occurred during:$updated"
;; fi
*)
echo "Errors occurred during:$updated"
;;
esac
case "$updated" in if [ -n "$updated" ]; then
"") echo "src: Updated:$updated"
echo "Nothing updated" else
;; echo "src: Nothing updated"
*) fi
echo "Updated:$updated"
;;
esac
cleanup cleanup
} }
list_all() { list_all() {
## Parse srcfile and update everything ## Parse srcfile and list all source directories which should be managed by
## src
preproc preproc
while read -r type url path; do while read -r type url path; do
@ -171,6 +166,16 @@ diff_all() {
cleanup cleanup
} }
install_into_cd() {
## Install a copy of this script into the current working directory
script_path="$(realpath "$0")"
if install -m755 "$script_path" "$(pwd)"; then
echo "src: Install successful"
else
echo "src: Error during install"
fi
}
case "$1" in case "$1" in
"u"|"update") "u"|"update")
update_all update_all
@ -188,6 +193,9 @@ case "$1" in
"d"|"diff") "d"|"diff")
diff_all diff_all
;; ;;
"i"|"install")
install_into_cd
;;
"--help"|"-h") "--help"|"-h")
usage usage
exit 1 exit 1
@ -197,7 +205,7 @@ case "$1" in
exit 1 exit 1
;; ;;
*) *)
echo "Invalid command or flag" echo "src: Invalid command or flag"
exit 1 exit 1
;; ;;
esac esac