-
Notifications
You must be signed in to change notification settings - Fork 2
/
setup.sh
executable file
·151 lines (130 loc) · 4.72 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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
#!/bin/bash
set -e
# ------------
# FUNCTIONS
# Install packages based on the selected package manager: apt, pacman, brew
install_packages() {
local AUTO=$1
local PACKAGE_MANAGER=$2
local PACKAGE_LIST=("${!3}")
case $PACKAGE_MANAGER in
apt)
sudo apt update
if [ $AUTO = true ]; then
sudo apt install -y "${PACKAGE_LIST[@]}"
else
sudo apt install "${PACKAGE_LIST[@]}"
fi
;;
pacman)
sudo pacman -Syyu
if [ $AUTO = true ]; then
sudo pacman -Sy "${PACKAGE_LIST[@]}"
else
sudo pacman -S "${PACKAGE_LIST[@]}"
fi
;;
brew)
brew update
if [ $AUTO = true ]; then
brew install "${PACKAGE_LIST[@]}" || true
else
brew install "${PACKAGE_LIST[@]}"
fi
;;
esac
}
# Prompt user to install dependencies, (and choose a package manager, if multiple are available)
prompt_install_dependencies() {
local AUTO=$1
if [ $AUTO = false ]; then
echo
echo -n "Install dependencies? (Y/n): "
read -r INSTALL_DEPS
else
INSTALL_DEPS="Y"
fi
if [[ "$INSTALL_DEPS" != "N" && "$INSTALL_DEPS" != "n" ]]; then
# Check for available package managers
AVAILABLE_PACKAGE_MANAGERS=()
if [ "$(uname)" == "Darwin" ]; then
if command -v brew &>/dev/null; then
AVAILABLE_PACKAGE_MANAGERS+=("brew")
fi
elif [ "$(expr substr $(uname -s) 1 5)" == "Linux" ]; then
if command -v apt &>/dev/null; then
AVAILABLE_PACKAGE_MANAGERS+=("apt")
fi
if command -v pacman &>/dev/null; then
AVAILABLE_PACKAGE_MANAGERS+=("pacman")
fi
# if command -v yum &>/dev/null; then
# AVAILABLE_PACKAGE_MANAGERS+=("yum")
# fi
fi
# Prompt user to choose a package manager
if [ ${#AVAILABLE_PACKAGE_MANAGERS[@]} -eq 0 ]; then
echo "No supported package managers found."
exit 1
elif [ ${#AVAILABLE_PACKAGE_MANAGERS[@]} -eq 1 ] || [ $AUTO = true ]; then
SELECTED_PACKAGE_MANAGER=${AVAILABLE_PACKAGE_MANAGERS[0]}
else
echo -n "Multiple package managers found. Please choose one:"
select SELECTED_PACKAGE_MANAGER in "${AVAILABLE_PACKAGE_MANAGERS[@]}"; do
if [ -n "$SELECTED_PACKAGE_MANAGER" ]; then
break
else
echo "Invalid selection. Please choose a number."
fi
done
fi
# Install packages based on the selected package manager
case $SELECTED_PACKAGE_MANAGER in
apt)
PACKAGE_LIST=("git" "cmake" "ninja-build" "pkg-config" "build-essential" "libgl1-mesa-dev" "mesa-common-dev" "libgstreamer1.0-dev" "libgstreamer-gl1.0-0" "libgstreamer-plugins-base1.0-dev" "gstreamer1.0-tools" "gstreamer1.0-libav" "libunwind-dev")
install_packages $AUTO "$SELECTED_PACKAGE_MANAGER" PACKAGE_LIST[@]
;;
pacman)
PACKAGE_LIST=("git" "cmake" "ninja" "pkgconf" "base-devel" "mesa" "gst-plugins-base-libs" "gst-libav")
install_packages $AUTO "$SELECTED_PACKAGE_MANAGER" PACKAGE_LIST[@]
;;
# yum)
# PACKAGE_LIST=()
# install_packages $AUTO "$SELECTED_PACKAGE_MANAGER" PACKAGE_LIST[@]
# ;;
brew)
PACKAGE_LIST=("git" "cmake" "ninja" "pkg-config" "gstreamer")
install_packages $AUTO "$SELECTED_PACKAGE_MANAGER" PACKAGE_LIST[@]
;;
esac
else
echo
echo "Skipping dependency installation."
fi
}
# Check if Xcode command-line tools are installed and properly set up
check_xcode() {
# Check if Xcode command-line tools are installed
if ! xcode-select -p &>/dev/null; then
echo "Xcode command-line tools are not installed."
echo "Please install them by running: xcode-select --install"
exit 1
fi
# Check if Xcode license agreement is accepted
if ! xcodebuild -version &>/dev/null; then
echo "Xcode license agreement is not accepted."
echo "Please accept the license agreement by running: sudo xcodebuild -license accept"
exit 1
fi
}
# ------------
# Main
AUTO=false
# Skip prompt if --auto is passed
if [ "$1" = "--auto" ] ; then
AUTO=true
fi
prompt_install_dependencies $AUTO
if [ "$(uname)" == "Darwin" ]; then
check_xcode
fi