GitRoot
craft your forge, build your project, grow your community freely
1#!/usr/bin/env bash
2
3RED='\033[0;31m'
4GREEN='\033[0;32m'
5PURPLE='\033[0;35m'
6NC='\033[0m'
7
8POSITIONAL_ARGS=()
9
10while [[ $# -gt 0 ]]; do
11 case $1 in
12 --pubKey)
13 PUB_KEY="$2"
14 shift # past argument
15 shift # past value
16 ;;
17 --privKey)
18 PRIV_KEY="$2"
19 shift # past argument
20 shift # past value
21 ;;
22 --email)
23 EMAIL="$2"
24 shift # past argument
25 shift # past value
26 ;;
27 --name)
28 NAME="$2"
29 shift # past argument
30 shift # past value
31 ;;
32 -*|--*)
33 echo "Unknown option $1"
34 exit 1
35 ;;
36 *)
37 POSITIONAL_ARGS+=("$1") # save positional arg
38 shift # past argument
39 ;;
40 esac
41done
42
43set -- "${POSITIONAL_ARGS[@]}" # restore positional parameters
44
45if [ -z "$PUB_KEY" ]; then
46 echo "Where is your ssh public key?"
47 read -p '(~/.ssh/id_rsa.pub): ' SSH_PUB_PATH
48
49 SSH_PUB_PATH=${SSH_PUB_PATH:-"~/.ssh/id_rsa.pub"}
50 SSH_PUB_PATH=${SSH_PUB_PATH/#~\//$HOME/}
51
52 if [ -f "$SSH_PUB_PATH" ]; then
53 echo -e "${GREEN}Use ssh key ${SSH_PUB_PATH}${NC}"
54 PUB_KEY=${SSH_PUB_PATH}
55 else
56 echo -e "${RED}Ssh key ${SSH_PUB_PATH} not found${NC}"
57 exit 1
58 fi
59fi
60
61if [ -z "$PRIV_KEY" ]; then
62 echo "Where is your ssh private key?"
63 read -p '(~/.ssh/id_rsa): ' SSH_PRIV_PATH
64
65 SSH_PRIV_PATH=${SSH_PRIV_PATH:-"~/.ssh/id_rsa"}
66 SSH_PRIV_PATH=${SSH_PRIV_PATH/#~\//$HOME/}
67
68 if [ -f "$SSH_PRIV_PATH" ]; then
69 echo -e "${GREEN}Use ssh key ${SSH_PRIV_PATH}${NC}"
70 PRIV_KEY=${SSH_PRIV_PATH}
71 else
72 echo -e "${RED}Ssh key ${SSH_PRIV_PATH} not found${NC}"
73 exit 1
74 fi
75fi
76
77git config commit.gpgSign true
78git config gpg.format ssh
79git config user.signingkey $PUB_KEY
80git config gpg.ssh.allowedSignersFile "$(pwd)/.gitroot/allowed_signers"
81git config core.sshCommand "ssh -i ${PRIV_KEY} -o IdentitiesOnly=yes"
82
83echo -e "${GREEN}Local git repository configured${NC}"
84
85## Email
86
87if [ -z "$EMAIL" ]; then
88 EMAIL=$(git config --get user.email)
89 echo "What email do you want to use for this repo?"
90 read -p "($EMAIL): " EMAIL
91
92 EMAIL=${EMAIL:-"$(git config --get user.email)"}
93fi
94
95echo "$EMAIL $(cat $PUB_KEY)" >> "$(pwd)/.gitroot/allowed_signers"
96sed -i -e "s/- \"\"/- $EMAIL/g" .gitroot/users.yml
97git config user.email "$EMAIL"
98
99## Name
100
101if [ -z "$NAME" ]; then
102 NAME=$(git config --get user.name)
103 echo "What name do you want to use for this repo?"
104 read -p "($NAME): " NAME
105
106 NAME=${NAME:-"$(git config --get user.name)"}
107fi
108
109sed -i -e "s/- pseudo: \"\"/- pseudo: \"$NAME\"/g" .gitroot/users.yml
110git config user.name "$NAME"
111
112echo -e "${GREEN}GitRoot configuration files updated.${NC}"
113
114echo -e "${PURPLE}Configuration finish. Please commit and push modified files.${NC}"