Index

s3-bsync / 2414eba

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

Latest Commit

{#}TimeHashSubjectAuthor#(+)(-)GPG?
1016 Jun 2022 12:0894fa0b0Clean up repo, begin work on class abstraction and serializationJosh Stockin132G

Blob @ s3-bsync / install.sh

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