-
Notifications
You must be signed in to change notification settings - Fork 1k
Expand file tree
/
Copy pathsetup
More file actions
executable file
·159 lines (137 loc) · 3.56 KB
/
setup
File metadata and controls
executable file
·159 lines (137 loc) · 3.56 KB
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
152
153
154
155
156
157
158
159
#!/usr/bin/env bash
set -eo pipefail
# Prefer app executables
app_root="$(
cd "$(dirname "$0")/.."
pwd
)"
export PATH="$app_root/bin:$PATH"
if [ -e tmp/saas.txt ]; then
export SAAS=1
fi
if [ -n "$SAAS" ]; then
export BUNDLE_GEMFILE="Gemfile.saas"
fi
# Install gum if needed
if ! command -v gum &>/dev/null; then
echo
echo "▸ Installing gum"
if command -v pacman &>/dev/null; then
sudo pacman -S --noconfirm gum
elif command -v brew &>/dev/null; then
brew install gum
else
echo "Please install gum: https://github.com/charmbracelet/gum"
exit 1
fi
echo
fi
# Install mise if needed
if ! command -v mise &>/dev/null; then
echo
echo "▸ Installing mise"
if command -v pacman &>/dev/null; then
sudo pacman -S --noconfirm mise
elif command -v brew &>/dev/null; then
brew install mise
else
echo "Please install mise: https://mise.jdx.dev/installing-mise.html#installation-methods"
exit 1
fi
echo
fi
# Install gh if needed
if ! command -v gh &>/dev/null; then
echo
echo "▸ Installing GitHub CLI"
if command -v pacman &>/dev/null; then
sudo pacman -S --noconfirm gh
elif command -v brew &>/dev/null; then
brew install gh
else
echo "Please install GitHub CLI: https://github.com/cli/cli#installation"
exit 1
fi
echo
fi
step() {
local step_name="$1"
shift
gum style --foreground 135 --bold "▸ $step_name"
gum style --foreground 240 "$*"
"$@"
local exit_code=$?
echo
return $exit_code
}
needs_seeding() {
if [ "$CI" != "" ]; then
return 1
fi
has_data=$(bin/rails runner "pp Account.all.any?" 2>/dev/null)
if [ "$has_data" = "true" ] ; then
return 1
else
return 0
fi
}
oss_mysql_setup() {
if ! nc -z localhost 3306 2>/dev/null; then
if docker ps -aq -f name=fizzy-mysql | grep -q .; then
step "Starting MySQL" docker start fizzy-mysql
else
step "Setting up MySQL" bash -c '
docker pull mysql:8.4
docker run -d \
--name fizzy-mysql \
-e MYSQL_ALLOW_EMPTY_PASSWORD=yes \
-p 3306:3306 \
mysql:8.4
echo "MySQL is starting… (it may take a few seconds)"
'
fi
fi
}
echo
gum style --foreground 153 " ˚ ∘ ∘ ˚ "
gum style --foreground 111 --bold " ∘˚˳°∘° 𝒻𝒾𝓏𝓏𝓎 °∘°˳˚∘ "
echo
step "Installing Ruby" mise install --yes
eval "$(mise hook-env -s bash)"
if which pacman >/dev/null 2>&1; then
packages=(imagemagick mariadb-libs openslide libvips gitleaks)
if ! pacman -Q "${packages[@]}" >/dev/null 2>&1; then
step "Installing packages" sudo pacman -S --noconfirm --needed "${packages[@]}"
fi
elif which brew >/dev/null 2>&1; then
packages=(imagemagick openslide vips gitleaks)
missing_packages=()
for pkg in "${packages[@]}"; do
if ! brew list "$pkg" &>/dev/null; then
missing_packages+=("$pkg")
fi
done
if [ ${#missing_packages[@]} -gt 0 ]; then
step "Installing packages" brew install "${missing_packages[@]}"
fi
fi
bundle config set --local auto_install true
step "Installing RubyGems" bundle install
if [ -n "$SAAS" ]; then
saas_setup=$(bundle show fizzy-saas)/bin/setup
source "$saas_setup"
else
if [ "$DATABASE_ADAPTER" = "mysql" ]; then
oss_mysql_setup
fi
fi
if [[ $* == *--reset* ]]; then
step "Resetting the database" rails db:reset
else
step "Preparing the database" rails db:prepare
if needs_seeding; then
step "Seeding the database" rails db:seed
fi
fi
step "Cleaning up logs and tempfiles" rails log:clear tmp:clear
gum style --foreground 46 "✓ Done (${SECONDS} sec)"