Skip to content

Commit

Permalink
📦 Add install script
Browse files Browse the repository at this point in the history
  • Loading branch information
Ciaxur committed Dec 6, 2021
1 parent bbf09b2 commit 0e96149
Show file tree
Hide file tree
Showing 5 changed files with 93 additions and 7 deletions.
17 changes: 16 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,21 @@ _scripts/generate_certs.sh

❗ For **remote servers**, modify [server-ext.cnf](_scripts/server-ext.cnf) respectively.

## Installing OpenAbyss 📦
Binary home is installed under `/opt/OpenAbyss`.
Binary is symlinked in `/usr/bin/open-abyss`

Run the following,
```sh
# Generate the certificates used between the client & server. Only have to
# generate this once.
_scripts/generate_certs.sh

# Run the install script with sudo permissions.
_scripts/build.sh --install
```


## Build and Run 🚀
Building both `server` and `client` binaries by running the following,
```sh
Expand Down Expand Up @@ -124,4 +139,4 @@ At any time, passing in the `--help` flag, will print out the help menu with the


## License 📔
Licensed under the [MIT](LICENSE) License.
Licensed under the [MIT](LICENSE) License.
68 changes: 65 additions & 3 deletions _scripts/build.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#!/usr/bin/env bash

SCRIPT_DIR=`dirname $0`
pushd "$SCRIPT_DIR/.."
mkdir build
pushd "$SCRIPT_DIR/.." 1> /dev/null
mkdir build 2> /dev/null

platforms=( 'darwin' 'linux' 'windows')
archs=('amd64' 'arm64')
Expand All @@ -24,10 +24,72 @@ if [ "$1" == "--release" ]; then
done
done

elif [ "$1" == "--install" ]; then # Installs client for Linux Users
echo "Installing open-abyss client binary..."
INSTALL_PATH="/opt/OpenAbyss"
CLIENT_CONFIG=".config/config-client.json"

# Create path for OpenAbyss if fresh install, otherwise
# remove previous binary.
echo "Creating OpenAbyss User Directory '$INSTALL_PATH'"
if [ -d $INSTALL_PATH ]; then
rm $INSTALL_PATH/open-abyss 2> /dev/null
else
mkdir $INSTALL_PATH 2> /dev/null
fi

# Check for faults
if [ $? != 0 ]; then
echo "Run installation process with sudo." && exit 1
fi

# Build Client binary
echo "Building client binary."
go build -o $INSTALL_PATH/open-abyss ./client

# Check if certificates were created and warn user of certificates not
# being present, which would require another install if certificates
# are generated after installing the binary.
if [ -d ./cert ]; then
echo "Installing certificates used to communicate with the server."
cp -r ./cert $INSTALL_PATH/
else
echo "WARN: No certificates found. If you generate SSL certificates " \
"after installing this binary, be sure to re-run the installation " \
"process to ensure certificates are copied over."
fi

# Copy over configurations if present in current directory and
# not in install path.
if [ -f $CLIENT_CONFIG ] && ! [ -d $INSTALL_PATH/.config ]; then
echo "Installing client configurations."
mkdir $INSTALL_PATH/.config 2> /dev/null
cp $CLIENT_CONFIG $INSTALL_PATH/.config/
fi

# Create the final piece: The symlink!
if ! [ -f /usr/bin/open-abyss ]; then
echo "Installing symlink within the user's '/usr/bin' path"
ln -s $INSTALL_PATH/open-abyss /usr/bin/
fi

# Final CLI-bliss
echo -e "\nTo enable shell completion, add the following to your shell source rc,"
echo 'For bash: eval "$(open-abyss --completion-script-bash)"'
echo 'For zsh: eval "$(open-abyss --completion-script-zsh)"'

else
# Assumes "local" testing, with respect to the cloned repo's path
# Build based on current platform/architecture
go build -o build/server ./server
go build -o build/client ./client

# Copy certificates, if available, into build path for client to use
if [ -d ./cert ]; then
echo "Copying certificate directory to '$SCRIPT_DIR'"
cp -r ./cert ./build/
fi

fi

popd
popd 1> /dev/null
3 changes: 2 additions & 1 deletion client/configuration/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ func DisableVerbose() {

func Init() {
// Assemble internal storage paths
wd, err := os.Getwd()
bin_path, err := os.Executable()
wd := path.Dir(bin_path)
if err != nil {
log.Fatalln("could not get cwd", err)
}
Expand Down
2 changes: 1 addition & 1 deletion client/env.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
package main

var (
version = "0.1.0"
version = "0.1.1"
)
10 changes: 9 additions & 1 deletion client/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -552,9 +552,17 @@ func main() {
var conn *grpc.ClientConn
var conn_err error = nil

// Get the current binary's parent directory path which will be used for
// determining where the certificates are. (Client-Only)
bin_path, err := os.Executable()
wd := path.Dir(bin_path)
if err != nil {
log.Fatalln("could not get cwd", err)
}

// Init TLS Credentials
insecure := configuration.LoadedConfig.Insecure
tlsCertPath := configuration.LoadedConfig.TLSCertPath
tlsCertPath := path.Join(wd, configuration.LoadedConfig.TLSCertPath)

if !insecure {
creds, err := credentials.NewClientTLSFromFile(tlsCertPath, "")
Expand Down

0 comments on commit 0e96149

Please sign in to comment.