From 8af9f18b224a7c3307a2c70ddb7a7c938c196ea2 Mon Sep 17 00:00:00 2001 From: Fierelier Date: Mon, 9 Jan 2023 08:27:14 +0100 Subject: [PATCH] First commit --- .gitignore | 1 + LICENSE | 19 +++++++++++++++++++ currentProject | 1 + env | 5 +++++ path/project-current | 3 +++ path/project-list | 3 +++ path/project-pull | 26 ++++++++++++++++++++++++++ path/project-push | 28 ++++++++++++++++++++++++++++ path/project-sshn | 2 ++ path/ssh | 2 ++ shell | 15 +++++++++++++++ 11 files changed, 105 insertions(+) create mode 100644 .gitignore create mode 100644 LICENSE create mode 100644 currentProject create mode 100644 env create mode 100755 path/project-current create mode 100755 path/project-list create mode 100755 path/project-pull create mode 100755 path/project-push create mode 100755 path/project-sshn create mode 100755 path/ssh create mode 100755 shell diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..6c49703 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +project/ \ No newline at end of file diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..62550b0 --- /dev/null +++ b/LICENSE @@ -0,0 +1,19 @@ +Copyright (c) 2023 + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. \ No newline at end of file diff --git a/currentProject b/currentProject new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/currentProject @@ -0,0 +1 @@ + diff --git a/env b/env new file mode 100644 index 0000000..cd6642d --- /dev/null +++ b/env @@ -0,0 +1,5 @@ +# You can also export these manually while in the shell +export SSHADDR=127.0.0.1 +export SSHPORT=22 +export SSHUSER=user +export SSHPASS=pass \ No newline at end of file diff --git a/path/project-current b/path/project-current new file mode 100755 index 0000000..edeed31 --- /dev/null +++ b/path/project-current @@ -0,0 +1,3 @@ +#!/bin/bash +set -e +cat currentProject \ No newline at end of file diff --git a/path/project-list b/path/project-list new file mode 100755 index 0000000..2066d16 --- /dev/null +++ b/path/project-list @@ -0,0 +1,3 @@ +#!/bin/bash +set -e +ssh "$(project-sshn)" "ls "~/project-manager/projects"" \ No newline at end of file diff --git a/path/project-pull b/path/project-pull new file mode 100755 index 0000000..d73aad0 --- /dev/null +++ b/path/project-pull @@ -0,0 +1,26 @@ +#!/bin/bash +set -e +local_host="$HOSTNAME" +local_project="$(cat currentProject)" +remote_host="$(ssh "$(project-sshn)" "cat "~/project-manager/host"")" +remote_project="$(ssh "$(project-sshn)" "cat "~/project-manager/project"")" + +if [ "$local_project" != "" ]; then + echo "ERROR: This machine has an unpushed project: $local_project" + exit 1 +fi + +if [ "$1" == "" ]; then + echo "ERROR: No project given." + exit 1 +fi + +if [ "$remote_project" != "" ]; then + echo "ERROR: $remote_host is currently maintaining $remote_project. Push from it first." + exit 1 +fi + +echo "$local_host" | ssh "$(project-sshn)" "cat > "~/project-manager/host"" +echo "$1" | ssh "$(project-sshn)" "cat > "~/project-manager/project"" +rsync --progress --delete -a "$(project-sshn):~/project-manager/projects/$1/." "project" +echo "$1" > currentProject diff --git a/path/project-push b/path/project-push new file mode 100755 index 0000000..bbf122e --- /dev/null +++ b/path/project-push @@ -0,0 +1,28 @@ +#!/bin/bash +set -e +local_host="$HOSTNAME" +local_project="$(cat currentProject)" +remote_host="$(ssh "$(project-sshn)" "cat "~/project-manager/host"")" +remote_project="$(ssh "$(project-sshn)" "cat "~/project-manager/project"")" + +if [ "$remote_host" != "" ] && [ "$local_host" != "$remote_host" ]; then + echo "ERROR: $remote_host is currently maintaining $remote_project. Push from it first." + exit 1 +fi + +if [ "$local_project" == "" ]; then + echo "ERROR: You are not maintaining a project." + exit 1 +fi + +if [ "$remote_project" != "" ] && [ "$local_project" != "$remote_project" ]; then + echo "ERROR: You are currently maintaining $local_project on this machine, push that first." + exit 1 +fi + +set -e +rsync --progress --delete -a "project/." "$(project-sshn):~/project-manager/projects/$local_project" +echo "" | ssh "$(project-sshn)" "cat > "~/project-manager/host"" +echo "" | ssh "$(project-sshn)" "cat > "~/project-manager/project"" +echo "" > "currentProject" +rm -rf "project" \ No newline at end of file diff --git a/path/project-sshn b/path/project-sshn new file mode 100755 index 0000000..45270f4 --- /dev/null +++ b/path/project-sshn @@ -0,0 +1,2 @@ +#!/bin/bash +echo "$SSHUSER@$SSHADDR" \ No newline at end of file diff --git a/path/ssh b/path/ssh new file mode 100755 index 0000000..810627e --- /dev/null +++ b/path/ssh @@ -0,0 +1,2 @@ +#!/bin/bash +exec sshpass -e /usr/bin/ssh -o PreferredAuthentications=password -p $SSHPORT "$@" \ No newline at end of file diff --git a/shell b/shell new file mode 100755 index 0000000..310ffa2 --- /dev/null +++ b/shell @@ -0,0 +1,15 @@ +#!/bin/bash +set -e +SCRIPT_DIR="$(dirname "$(realpath -s "$BASH_SOURCE")")" +cd "$SCRIPT_DIR" +ARGS="$@" +export PATH="$SCRIPT_DIR/path:$PATH" +export PS1="\$? $PS1" +source ./env + +if [ "$ARGS" == "" ]; then + echo "-- project shell --" + exec bash +else + exec bash -c "$ARGS" +fi \ No newline at end of file