mirror of
https://git.alemi.dev/gitshell.git
synced 2024-11-12 18:59:19 +01:00
feat: pushing existing commands
i made this some time ago, pushing as one commit
This commit is contained in:
commit
6bdae48354
16 changed files with 395 additions and 0 deletions
27
descr
Executable file
27
descr
Executable file
|
@ -0,0 +1,27 @@
|
|||
#!/bin/bash
|
||||
|
||||
REPOSITORY="$1"
|
||||
|
||||
if [[ ! "$REPOSITORY" == *.git ]]; then
|
||||
REPOSITORY="$REPOSITORY.git"
|
||||
fi
|
||||
|
||||
if [ $# -eq 0 ]; then
|
||||
echo "[!] no repository name specified"
|
||||
exit
|
||||
fi
|
||||
|
||||
if [ ! -d "/srv/git/$REPOSITORY" ]; then
|
||||
echo "[!] repository does not exist"
|
||||
exit
|
||||
fi
|
||||
|
||||
if [ $# -eq 1 ]; then
|
||||
echo "[!] no branch name specified"
|
||||
exit
|
||||
fi
|
||||
|
||||
|
||||
echo "$2" > "/srv/git/$REPOSITORY/description"
|
||||
echo "Changed description of $REPOSITORY to '$2'"
|
||||
|
41
fetch-mirrors
Executable file
41
fetch-mirrors
Executable file
|
@ -0,0 +1,41 @@
|
|||
#!/usr/bin/env python3
|
||||
|
||||
import os
|
||||
import os.path
|
||||
import subprocess
|
||||
|
||||
GIT_ROOT = os.environ.get("GIT_ROOT_DIR") or "/srv/git/"
|
||||
|
||||
def is_mirror(repo):
|
||||
cmd = ["git", "config", "-f", f"{GIT_ROOT}{repo}/config", "remote.origin.mirror"]
|
||||
proc = subprocess.run(cmd, stdout=subprocess.PIPE)
|
||||
if proc.stdout.decode().strip() == "true":
|
||||
return True
|
||||
return False
|
||||
|
||||
def get_direction(repo):
|
||||
cmd = ["git", "config", "-f", f"{GIT_ROOT}{repo}/config", "remote.origin.direction"]
|
||||
proc = subprocess.run(cmd, stdout=subprocess.PIPE)
|
||||
return proc.stdout.decode().strip()
|
||||
|
||||
def fetch_all(repo):
|
||||
print(f"[<] Fetching {repo}")
|
||||
subprocess.run(["git", "fetch", "--all"], cwd=GIT_ROOT+repo)
|
||||
if os.path.isfile(f"{GIT_ROOT}{repo}/hooks/post-receive"):
|
||||
subprocess.run([f"{GIT_ROOT}{repo}/hooks/post-receive"])
|
||||
|
||||
def push_all(repo):
|
||||
print(f"[>] Pushing {repo}")
|
||||
subprocess.run(["git", "push", "origin"], cwd=GIT_ROOT+repo)
|
||||
#subprocess.run([f"{GIT_ROOT}.hooks/post-update"], cwd=GIT_ROOT+repo)
|
||||
|
||||
if __name__ == "__main__":
|
||||
for element in os.listdir(GIT_ROOT):
|
||||
if element.endswith(".git"):
|
||||
if is_mirror(element):
|
||||
direction = get_direction(element)
|
||||
if direction == "up":
|
||||
push_all(element)
|
||||
if direction == "down":
|
||||
fetch_all(element)
|
||||
|
30
group
Executable file
30
group
Executable file
|
@ -0,0 +1,30 @@
|
|||
#!/bin/bash
|
||||
if [ $# -eq 0 ]; then
|
||||
echo "[!] no repository name specified"
|
||||
exit
|
||||
fi
|
||||
|
||||
REPOSITORY="$1" # with .git
|
||||
REPONAME="$1" # without .git
|
||||
|
||||
if [[ ! "$REPOSITORY" == *.git ]]; then
|
||||
REPOSITORY="$REPOSITORY.git"
|
||||
fi
|
||||
|
||||
if [[ "$REPONAME" == *.git ]]; then
|
||||
REPONAME=$(echo "$REPONAME" | sed 's/\.git$//')
|
||||
fi
|
||||
|
||||
if [ ! -d "/srv/git/$REPOSITORY" ]; then
|
||||
echo "[!] repository doesn't exist"
|
||||
exit
|
||||
fi
|
||||
|
||||
if [ $# -eq 1 ]; then
|
||||
git config -f "/srv/git/$REPOSITORY/config" --unset gitweb.category
|
||||
echo "[ ] unset category from $REPONAME"
|
||||
else
|
||||
git config -f "/srv/git/$REPOSITORY/config" gitweb.category "$2"
|
||||
echo "[,] set '$2' as $REPONAME category"
|
||||
fi
|
||||
|
30
head
Executable file
30
head
Executable file
|
@ -0,0 +1,30 @@
|
|||
#!/bin/bash
|
||||
|
||||
REPOSITORY="$1"
|
||||
|
||||
if [[ ! "$REPOSITORY" == *.git ]]; then
|
||||
REPOSITORY="$REPOSITORY.git"
|
||||
fi
|
||||
|
||||
if [ $# -eq 0 ]; then
|
||||
echo "[!] no repository name specified"
|
||||
exit
|
||||
fi
|
||||
|
||||
if [ ! -d "/srv/git/$REPOSITORY" ]; then
|
||||
echo "[!] repository does not exist"
|
||||
exit
|
||||
fi
|
||||
|
||||
if [ $# -eq 1 ]; then
|
||||
echo "[!] no branch name specified"
|
||||
exit
|
||||
fi
|
||||
|
||||
|
||||
cd "/srv/git/$REPOSITORY"
|
||||
git symbolic-ref HEAD "refs/heads/$2"
|
||||
git config -f "/srv/git/$REPOSITORY/config" init.defaultBranch "$2"
|
||||
|
||||
echo "Changed HEAD of $REPOSITORY to refs/heads/$2"
|
||||
|
17
help
Executable file
17
help
Executable file
|
@ -0,0 +1,17 @@
|
|||
#!/bin/bash
|
||||
echo "Command list:"
|
||||
echo " $ help print this"
|
||||
echo " $ ls list all repositories"
|
||||
echo " $ public list public repositories"
|
||||
echo " $ new <name> create new repo"
|
||||
echo " $ mirror <url> [name] mirror remote repository"
|
||||
echo " $ upstream <name> <url> set repository to push to a given remote"
|
||||
echo " $ tree <name> show file tree of repo at HEAD"
|
||||
echo " $ log <name> show commit log of repo"
|
||||
echo " $ head <repo> <name> change default branch of repository"
|
||||
echo " $ descr <repo> <text> change description of repository"
|
||||
echo " $ owner <repo> [owner] set or unset owner for repository"
|
||||
echo " $ group <repo> [group] set or unset group for repository"
|
||||
echo " $ page <repo> [page] set or unset homepage for repository"
|
||||
echo " $ show <repo> make repository public"
|
||||
echo " $ hide <repo> hide public repository"
|
25
hide
Executable file
25
hide
Executable file
|
@ -0,0 +1,25 @@
|
|||
#!/bin/bash
|
||||
if [ $# -eq 0 ]; then
|
||||
echo "[!] no repository name specified"
|
||||
exit
|
||||
fi
|
||||
|
||||
REPOSITORY="$1" # with .git
|
||||
REPONAME="$1" # without .git
|
||||
|
||||
if [[ ! "$REPOSITORY" == *.git ]]; then
|
||||
REPOSITORY="$REPOSITORY.git"
|
||||
fi
|
||||
|
||||
if [[ "$REPONAME" == *.git ]]; then
|
||||
REPONAME=$(echo "$REPONAME" | sed 's/\.git$//')
|
||||
fi
|
||||
|
||||
if [ ! -d "/srv/git/.public/$REPONAME" ]; then
|
||||
echo "[!] repository isn't public"
|
||||
exit
|
||||
fi
|
||||
|
||||
rm "/srv/git/.public/$REPONAME"
|
||||
|
||||
echo "[#] made $REPONAME hidden"
|
21
log
Executable file
21
log
Executable file
|
@ -0,0 +1,21 @@
|
|||
#!/bin/bash
|
||||
if [ $# -eq 0 ]; then
|
||||
echo "[!] no repository name specified"
|
||||
exit
|
||||
fi
|
||||
|
||||
REPOSITORY="$1"
|
||||
|
||||
if [[ ! "$REPOSITORY" == *.git ]]; then
|
||||
REPOSITORY="$REPOSITORY.git"
|
||||
fi
|
||||
|
||||
if [ ! -d "/srv/git/$REPOSITORY" ]; then
|
||||
echo "[!] repository doesn't exists"
|
||||
exit
|
||||
fi
|
||||
|
||||
cd "/srv/git/$REPOSITORY"
|
||||
echo "$ git log --graph --abbrev-commit --decorate $REPOSITORY"
|
||||
TERM=xterm git log --graph --abbrev-commit --decorate --format=format:'%C(bold blue)%h%C(reset) - %C(bold cyan)%aD%C(reset) %C(bold green)(%ar)%C(reset)%C(bold yellow)%d%C(reset)%n'' %C(white)%s%C(reset) %C(dim white)- %an%C(reset)' --all
|
||||
echo ""
|
10
ls
Executable file
10
ls
Executable file
|
@ -0,0 +1,10 @@
|
|||
#!/bin/bash
|
||||
|
||||
# ls /srv/git -I 'git-shell-commands'
|
||||
|
||||
# one above misses repos like '.dotfiles', let's do it by hand
|
||||
for f in $(ls /srv/git -a); do
|
||||
if [[ $f == *.git ]]; then
|
||||
echo $f
|
||||
fi
|
||||
done
|
30
mirror
Executable file
30
mirror
Executable file
|
@ -0,0 +1,30 @@
|
|||
#!/bin/bash
|
||||
if [ $# -eq 0 ]; then
|
||||
echo "[!] no repository specified"
|
||||
exit
|
||||
fi
|
||||
|
||||
REMOTE="origin" # TODO can we get this as argument but optionally?
|
||||
|
||||
if [ $# -eq 1 ]; then
|
||||
IFS='/' read -ra FRAGS <<< "$1"
|
||||
REPOSITORY=${FRAGS[-1]}
|
||||
REPONAME=${FRAGS[-1]}
|
||||
else
|
||||
REPOSITORY="$2" # with .git
|
||||
REPONAME="$2" # without .git
|
||||
fi
|
||||
|
||||
if [[ ! "$REPOSITORY" == *.git ]]; then
|
||||
REPOSITORY="$REPOSITORY.git"
|
||||
fi
|
||||
|
||||
if [[ "$REPONAME" == *.git ]]; then
|
||||
REPONAME=$(echo "$REPONAME" | sed 's/\.git$//')
|
||||
fi
|
||||
|
||||
git clone --mirror "$1" "/srv/git/$REPOSITORY" --origin "$REMOTE"
|
||||
git config -f "/srv/git/$REPOSITORY/config" "remote.$REMOTE.direction" "down"
|
||||
|
||||
cd "$REPOSITORY"
|
||||
/srv/git/.hooks/post-receive
|
20
new
Executable file
20
new
Executable file
|
@ -0,0 +1,20 @@
|
|||
#!/bin/bash
|
||||
if [ $# -eq 0 ]; then
|
||||
echo "[!] no repository name specified"
|
||||
exit
|
||||
fi
|
||||
|
||||
REPOSITORY="$1"
|
||||
|
||||
if [[ ! "$REPOSITORY" == *.git ]]; then
|
||||
REPOSITORY="$REPOSITORY.git"
|
||||
fi
|
||||
|
||||
if [ -d "/srv/git/$REPOSITORY" ]; then
|
||||
echo "[!] repository already exists"
|
||||
exit
|
||||
fi
|
||||
|
||||
mkdir -p "/srv/git/$REPOSITORY"
|
||||
cd "/srv/git/$REPOSITORY"
|
||||
git init --bare
|
30
owner
Executable file
30
owner
Executable file
|
@ -0,0 +1,30 @@
|
|||
#!/bin/bash
|
||||
if [ $# -eq 0 ]; then
|
||||
echo "[!] no repository name specified"
|
||||
exit
|
||||
fi
|
||||
|
||||
REPOSITORY="$1" # with .git
|
||||
REPONAME="$1" # without .git
|
||||
|
||||
if [[ ! "$REPOSITORY" == *.git ]]; then
|
||||
REPOSITORY="$REPOSITORY.git"
|
||||
fi
|
||||
|
||||
if [[ "$REPONAME" == *.git ]]; then
|
||||
REPONAME=$(echo "$REPONAME" | sed 's/\.git$//')
|
||||
fi
|
||||
|
||||
if [ ! -d "/srv/git/$REPOSITORY" ]; then
|
||||
echo "[!] repository doesn't exist"
|
||||
exit
|
||||
fi
|
||||
|
||||
if [ $# -eq 1 ]; then
|
||||
git config -f "/srv/git/$REPOSITORY/config" --unset gitweb.owner
|
||||
echo "[ ] unset owner from $REPONAME"
|
||||
else
|
||||
git config -f "/srv/git/$REPOSITORY/config" gitweb.owner "$2"
|
||||
echo "['] set '$2' as $REPONAME owner"
|
||||
fi
|
||||
|
30
page
Executable file
30
page
Executable file
|
@ -0,0 +1,30 @@
|
|||
#!/bin/bash
|
||||
if [ $# -eq 0 ]; then
|
||||
echo "[!] no repository name specified"
|
||||
exit
|
||||
fi
|
||||
|
||||
REPOSITORY="$1" # with .git
|
||||
REPONAME="$1" # without .git
|
||||
|
||||
if [[ ! "$REPOSITORY" == *.git ]]; then
|
||||
REPOSITORY="$REPOSITORY.git"
|
||||
fi
|
||||
|
||||
if [[ "$REPONAME" == *.git ]]; then
|
||||
REPONAME=$(echo "$REPONAME" | sed 's/\.git$//')
|
||||
fi
|
||||
|
||||
if [ ! -d "/srv/git/$REPOSITORY" ]; then
|
||||
echo "[!] repository doesn't exist"
|
||||
exit
|
||||
fi
|
||||
|
||||
if [ $# -eq 1 ]; then
|
||||
git config -f "/srv/git/$REPOSITORY/config" --unset gitweb.homepage
|
||||
echo "[ ] unset homepage from $REPONAME"
|
||||
else
|
||||
git config -f "/srv/git/$REPOSITORY/config" gitweb.homepage "$2"
|
||||
echo "[@] set '$2' as $REPONAME homepage"
|
||||
fi
|
||||
|
14
public
Executable file
14
public
Executable file
|
@ -0,0 +1,14 @@
|
|||
#!/bin/bash
|
||||
|
||||
# ls /srv/git -I 'git-shell-commands'
|
||||
|
||||
# one above misses repos like '.dotfiles', let's do it by hand
|
||||
for f in $(ls /srv/git/.public -a); do
|
||||
if [[ $f == '.' ]]; then
|
||||
continue
|
||||
elif [[ $f == '..' ]]; then
|
||||
continue
|
||||
fi
|
||||
|
||||
echo "$f"
|
||||
done
|
25
show
Executable file
25
show
Executable file
|
@ -0,0 +1,25 @@
|
|||
#!/bin/bash
|
||||
if [ $# -eq 0 ]; then
|
||||
echo "[!] no repository name specified"
|
||||
exit
|
||||
fi
|
||||
|
||||
REPOSITORY="$1" # with .git
|
||||
REPONAME="$1" # without .git
|
||||
|
||||
if [[ ! "$REPOSITORY" == *.git ]]; then
|
||||
REPOSITORY="$REPOSITORY.git"
|
||||
fi
|
||||
|
||||
if [[ "$REPONAME" == *.git ]]; then
|
||||
REPONAME=$(echo "$REPONAME" | sed 's/\.git$//')
|
||||
fi
|
||||
|
||||
if [ ! -d "/srv/git/$REPOSITORY" ]; then
|
||||
echo "[!] repository doesn't exist"
|
||||
exit
|
||||
fi
|
||||
|
||||
ln -s "/srv/git/$REPOSITORY" "/srv/git/.public/$REPONAME"
|
||||
|
||||
echo "[#] made $REPONAME publicly visible"
|
19
tree
Executable file
19
tree
Executable file
|
@ -0,0 +1,19 @@
|
|||
#!/bin/bash
|
||||
if [ $# -eq 0 ]; then
|
||||
echo "[!] no repository name specified"
|
||||
exit
|
||||
fi
|
||||
|
||||
REPOSITORY="$1"
|
||||
|
||||
if [[ ! "$REPOSITORY" == *.git ]]; then
|
||||
REPOSITORY="$REPOSITORY.git"
|
||||
fi
|
||||
|
||||
if [ ! -d "/srv/git/$REPOSITORY" ]; then
|
||||
echo "[!] repository doesn't exists"
|
||||
exit
|
||||
fi
|
||||
|
||||
cd "/srv/git/$REPOSITORY"
|
||||
git ls-tree -r HEAD --name-only --full-tree | TERM=xterm less
|
26
upstream
Executable file
26
upstream
Executable file
|
@ -0,0 +1,26 @@
|
|||
#!/bin/bash
|
||||
if [ $# -lt 2 ]; then
|
||||
echo "[!] must specify both repository and remote"
|
||||
exit
|
||||
fi
|
||||
|
||||
REPOSITORY="$1"
|
||||
URL="$2"
|
||||
|
||||
if [[ ! "$REPOSITORY" == *.git ]]; then
|
||||
REPOSITORY="$REPOSITORY.git"
|
||||
fi
|
||||
|
||||
if [ ! -d "/srv/git/$REPOSITORY" ]; then
|
||||
echo "[!] repository does not exist"
|
||||
exit
|
||||
fi
|
||||
|
||||
REMOTE="origin" # TODO can we get this as argument but optionally?
|
||||
|
||||
cd "/srv/git/$REPOSITORY"
|
||||
|
||||
git remote remove "$REMOTE" # TODO this complains about branches abandoned, but we will recreate the remote right after this, so maybe do it smartly and check?
|
||||
git remote add "$REMOTE" "$URL"
|
||||
git config remote.$REMOTE.mirror "true"
|
||||
git config remote.$REMOTE.direction "up"
|
Loading…
Reference in a new issue