From 2fb4263bf501f3291f501f8c2fe9aa83df1be1fc Mon Sep 17 00:00:00 2001 From: joachimschmidt557 Date: Sun, 8 Mar 2020 18:10:10 +0100 Subject: [PATCH] Move to separate repo --- src | 209 ------------------------------------------------------------ 1 file changed, 209 deletions(-) delete mode 100755 src diff --git a/src b/src deleted file mode 100755 index f6e3661..0000000 --- a/src +++ /dev/null @@ -1,209 +0,0 @@ -#!/bin/sh - -srcfile=$(pwd)/.srcfile - -usage() { - ## Print usage information - cat <> "$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