Index

s3-bsync / 9613f30

Bidirectional syncing tool to sync local filesystem directories with S3 buckets. (Incomplete)

Latest Commit

{#}TimeHashSubjectAuthor#(+)(-)GPG?
518 Oct 2021 20:59dac3807Create install script; set up source directoryJosh Stockin11280G

Blob @ s3-bsync / install.sh

text/x-shellscript3780 bytesdownload raw
1#!/usr/bin/env bash
2
3# Script variables
4PYTHON_MAJOR=3
5PYTHON_MINOR=6
6ACCEPTABLE_PYTHON_COMMANDS="python3 python3.10 python3.9 python3.8 python3.7 python3.6 python"
7REQUIRED_PYTHON_MODULES=$(cat requirements.txt)
8
9
10# Plumbing
11set -o pipefail
12
13RESTORE=$(echo -en '\033[0m')
14STANDOUT=$(echo -en '\033[7m')
15RED=$(echo -en '\033[00;31m')
16GREEN=$(echo -en '\033[00;32m')
17YELLOW=$(echo -en '\033[00;33m')
18PURPLE=$(echo -en '\033[00;35m')
19LIGHTGRAY=$(echo -en '\033[00;37m')
20LRED=$(echo -en '\033[01;31m')
21LYELLOW=$(echo -en '\033[01;33m')
22LBLUE=$(echo -en '\033[01;34m')
23LCYAN=$(echo -en '\033[01;36m')
24
25SCRIPT_SOURCE_DIR=$(dirname -- "${BASH_SOURCE[0]}")
26
27
28# Handle argument input
29case $1 in
30 h|help|?|-h|-help|-?|--h|--help|--?)
31 echo "Usage: ./install.sh [install|uninstall] [<python executable>]"
32 exit 0
33 ;;
34 install)
35 PYTHON_COMMAND=$2
36 ;;
37 uninstall)
38 UNINSTALL=1
39 PYTHON_COMMAND=$2
40 ;;
41 *)
42 PYTHON_COMMAND=$1
43 ;;
44esac
45
46
47# Report operating mode
48if [ -z $UNINSTALL ]; then
49 echo "${YELLOW}Running in ${LYELLOW}INSTALL${YELLOW} mode${RESTORE}"
50else
51 echo "${YELLOW}Running in ${LYELLOW}UNINSTALL${YELLOW} mode${RESTORE}"
52 REQUIRED_PYTHON_MODULES="pip"
53fi
54
55
56# Determine Python interpreter to use
57echo "${LIGHTGRAY}Determining Python interpreter${RESTORE}"
58if [ -z $PYTHON_COMMAND ]; then
59 for COMMAND in $ACCEPTABLE_PYTHON_COMMANDS
60 do
61 if command -v $COMMAND &> /dev/null; then
62 PYTHON_COMMAND=$COMMAND
63 break
64 fi
65 done
66fi
67
68# Expand interpreter command, verify with `import sys` test instruction
69PYTHON_COMMAND=$(command -v $PYTHON_COMMAND)
70if [ -z $PYTHON_COMMAND ]; then
71 echo " ${RED}Python interpreter not found${RESTORE}"
72 exit 1
73fi
74if [ -h "$PYTHON_COMMAND" ]; then
75 PYTHON_COMMAND=$(readlink -f $PYTHON_COMMAND)
76fi
77echo " Trying interpreter [ ${LYELLOW}$PYTHON_COMMAND${RESTORE} ]"
78if ! $PYTHON_COMMAND -c "import sys"; then
79 echo " ${RED}Executable is not Python${RESTORE}"
80 exit 1
81fi
82
83
84# Verifying Python version
85echo "${LIGHTGRAY}Checking Python version${RESTORE} [ needs ${LIGHTGRAY}>=$PYTHON_MAJOR.$PYTHON_MINOR${RESTORE} ]"
86PYTHON_VERSION_STRING=$($PYTHON_COMMAND -c "print('.'.join([str(a) for a in __import__('sys').version_info[:3]]))")
87if ! $PYTHON_COMMAND -c "import sys;exit(not(sys.version_info.major==$PYTHON_MAJOR and sys.version_info.minor>=$PYTHON_MINOR))"; then
88 echo " ${RED}Python version must be ${RESTORE}[ ${LCYAN}>=$PYTHON_MAJOR.$PYTHON_MINOR${RESTORE} ]${RED}."\
89 "Installed is ${RESTORE}[ ${LCYAN}$PYTHON_VERSION_STRING${RESTORE} ]"
90 exit 1
91fi
92echo " Version [ ${LCYAN}$PYTHON_VERSION_STRING${RESTORE} ] acceptable"
93
94
95# Verifying required modules are installed
96echo "${LIGHTGRAY}Checking Python modules installed${RESTORE}"
97for MODULE in $REQUIRED_PYTHON_MODULES
98do
99 if ! $PYTHON_COMMAND -c "import $MODULE" &> /dev/null; then
100 echo " ${RED}Required Python module ${RESTORE}[ ${LBLUE}$MODULE${RESTORE} ] ${RED}not found${RESTORE}"
101 exit 1
102 fi
103 echo " Module [ ${LBLUE}$MODULE${RESTORE} ] found"
104done
105echo " ${GREEN}All required modules found${RESTORE}"
106
107
108# Set pip command based on script mode
109if [ -z $UNINSTALL ]; then
110 PIP_COMMAND="$PYTHON_COMMAND -m pip install $SCRIPT_SOURCE_DIR/"
111else
112 PIP_COMMAND="$PYTHON_COMMAND -m pip uninstall --yes s3-bsync"
113fi
114
115
116# Run pip command and handle output
117function indent() {
118 sed 's/^/ /';
119}
120echo "${LIGHTGRAY}Running [ ${PURPLE}$PIP_COMMAND${LIGHTGRAY} ]${RESTORE}"
121if $PIP_COMMAND 2>&1 | indent; then
122 echo "${GREEN}Success${RESTORE}"
123 exit 0
124else
125 ERROR_CODE=$?
126 echo "${LRED}${STANDOUT}pip did not exit successfully (status code $ERROR_CODE)${RESTORE}"
127 exit $ERROR_CODE
128fi
129