-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.sh
More file actions
executable file
·214 lines (176 loc) · 5.34 KB
/
setup.sh
File metadata and controls
executable file
·214 lines (176 loc) · 5.34 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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
#!/bin/sh
# [ -d "$HOME/.local/share" ] || {
# echo "~/.local/share gibt's nicht!"
# exit 1
# }
# Check if test is requested.
for arg in "$@"; do
case "$arg" in
--test) TESTING=true ;;
--no-cache) CACHELESS=true ;;
esac
done
PINK="\033[38;5;205m"
GREEN="\033[32m"
YELLOW="\033[33m"
LILA="\033[35m"
GREY="\033[2;37m"
RED="\033[31m"
NOCO="\033[0m"
# Run a command completly silent.
silent() {
"$@" >/dev/null 2>&1
}
# Colored echo.
cecho() {
color=$1
shift
echo -e "${color}$@${NOCO}"
}
# Colored inline echo.
cnecho() {
color=$1
shift
echo -en "${color}$@${NOCO}"
}
# Colored, indented echo.
ciecho() {
color=$1
shift
echo -e "$GREY╟$NOCO ${color}$@${NOCO}"
}
section_end() {
echo -en "$GREY╙$NOCO ✅"
echo -e "\n"
}
echo -e "\n$PINK///// ////// // //// ///// //////"
sleep 0.05
echo -e "// // // // // // // // // // //"
sleep 0.05
echo -e "///// ///// // // // // //// ///// "
sleep 0.05
echo -e "// // // // // // // // // // // "
sleep 0.05
echo -e "//// // // //// //// ///// // //"
sleep 0.05
echo -e "Dein Bruder der Musik (I use Arch btw)$NOCO\n"
sleep 0.05
read -p "Hast du Bock? Schreib [ja] oder [nein] ⌨️ " you_in </dev/tty
if [ "$you_in" != "ja" ]; then
cecho "$YELLOW" "✋ Alles klar Bruder, vielleicht ein andermal!"
exit 1
fi
cecho "$GREEN" "😍 Nice, dann las los gehen jetzt…\n"
HOME_DIR=${XDG_DATA_HOME:-$HOME}
WORK_DIR="$HOME_DIR/.local/share"
BIN_DIR="$HOME_DIR/.local/bin"
LOG_DIR="$HOME_DIR/.logs/musikbruder"
LOG_FILE=$LOG_DIR/setup.log
# Ensure the .local/share dir exists by creating it. This won't
# output anything if it already exists.
mkdir -p "$WORK_DIR"
mkdir -p "$BIN_DIR"
# + Logging setup
mkdir -p "$LOG_DIR"
if [ -f "$LOG_FILE" ]; then
rm -f $LOG_DIR/setup.log
fi
touch $LOG_FILE
cd $WORK_DIR
[ -n "$TESTING" ] && cecho "$RED" "Test-Modus aktiviert"
[ -n "$CACHELESS" ] && cecho "$RED" "Cache wird umgangen"
echo -e ""
# + Download App
cecho "$LILA" "App runterladen…"
# If the base directory already exists, ask for reinstalling everything.
if [ -d "musikbruder" ]; then
ciecho "$RED" "»~/.local/share/musikbruder« existiert schon!"
read -p "$(echo -e "${GREY}╟${NOCO} ${YELLOW}Alles löschen & neu installieren?$NOCO [ja]/[nein] ⌨️ ")" delete </dev/tty
if [ "$delete" != "ja" ]; then
ciecho "$GREEN" "Alles klar Bruder, vielleicht ein andermal!"
exit 1
else
ciecho "$GREY" "Oha, wird gelöscht…"
cd musikbruder
docker compose -f compose.deploy.yml down --volumes >>"$LOG_FILE" 2>&1
cd ..
sudo -p "$(echo -e "$GREY╟$NOCO ${YELLOW}Passwort für %u$NOCO 🔒 ")" rm -rf musikbruder
fi
fi
# + Clone GitHub
REPO="https://github.com/brudermusscode/MusikBruder.git"
BRANCH="deploy"
[ -n "$TESTING" ] && BRANCH="test"
ciecho "$GREY" "Kloniere $REPO (Branch: $BRANCH)…"
git clone --branch "$BRANCH" --single-branch "$REPO" musikbruder >>"$LOG_FILE" 2>&1
cd musikbruder
section_end
# + Dependency directories and files.
# {
cecho "$LILA" "Alle Relevanzen erstellen…"
ciecho "$GREY" "Mach ich Bruder, warte kurz…"
ciecho "$GREY" "Ordner erstellen…"
mkdir -p public/data/user/1/{tracks,art,portraits,videos}
mkdir -p public/data/user/1/tracks/deleted
mkdir -p storage/logs
touch storage/logs/setup.log
touch sql/last_migration
ciecho "$GREY" "Rechte einstellen…"
chmod a+rw -R storage public sql
chmod a+rw sql/last_migration
ciecho "$GREY" "Environment erstellen…"
cp .env.example .env
# } >>"$LOG_FILE" 2>&1
# + Link Music Directory
MUSIC_DIR="$HOME_DIR/Music"
REPLACEMENT=""
if [ -d $MUSIC_DIR ]; then
read -p "$(echo -e "${GREY}╟${NOCO} ${YELLOW}Willst du deinen lokalen Musik-Ordner synchronisieren?$NOCO [ja]/[nein] ⌨️ ")" link_music </dev/tty
if [ "$link_music" == "ja" ]; then
MUSIC_DIR_LINKED="yes"
REPLACEMENT="- $MUSIC_DIR:/data/public/data/user/1/tracks/local"
fi
fi
# If local music shall be linked, create a /local folder inside
# the sync base dir in the app.
if [ -n "$MUSIC_DIR_LINKED" ]; then
ciecho "$GREY" "Verlinke lokale Musik-Bib…"
mkdir -p public/data/user/1/tracks/local
fi
ciecho "$GREY" "Compose Dummy-Datei aufbereiten…"
{
# Replace variable placeholders with the actual replacement and
# create a real compose file for upping docker.
cp compose-dummy compose.deploy.yml
sed -i "s|%MUSIC_DIR_AS_VOLUME%|${REPLACEMENT}|g" compose.deploy.yml
} >>"$LOG_FILE" 2>&1
section_end
# + Build docker-container.
cecho "$LILA" "Bruder bauen…"
ciecho "$GREY" "Lehn dich zurück, das kann 1 bisschen dauern 😇…"
docker compose -f compose.deploy.yml build ${CACHELESS:+--no-cache} >>"$LOG_FILE" 2>&1
section_end
# + Start the app.
cecho "$LILA" "Endspürt…"
ciecho "$GREY" "App hochfahren…"
docker compose -f compose.deploy.yml up -d >>"$LOG_FILE" 2>&1
# Wait for the app to return status 200.
URL="http://localhost:6789"
printf "\r$GREY╟$NOCO ${GREY}Auf Status 200 warten "
while [ "$(curl -s -o /dev/null -w "%{http_code}" "$URL")" != "200" ]; do
printf "▓"
sleep 1
done
echo -e ""
# if command -v xdg-open >>$LOG_FILE 2>&1; then
# xdg-open "$URL"
# else
# ciecho "$GREY" "xdg-open fehlt leider, sont hätte sich das Fenster nun automatisch geöffnet 🥸"
# fi
section_end
# # DONE
if [ -n $MUSIC_DIR_LINKED ]; then
cecho "$GREEN" "🤝 Fertig! Geh zu $URL - Musik wird automatisch aus deinem lokalen Musik-Ordner synchronisiert! ❤️"
else
cecho "$GREEN" "🤝 Fertig! Geh zu $URL ❤️"
fi