Skip to content

Commit bccff56

Browse files
committed
init: start new project [create-git] as wrapper for git command
0 parents  commit bccff56

File tree

7 files changed

+207
-0
lines changed

7 files changed

+207
-0
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
/git
2+
/src/create-git.sh.x.c
3+
/src/git
4+
.idea/

README.md

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
# Create Git - Executable file with SSH Key
2+
This project contains tool to generate binary executable git file which using your SSH private key in passed path.
3+
This is wrapper for git command.
4+
5+
## Why and When ?
6+
- When You are working on private machine (Notebook, Desktop) and You would like to separate your
7+
private configuration (private OpenSource projects) and your company configuration.
8+
- When Your company has implemented not-standard authentication methods (i.e., Username & Password) by HTTPS
9+
(i.e., by Token in GitLab self-hosted)
10+
- When Your favourite IDE does not support and store path to SSH Key for Git (i.e., PyCharm 2021.1.2)
11+
- When You don't run ssh-agent in daemon mode using only in your company (and adding SSH Key to each session in shell)
12+
- When You don't want to configure in global home directory ssh-keys used by Your company [Security Reason]
13+
14+
## Requirements
15+
- ssh
16+
- ssh-agent
17+
- ssh-add
18+
- bash
19+
- git
20+
- shc # compile sh scripts to binary executable
21+
22+
## Installation
23+
24+
### [How to install required SHC](doc/install.md)
25+
26+
### Create-Git
27+
28+
Download or clone this repository:
29+
30+
git clone https://github.com/Webinterpret/create-git.git
31+
Change directory:
32+
33+
cd create-git
34+
35+
Check files:
36+
37+
ls -la
38+
39+
Compare if structure is like below:
40+
41+
├── create-git # The main git executable creator (compiled from ./src/create-git.sh)
42+
├── README.md # This README.md file
43+
└── src # Source directory
44+
├── create-git.sh # Main git executable creator source code written in bash
45+
└── git.sh # Main source code of git wrapper command used to compile locally written in bash
46+
47+
48+
## Usage (after `cd` to `create-git` directory)
49+
50+
To see available options:
51+
52+
$ ./create-git -h
53+
or
54+
55+
$ ./create-git --help
56+
57+
or
58+
59+
$ ./create-git -?
60+
61+
62+
Example:
63+
64+
$ ./create-git -k /path/to/your/company/topsecret/private/key [-s|--source] [i.e. /home/{user}/repositories/create-git/src] [-t|--target] [i.e. /top/secret/path/to/encrypted/company/drive/bin/]
65+
66+
67+
## Compiling `create-git.sh` script
68+
69+
When you change `/src/create-git.sh` file then you need to compile new version like below (when you inside main project dir):
70+
71+
$ shc -f src/create-git.sh -o create-git && rm src/create-git.sh.x.c
72+
73+
After that you can commit new version for create-git tool.
74+
75+
## Use cases
76+
77+
When you want to change system git executable in PyCharm:
78+
79+
1. Open `Settings`
80+
2. Find `Version Control` section
81+
3. Find `Git` section
82+
4. Find `Git executable` and fill like below:
83+
![pycharm](./doc/pycharm.png)

create-git

17.1 KB
Binary file not shown.

doc/install.md

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
## Installation
2+
3+
### SHC (Required)
4+
1. For Debian family [Debian, Ubuntu, Xubuntu, Lubuntu, etc.]
5+
6+
7+
sudo add-apt-repository -y ppa:neurobin/ppa
8+
sudo apt-get update
9+
sudo apt-get install shc
10+
11+
2. For ArchLinux family [ArchLinux, Manjaro, etc.]
12+
13+
14+
pacman -S shc
15+
16+
Alternative by `yay` or alias for yay `ya`:
17+
18+
yay -S shc
19+
ya -S shc
20+
21+
22+
3. CentOS & Fedora family [CentOS, Fedora, etc.]
23+
24+
25+
yum install -y epel-release shc
26+
27+
X. From source:
28+
29+
Download the latest version of shc
30+
Open a terminal and changeg directory to your downloads directory, or wherever the tar file is.
31+
Extract it:
32+
33+
$ tar xvfz shc-4.0.3.tar.gz # depending on version
34+
35+
Then do the installation:
36+
37+
$ ./configure
38+
...
39+
$ make
40+
...
41+
$ sudo make install
42+
...
43+
44+
### [Back to README](../README.md)

doc/pycharm.png

196 KB
Loading

src/create-git.sh

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
#!/bin/bash
2+
key=""
3+
source="./src/"
4+
target="."
5+
6+
NC='\033[0m'
7+
RED='\033[0;31m'
8+
GREEN="\033[0;32m"
9+
YELLOW='\033[1;33m'
10+
BLUE='\033[0;34m'
11+
12+
function help() {
13+
echo
14+
echo "Create Git - Tool to create binary executable git file using compiled SSH Key"
15+
echo
16+
echo -e "Syntax: ${GREEN}create-git ${YELLOW}[OPTIONS]${NC}"
17+
echo
18+
echo "Example usage: "
19+
echo -e "${BLUE}$ ${NC}create-git -k /path/to/your/company/topsecret/private/key [-s|--source] [i.e. /home/{user}/repositories/create-git/src] [-t|--target] [i.e. /top/secret/path/to/encrypted/company/drive/bin/]"
20+
echo
21+
echo "OPTIONS:"
22+
echo " -k, --key Full absolute path to SSH Key file (i.e. /home/{user}/.ssh/id_rsa)"
23+
echo " [-h, --help, -?] Print this help"
24+
echo " [-s, --source] Path to source directory"
25+
echo " [-t, --target] Target source to create git executable file"
26+
echo
27+
}
28+
29+
no_args="true"
30+
while [[ $# -gt 0 ]]; do
31+
option="$1"
32+
33+
case $option in
34+
-k|--key)
35+
key="$2"
36+
shift # past argument
37+
shift # past value
38+
;;
39+
-s|--source)
40+
source="$2"
41+
shift # past argument
42+
shift # past value
43+
;;
44+
-t|--target)
45+
target="$2"
46+
shift # past argument
47+
shift # past value
48+
;;
49+
-h|--help|-?)
50+
help
51+
shift # past argument
52+
shift # past value
53+
;;
54+
*)
55+
# shellcheck disable=SC2059
56+
printf "${RED}Unknown option passed:${NC} ${YELLOW}$1${NC}\n\n"
57+
help
58+
exit
59+
;;
60+
esac
61+
no_args="false"
62+
done;
63+
64+
if [[ "$no_args" == "true" ]]; then
65+
echo -n 'Enter source to private key SSH: '
66+
read -r key
67+
fi
68+
69+
cp "$source/git.sh" git.sh.tmp
70+
sed -i -e "s|\$SSH_KEY|$key|g" git.sh.tmp
71+
shc -f git.sh.tmp
72+
mv git.sh.tmp.x "$target/git"
73+
rm git.sh.tmp*

src/git.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/bin/bash
2+
args="${@}"
3+
ssh-agent bash -c "ssh-add $SSH_KEY; git $args"

0 commit comments

Comments
 (0)