This repository has been archived by the owner on Aug 30, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build-linux.sh
93 lines (78 loc) · 2.73 KB
/
build-linux.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
#!/bin/bash
function echo_blue {
echo -e "\e[34m$1\e[0m"
}
function echo_cyan {
echo -e "\e[36m$1\e[0m"
}
function echo_green {
echo -e "\e[32m$1\e[0m"
}
function refresh_environment_if_required {
if [[ $ENVIRONMENT_REFRESH_REQUIRED = true ]]; then
echo_blue "Refreshing environment variables"
source ~/.bashrc
ENVIRONMENT_REFRESH_REQUIRED=false
fi
}
# Set initial values
DOTNET_INSTALLED=false
DOTNET_6_INSTALLED=false
DOTNET_7_INSTALLED=false
ENVIRONMENT_REFRESH_REQUIRED=false
# Check if dotnet is installed
if hash dotnet 2>/dev/null; then
DOTNET_INSTALLED=true
DOTNET_VERSIONS=$(dotnet --list-sdks)
# Check if dotnet 6 is installed
if [[ $DOTNET_VERSIONS == *"6.0.314"* ]]; then
DOTNET_6_INSTALLED=true
fi
# Check if dotnet 7 is installed
if [[ $DOTNET_VERSIONS == *"7.0.305"* ]]; then
DOTNET_7_INSTALLED=true
fi
fi
# Download dotnet install script
if [[ $DOTNET_INSTALLED = false ]] || [[ $DOTNET_6_INSTALLED = false ]] || [[ $DOTNET_7_INSTALLED = false ]]; then
if [[ $DOTNET_INSTALLED = false ]]; then
echo_cyan "Installing dotnet, and SDKs 6 and 7"
elif [[ $DOTNET_6_INSTALLED = false ]] && [[ $DOTNET_7_INSTALLED = false ]]; then
echo_cyan "Updating dotnet: Installing 6 and 7 SDKs"
elif [[ $DOTNET_6_INSTALLED = false ]]; then
echo_cyan "Updating dotnet: Installing dotnet 6 SDK"
elif [[ $DOTNET_7_INSTALLED = false ]]; then
echo_cyan "Updating dotnet: Installing dotnet 7 SDK"
fi
# Download dotnet install script
wget https://dot.net/v1/dotnet-install.sh -O dotnet-install.sh
chmod +x ./dotnet-install.sh
# Install dotnet 6 if not already installed
if [[ $DOTNET_6_INSTALLED = false ]]; then
./dotnet-install.sh --version 6.0.314
fi
# Install dotnet 7 if not already installed
if [[ $DOTNET_7_INSTALLED = false ]]; then
./dotnet-install.sh --version 7.0.305
fi
# Remove dotnet install script
rm dotnet-install.sh
# Set environment variables and add them to .bashrc to persist
export DOTNET_ROOT="$HOME/.dotnet"
export PATH="$PATH:$DOTNET_ROOT:$DOTNET_ROOT/tools"
echo 'export DOTNET_ROOT="$HOME/.dotnet"' >> ~/.bashrc
echo 'export PATH="$PATH:$DOTNET_ROOT:$DOTNET_ROOT/tools"' >> ~/.bashrc
echo_green "Dotnet installed"
ENVIRONMENT_REFRESH_REQUIRED=true
else
echo_green "Found dotnet runtime with SDKs 6 and 7"
fi
# Remove all build artifacts
rm -rf "build"
rm -rf "RestAPI/bin"
rm -rf "RestAPI/obj"
rm -rf "RestAPI/build"
# Build the backend
echo_cyan "Building backend"
dotnet publish RestAPI/RestAPI.csproj /p:PublishProfile=RestAPI/Properties/PublishProfiles/Linux-x64.pubxml -c Release
echo_green "Backend build complete"