First commit

This commit is contained in:
Fierelier 2023-01-09 08:27:14 +01:00
commit 8af9f18b22
11 changed files with 105 additions and 0 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
project/

19
LICENSE Normal file
View File

@ -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.

1
currentProject Normal file
View File

@ -0,0 +1 @@

5
env Normal file
View File

@ -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

3
path/project-current Executable file
View File

@ -0,0 +1,3 @@
#!/bin/bash
set -e
cat currentProject

3
path/project-list Executable file
View File

@ -0,0 +1,3 @@
#!/bin/bash
set -e
ssh "$(project-sshn)" "ls "~/project-manager/projects""

26
path/project-pull Executable file
View File

@ -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

28
path/project-push Executable file
View File

@ -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"

2
path/project-sshn Executable file
View File

@ -0,0 +1,2 @@
#!/bin/bash
echo "$SSHUSER@$SSHADDR"

2
path/ssh Executable file
View File

@ -0,0 +1,2 @@
#!/bin/bash
exec sshpass -e /usr/bin/ssh -o PreferredAuthentications=password -p $SSHPORT "$@"

15
shell Executable file
View File

@ -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