Move to separate repo
This commit is contained in:
parent
318025a9ae
commit
2fb4263bf5
1 changed files with 0 additions and 209 deletions
209
src
209
src
|
|
@ -1,209 +0,0 @@
|
||||||
#!/bin/sh
|
|
||||||
|
|
||||||
srcfile=$(pwd)/.srcfile
|
|
||||||
|
|
||||||
usage() {
|
|
||||||
## Print usage information
|
|
||||||
cat <<EOF
|
|
||||||
src
|
|
||||||
manages source directories
|
|
||||||
|
|
||||||
Usage: src [COMMAND]
|
|
||||||
|
|
||||||
Commands:
|
|
||||||
u, update Update source directory
|
|
||||||
ls, list List managed directories
|
|
||||||
a, add Add a source
|
|
||||||
rm, remove Remove a source directory
|
|
||||||
i, install Install a copy of this script into the current directory
|
|
||||||
|
|
||||||
Flags:
|
|
||||||
--help, -h Displays this help
|
|
||||||
--version, -v Show version and exit
|
|
||||||
EOF
|
|
||||||
}
|
|
||||||
|
|
||||||
add_item() {
|
|
||||||
## Add this item repo to the srcfile
|
|
||||||
echo "$1" "$2" "$3" >> "$srcfile"
|
|
||||||
}
|
|
||||||
|
|
||||||
rm_item() {
|
|
||||||
## Remove this entry from the srcfile and delete the source files afterwards
|
|
||||||
tmp="$srcfile.tmp"
|
|
||||||
|
|
||||||
awk "\$3 != \"$1\" { print }" "$srcfile" > "$tmp"
|
|
||||||
mv "$tmp" "$srcfile"
|
|
||||||
|
|
||||||
rm -rf "$1"
|
|
||||||
}
|
|
||||||
|
|
||||||
update_gitrepo() {
|
|
||||||
## Update/clone this git repo
|
|
||||||
if ! [ -d "$2" ] ; then
|
|
||||||
git clone "$1" "$2"
|
|
||||||
updated="$updated $2"
|
|
||||||
else
|
|
||||||
count=$(git -C "$2" pull | wc -l)
|
|
||||||
if [ "$count" -gt 1 ] ; then
|
|
||||||
updated="$updated $2"
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
update_tarfile() {
|
|
||||||
## Download and extract this tarfile if it doesn't exist yet
|
|
||||||
if ! [ -d "$2" ] ; then
|
|
||||||
wget "$1"
|
|
||||||
tar -xf "$1" -C "$2"
|
|
||||||
updated="$updated $2"
|
|
||||||
else
|
|
||||||
echo "Already downloaded"
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
update_zipfile() {
|
|
||||||
## Download and extract this zipfile if it doesn't exist yet
|
|
||||||
if ! [ -d "$2" ] ; then
|
|
||||||
wget "$1" "${2}.zip"
|
|
||||||
unzip "${2}.zip" -d "$2"
|
|
||||||
updated="$updated $2"
|
|
||||||
else
|
|
||||||
echo "Already downloaded"
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
update_item() {
|
|
||||||
## Updates an individual item
|
|
||||||
echo "src: Updating: $3"
|
|
||||||
case "$1" in
|
|
||||||
"git")
|
|
||||||
update_gitrepo "$2" "$3"
|
|
||||||
;;
|
|
||||||
"tar")
|
|
||||||
update_tarfile "$2" "$3"
|
|
||||||
;;
|
|
||||||
"zip")
|
|
||||||
update_zipfile "$2" "$3"
|
|
||||||
;;
|
|
||||||
*)
|
|
||||||
echo "src: Not a valid source type: $1"
|
|
||||||
errors="$errors $3"
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
}
|
|
||||||
|
|
||||||
preproc() {
|
|
||||||
## Preprocess the srcfile (remove comments etc.)
|
|
||||||
if ! [ -f "$srcfile" ] ; then
|
|
||||||
echo "src: .srcfile not found!"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
tmp="$srcfile.tmp"
|
|
||||||
sed 's/\s*#.*$//; /^\s*$/d' < "$srcfile" > "$tmp"
|
|
||||||
}
|
|
||||||
|
|
||||||
cleanup() {
|
|
||||||
## Cleanup everything (temp files)
|
|
||||||
rm "$tmp"
|
|
||||||
}
|
|
||||||
|
|
||||||
update_all() {
|
|
||||||
## Parse srcfile and update everything
|
|
||||||
preproc
|
|
||||||
|
|
||||||
while read -r type url path; do
|
|
||||||
update_item "$type" "$url" "$path"
|
|
||||||
done < "$tmp"
|
|
||||||
|
|
||||||
if [ -n "$errors" ]; then
|
|
||||||
echo "src: Errors occurred during:$updated"
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ -n "$updated" ]; then
|
|
||||||
echo "src: Updated:$updated"
|
|
||||||
else
|
|
||||||
echo "src: Nothing updated"
|
|
||||||
fi
|
|
||||||
|
|
||||||
cleanup
|
|
||||||
}
|
|
||||||
|
|
||||||
list_all() {
|
|
||||||
## Parse srcfile and list all source directories which should be managed by
|
|
||||||
## src
|
|
||||||
preproc
|
|
||||||
|
|
||||||
cut -d' ' -f3 < "$tmp"
|
|
||||||
|
|
||||||
cleanup
|
|
||||||
}
|
|
||||||
|
|
||||||
diff_all() {
|
|
||||||
## Show the difference of the sourcefile and the actual content of the
|
|
||||||
## directory
|
|
||||||
preproc
|
|
||||||
|
|
||||||
want=".src_want"
|
|
||||||
actual=".src_actual"
|
|
||||||
|
|
||||||
true > "$want"
|
|
||||||
true > "$actual"
|
|
||||||
|
|
||||||
# Set up want
|
|
||||||
cut -d' ' -f3 < "$tmp" | sort > "$want"
|
|
||||||
|
|
||||||
# Set up actual
|
|
||||||
find . -maxdepth 1 -type d | tail -n +2 | sed 's|^./||' | sort > "$actual"
|
|
||||||
|
|
||||||
# Diff
|
|
||||||
diff -u0 "$want" "$actual"
|
|
||||||
|
|
||||||
rm "$want" "$actual"
|
|
||||||
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
|
|
||||||
"u"|"update")
|
|
||||||
update_all
|
|
||||||
;;
|
|
||||||
"a"|"add")
|
|
||||||
add_item "$2" "$3" "$4"
|
|
||||||
update_item "$2" "$3" "$4"
|
|
||||||
;;
|
|
||||||
"rm"|"remove")
|
|
||||||
rm_item "$2"
|
|
||||||
;;
|
|
||||||
"ls"|"list")
|
|
||||||
list_all
|
|
||||||
;;
|
|
||||||
"d"|"diff")
|
|
||||||
diff_all
|
|
||||||
;;
|
|
||||||
"i"|"install")
|
|
||||||
install_into_cd
|
|
||||||
;;
|
|
||||||
"--help"|"-h")
|
|
||||||
usage
|
|
||||||
exit 1
|
|
||||||
;;
|
|
||||||
"--version"|"-v")
|
|
||||||
echo "src version 0.1.0"
|
|
||||||
exit 1
|
|
||||||
;;
|
|
||||||
*)
|
|
||||||
echo "src: Invalid command or flag"
|
|
||||||
exit 1
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue