This repository has been archived by the owner on Apr 6, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
install.sh
executable file
·84 lines (74 loc) · 2.65 KB
/
install.sh
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
#!/bin/bash
BUCKET=$1
PATH_TO_CRED=$2
CRED="-o Credentials:gs_service_key_file=${PATH_TO_CRED}"
cp gspip.sh gspip.sh.tmp
if [ "$BUCKET" != "" ] ; then
echo "Setting pypi bucket to $BUCKET"
sed -i "/BUCKET=\"\"/c\BUCKET=$BUCKET" gspip.sh.tmp
else
echo "You did not specify a bucket name. Rerun the command like that : ./install.sh pypi_bucket_name path_cred."
echo "Ask your code manager if you do not know the bucket name."
exit 1
fi
if [ "$PATH_TO_CRED" != "" ] ; then
echo "Setting PATH_TO_CRED to $PATH_TO_CRED"
sed -i "/PATH_TO_CRED=\"\"/c\PATH_TO_CRED=$PATH_TO_CRED" gspip.sh.tmp
else
echo "You did not specify a path to GCP credentials. Rerun the command like that : ./install.sh pypi_bucket_name path_cred."
echo "Ask your code manager if you do not know the path."
exit 1
fi
SCRIPTPATH="$(
cd "$(dirname "$0")" || {
echoerr "Could not cd to $(dirname "$0")" ; exit 1
} >/dev/null 2>&1
pwd -P
)"
PKG_OK=$(command -v gsutil 2> /dev/null)
if [ "$PKG_OK" = "" ] ; then
echo "This program requires gsutil to be installed and operationnal."
exit 1
fi
echo "Testing gsutil connection. You should see the list of buckets in the project appear..."
echo ""
if ! gsutil $CRED ls gs://$BUCKET ; then
if ! gsutil ls gs://$BUCKET ; then
echo "Could not talk to GCS : did you specify the correct paths and buckets in the arguments of the command ?"
echo "I currently have BUCKET=$BUCKET and PATH_TO_CRED=$PATH_TO_CRED."
echo "POSSIBLE SOLUTION : if you got the message 'CommandException: You have multiple types of configured credentials'..., run the command"
echo ""
echo "'gcloud config set pass_credentials_to_gsutil false' and retry installing gspip"
echo ""
echo "This will prevent gsutil from trying to use your gcloud credentials."
echo "Note that you will not be able to use gsutil without setting a .boto file or without giving a json with credentials. "
echo "To move files from/to GCS, you can still use TransparentPath though ;)"
exit 1
fi
fi
echo ""
echo "...gsutil connection is ok"
if [ ! -d "$HOME/bin" ] ; then
echo "Creating $HOME/bin directory..."
mkdir "$HOME/bin"
if [ ! -d "$HOME/bin" ] ; then
echo "Could not create directory $HOME/bin"
exit 1
fi
echo "...successfully create directory $HOME/bin"
fi
chmod +x "$SCRIPTPATH/"*
echo "Copying gspip.sh to $HOME/bin/gspip ..."
cp "$SCRIPTPATH/gspip.sh.tmp" "$HOME/bin/gspip"
rm gspip.sh.tmp
if [ ! -f "$HOME/bin/gspip" ] ; then
echo "Could not copy gspip.sh to $HOME/bin"
exit 1
fi
echo "...copied gspip."
echo "sourcing $HOME/.profile..."
if ! source $HOME/.profile ; then
exit 1
fi
echo "... sourced"
echo "Installation complete"