Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add install script #23

Merged
merged 16 commits into from
May 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ jobs:
- name: Copy needed files to build directory
run: |
cp README.md dist/terrabutler
cp LICENSE dist/terrabutler
cp scripts/install dist/terrabutler
- name: Create archive of build (.tar.gz)
uses: sibiraj-s/action-archiver@v1
with:
Expand Down
13 changes: 12 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,15 @@ jobs:
- name: Lint Python (Flake8)
uses: grantmcconnaughey/lintly-flake8-github-action@master
with:
token: ${{ secrets.GITHUB_TOKEN }}
token: ${{ secrets.GITHUB_TOKEN }}
lint-bash:
name: Lint Bash
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Lint Bash (Shellcheck)
uses: ludeeus/action-shellcheck@master
with:
scandir: './scripts'
additional_files: 'install'
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,6 @@ cython_debug/
[Ll]ib
[Ll]ib64
[Ll]ocal
[Ss]cripts
pyvenv.cfg
pip-selfcheck.json

Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ colorama==0.4.4
contextlib2==21.6.0
flake8==4.0.1
jmespath==1.0.0
mccabe==0.6.1
mccabe==0.7.0
pycodestyle==2.8.0
pyflakes==2.4.0
python-dateutil==2.8.2
Expand Down
90 changes: 90 additions & 0 deletions scripts/install
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
#!/bin/bash

usage() {
cat 1>&2 <<EOF
Installer of Terrabutler

USAGE:
install [FLAGS] [OPTIONS]

FLAGS:
-h, --help Prints this help menu

OPTIONS:
-i, --install-dir <path> Directory where Terrabutler will be installed. By
default, this directory is: /usr/share/terrabutler

-b, --bins-dir <path> The directory where the binaries of the Terrabutler
are stored. By default, the directory is: /usr/bin/
EOF
}

cli() {
while test $# -gt 0
do
key="$1"
case "$key" in
-i|--install-dir)
USER_INSTALL_DIR="$2"
shift
;;
-b|--bins-dir)
USER_BIN_DIR="$2"
shift
;;
-h|--help)
usage
exit 0
;;
*)
printf "Argument unrecognized: '%s'" "$1"
exit 1
;;
esac
shift
done
}

apply_env () {
INSTALLER_DIR=$(pwd)
INSTALLER_DIST_DIR="$INSTALLER_DIR/dist/."
INSTALL_DIR=${USER_INSTALL_DIR:-/usr/share/terrabutler}
BINS_DIR=${USER_BIN_DIR:-/usr/bin}
BIN_FILE="$BINS_DIR/terrabutler"
}

check_preexisting_install () {
if [ -d "$INSTALL_DIR" ] && [ -f "$BINS_DIR" ]; then
echo "Found preexisting Terrabutler installation: $INSTALL_DIR."
read -r -p "Do you want to replace it? [y/N] " response
case "$response" in
[yY])
;;
*)
echo "Aborting installation."
exit 1
;;
esac
fi
}

install () {
# Copy distribution files to the installation directory
mkdir -p "$INSTALL_DIR" || exit 1
cp -a "$INSTALLER_DIST_DIR" "$INSTALL_DIR" || exit 1

# Copy binaries to user's bin directory
mkdir -p "$BINS_DIR" || exit 1
ln -s "$INSTALL_DIR/terrabutler" "$BIN_FILE" || exit 1

printf "Install has finished successfully.\nYou may now use '%s' command.\n" "$BIN_FILE"
}

main () {
cli "$@"
apply_env
check_preexisting_install
install
}

main "$@"