-
Notifications
You must be signed in to change notification settings - Fork 4
/
setup.sh
107 lines (101 loc) · 3.68 KB
/
setup.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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# get os
if [[ $(uname -s) == "Darwin" ]]
then
KERNEL="Darwin"
OS="macos"
elif [[ $(uname -s) == "Linux" ]]
then
KERNEL="Linux"
if [[ -f /etc/arch-release ]]
then
OS="arch"
elif [[ -f /etc/debian_version ]]
then
OS="debian"
elif [[ -f /etc/redhat-release ]]
then
OS="fedora"
fi
else
echo "Could not determine system"
exit 1
fi
if command -v brew > /dev/null 2>&1
then
PACMAN='brew install'
PACSEARCH='brew list --formula'
PACAPPSEARCH='brew list --cask'
PACAPP='brew cask install'
else
declare -A osInfo;
osInfo[/etc/redhat-release]='sudo dnf --assumeyes install'
osInfo[/etc/arch-release]='sudo pacman -S --noconfirm'
osInfo[/etc/gentoo-release]='sudo emerge'
osInfo[/etc/SuSE-release]='sudo zypper in'
osInfo[/etc/debian_version]='sudo apt-get --assume-yes install'
declare -A osSearch;
osSearch[/etc/redhat-release]='dnf list installed'
osSearch[/etc/arch-release]='pacman -Qq'
osSearch[/etc/gentoo-release]="cd /var/db/pkg/ && ls -d */*| sed 's/\/$//'"
osSearch[/etc/SuSE-release]='rpm -qa'
osSearch[/etc/debian_version]='dpkg -l' # previously `apt list --installed`. Can use `sudo apt-cache search`.
for f in "${!osInfo[@]}"
do
if [[ -f $f ]];then
PACMAN="${osInfo[$f]}"
PACAPP="${osInfo[$f]}"
fi
done
for s in "${!osSearch[@]}"
do
if [[ -f $s ]];then
PACSEARCH="${osSearch[$s]}"
PACAPPSEARCH="${osSearch[$s]}"
fi
done
fi
notify_user() {
case ${1} in
w) echo -e "\u001b[1;34m===>\u001b[0;38m\t\u001b[1;38m${2}\u001b[0;38m" ;;
g) echo -e "\u001b[1;34m===>\u001b[0;38m\t\u001b[1;38;5;2m${2}\u001b[0;38m" ;;
y) echo -e "\u001b[1;34m===>\u001b[0;38m\t\u001b[1;33m${2}\u001b[0;38m" ;;
r) echo -e "\u001b[1;34m===>\u001b[0;38m\t\u001b[1;31m${2}\u001b[0;38m" ;;
i) echo -e "\u001b[1;34m===>\u001b[0;38m\t\u001b[0;3;38m${2}\u001b[0;38m" ;;
*) echo -e "\u001b[1;34m===>\u001b[0;38m\t\u001b[1;38m${2}\u001b[0;38m" ;;
esac
}
notify_user y "Please ensure you are at the root level of your TypeDBClient directory. Starting script..."
sleep 5
[[ "$(uname -s)" == "Darwin" ]] && notify_user w "Attempting to install GNU Sed" && $PACMAN gnu-sed > /dev/null 2>&1
notify_user w "Attempting to install ProtoBuf"
$PACMAN protobuf > /dev/null 2>&1
julia -E 'import Pkg; Pkg.add("ProtoBuf")' > /dev/null 2>&1
git switch protoc-gen > /dev/null 2>&1
notify_user w "Creating generated directories"
mkdir -p src/generated/protobuf/
notify_user w "Obtaining official TypeDBLabs protocol files"
git clone https://github.com/typedblabs/protocol.git/ > /dev/null 2>&1
mv protocol/protobuf/* src/generated/protobuf/ && rm -rf protocol
cd src/generated/
notify_user w "Installing additional ProtoBuf dependencies"
git clone https://github.com/JuliaIO/ProtoBuf.jl/ protobuf/ProtoBuf.jl/ > /dev/null 2>&1
julia --project=protobuf/ProtoBuf.jl/ -E 'import Pkg; Pkg.instantiate()' > /dev/null 2>&1
notify_user w "Adding Julia ProtoBuf executable to your path"
export PATH="$PATH:$PWD/protobuf/ProtoBuf.jl/plugin/"
notify_user w "Attempting to install correct version of sed"
if [[ "$(uname -s)" == "Darwin" ]] || [[ "$(uname -s)" == "FreeBSD" ]]; then
SED="gsed"
else
SED="sed"
fi
notify_user w "Correcting imports in protocol files"
ls protobuf/
for i in protobuf/*; do # correct imports
[ "${i##*.}" == "proto" ] || continue
$SED -i 's|\(import\s\)\"protobuf\/\(.*\.proto\)\"\;|\1\"\2\"\;|g' $i
done
notify_user w "Generating Julia protocol files"
for i in protobuf/*; do # generate files
[[ -d $i ]] && continue
[[ $i == "BUILD" ]] || protoc -I=protobuf --julia_out=. $i
done