-
Notifications
You must be signed in to change notification settings - Fork 3
/
installer
executable file
·150 lines (125 loc) · 5.71 KB
/
installer
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
#!/usr/bin/env bash
# This is the installer script for GiBBERISH - Git and Bash Based Encrypted Remote Interactive Shell
# Author: Somajit Dey 2021 <[email protected]>
# Online repository: https://github.com/SomajitDey/gibberish
# Bug reports: Raise an issue at the repository or email the author directly
# Copyright (C) 2021 Somajit Dey
# License: GPL-3.0-or-later <https://github.com/SomajitDey/gibberish>
# Disclaimer: This software comes with ABSOLUTELY NO WARRANTY; use at your own risk.
export rcfile='gibberish_rc.bash'
command -v git &>/dev/null || { echo 'Install git' ; exit 1;}
command -v curl &>/dev/null || { echo 'Install curl' ; exit 1;}
command -v flock &>/dev/null || { echo 'Install flock' ; exit 1;}
command -v gpg &>/dev/null || { echo 'Install gpg' ; exit 1;}
code_dir_relative="${BASH_SOURCE%/*}"
code_dir="$(cd "${code_dir_relative}"; echo "${PWD}" )"
. "${code_dir}/${rcfile}" || { echo "Missing ${rcfile}" ; exit 1;}
echo '
GiBBERISh requires a dedicated free Git repository hosted on cloud.
If you have already created such a repository, proceed with its URL.
If you have not created a repository yet, press ENTER below to exit
this installation. Then create an empty repository at any of the
following sites for free:
github.com, gitlab.com, sourceforge.net, bitbucket.org
Note down the URL link of your newly created repository and relaunch
this installer.
'
read -ep 'Repository URL: ' url
[[ -z "${url}" ]] && exit
uri="${url#*:\/\/}"
protocol="${url%:\/\/*}"
if [[ "${protocol}" == "file" ]] || [[ "${uri}" == "${protocol}" ]]; then
[[ -d "${uri}" ]] || { echo "No such directory" ; exit 1;}
uri="$(cd "${uri}" && pwd)" # Get the absolute path
protocol="file"
localhost="true"
fetch_url="${uri}"
push_url="${uri}"
if [[ "${uri}" == /mnt/* ]]; then
echo -e \\n"NFS is not very secure. If you want encryption, please provide a passphrase. Otherwise, simply press ENTER"
read -ep 'Passphrase: ' pass
else
pass="GiBBERISh"
fi
else
protocol="https" # Because https will be allowed by every firewall, unlike ssh://
echo -e \\n'Using https:// for git-push'
localhost="false"
domain="${uri%%\/*}"
echo -e "\nEnter your ${domain} credentials below. GIBBERISh will use this during git-push."
read -ep 'Username: ' uid
read -ep 'Passwd/PAT: ' pass
tput cuu1; tput ed; echo 'Got your passwd.'
push_url="https://${uid}:${pass}@${uri}"
echo -e \\n'Is this computer behind a firewall that blocks all non-web traffic?'
while read -p '1. Yes 2. No 3. Dunno : ' -n1 choice ; do
case "${choice}" in
2)fetch_url="git://${uri}"; break;; # Because git:// is faster
1|3)fetch_url="https://${uri}"; break;;
*)echo -e \\n'Tip: Type either 1, 2 or 3';;
esac
done
echo
fi
echo -e \\n'You shall be using this PC as'
while read -p '1. Server 2. Client : ' -n1 choice ; do
case "${choice}" in
1)config="server"; talkto="client"; break;;
2)config="client"; talkto="server"; break;;
*)echo -e \\n'Tip: Type either 1 or 2';;
esac
done
echo
if ! "${localhost}"; then
echo -e \\n'Make sure you are online. We will download your repository then and configure the upstream if needed.
Press any key to confirm.'
read -sn1
fi
echo -e \\n"Configuring ${config}..."\\n
export GIBBERISH="${config}"
GIBBERISH_filesys
rm -rf "${GIBBERISH_DIR}" # Clean previous installation
mkdir -p "${GIBBERISH_DIR}"
echo "${pass}" > "${patfile}"
git clone --quiet "${fetch_url}" "${incoming_dir}" || { echo -e \\n'Git-clone failed, exiting'; exit 1;}
cd "${incoming_dir}"
# Check if repo has atleast one commit; create a commit if there is none
git checkout --quiet "${config}" &>/dev/null || \
(git checkout --quiet -b "${config}"
git commit --allow-empty -m 'Root commit'; git push --quiet origin "${config}") || \
{ echo -e \\n'Oops, something failed. Reinstall.'; exit 1;}
# Create outgoing directory; checked out with appropriate branch
# Using the following instead of the much simpler git-worktree for backward compatibility with older Ubuntus
cp -r "${incoming_dir}" "${outgoing_dir}"
cd "${outgoing_dir}"
git remote set-url origin "${push_url}"
git config --local user.name "GiBBERISh"
git config --local user.email "gibberish@${config}"
git checkout --quiet "${talkto}" &>/dev/null || git checkout --quiet -b "${talkto}"
(touch "${iofile}"; git add "${iofile}";
git commit --allow-empty -m ':'; git push --quiet origin "${talkto}") || \
{ echo -e \\n'Oops, something failed. Reinstall with correct credentials.'; exit 1;}
cp "${code_dir}/post-commit" "${outgoing_dir}/.git/hooks/post-commit" || \
{ echo -e \\n'Missing post-commit hook. Reinstall with proper package' ; exit 1;}
if [[ "${domain}" == "github.com" ]]; then
if (command -v jq && command -v base64) &>/dev/null; then
repo="${uri##*/}"; repo="${repo%.git}"
echo "-X PUT -d @${api_payload} -u ${uid}:${pass} https://api.github.com/repos/${uid}/${repo}/contents/${iofile}" \
> "${api_options_file}"
content="\"$(cat ${outgoing_dir}/${iofile} | base64)\""
jq ".content=${content} | .branch=\"${talkto}\"" < <(echo {}) > "${api_json_template}"
else
echo -e \\n"Tip: Install the programs: 'jq' and 'base64' for decreasing latency"
fi
else
[[ "${protocol}" == https ]] && echo -e \\n"Tip: Use github.com as upstream for decreasing latency"
fi
cat <(echo "export GIBBERISH=${GIBBERISH}") "${code_dir}/${rcfile}" > "${HOME}/.${rcfile}"
run_command="source ${HOME}/.${rcfile}"
grep -q -x "${run_command}" "${HOME}/.bashrc" || (echo "${run_command}" >> "${HOME}/.bashrc")
case "${config}" in
server) echo -e \\n'Command to launch: gibberish-server';;
client) echo -e \\n'Command to launch: gibberish';;
esac
echo -e \\n"To use the above command right now, either open a new shell or terminal, or use the following command:
$run_command"