-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmigrate-to-data.sh
More file actions
executable file
·148 lines (123 loc) · 4.51 KB
/
Copy pathmigrate-to-data.sh
File metadata and controls
executable file
·148 lines (123 loc) · 4.51 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
#!/bin/bash
#
# One-time migration: move content directories from src/ to data/
#
# Run as maint on production:
# cd /home/maint/music/src
# ./migrate-to-data.sh
#
# This script:
# 1. Moves content directories from src/ to data/
# 2. Moves website/events and website/tokens to data/
# 3. Removes migrated files from the src git index and commits
# 4. Initializes a new git repo in data/, pushes to GitHub
# 5. Fixes permissions
#
# After running, you must manually update Apache config — the script
# prints the exact edits and commands at the end.
set -e
DATA_REPO="git@github.com:sdeibel/tunejam-data.git"
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
BASE_DIR="$(dirname "$SCRIPT_DIR")"
DATA_DIR="$BASE_DIR/data"
SRC_DIR="$SCRIPT_DIR"
echo "Migration: src/ content → data/"
echo " SRC_DIR: $SRC_DIR"
echo " DATA_DIR: $DATA_DIR"
echo " REPO: $DATA_REPO"
echo ""
# ── Safety checks ─────────────────────────────────────────────
if [ -d "$DATA_DIR/db" ]; then
echo "ERROR: $DATA_DIR/db already exists. Migration may have already run."
exit 1
fi
if [ ! -d "$SRC_DIR/db" ]; then
echo "ERROR: $SRC_DIR/db does not exist. Nothing to migrate."
exit 1
fi
# ── Create data directory ─────────────────────────────────────
echo "Creating $DATA_DIR ..."
mkdir -p "$DATA_DIR"
# ── Move content directories ─────────────────────────────────
echo "Moving content directories..."
# Top-level content dirs in src/
for dir in db tunes recordings config log; do
if [ -d "$SRC_DIR/$dir" ]; then
echo " mv $dir → data/$dir"
mv "$SRC_DIR/$dir" "$DATA_DIR/$dir"
else
echo " SKIP $dir (not found)"
fi
done
# Directories under website/
for dir in events tokens; do
if [ -d "$SRC_DIR/website/$dir" ]; then
echo " mv website/$dir → data/$dir"
mv "$SRC_DIR/website/$dir" "$DATA_DIR/$dir"
else
echo " SKIP website/$dir (not found)"
fi
done
echo ""
# ── Remove migrated files from src git index and commit ───────
echo "Removing migrated files from src git index..."
cd "$SRC_DIR"
for dir in db tunes recordings config log; do
git rm -r --cached "$dir" 2>/dev/null || true
done
for dir in website/events website/tokens; do
git rm -r --cached "$dir" 2>/dev/null || true
done
git add -A
git commit -m "Remove migrated content directories (moved to data/ repo)"
echo ""
# ── Initialize data git repo and push ─────────────────────────
echo "Initializing git repo in $DATA_DIR ..."
cd "$DATA_DIR"
git init
cat > .gitignore << 'GITIGNORE'
.DS_Store
*.pyc
__pycache__/
GITIGNORE
git add -A
git commit -m "Initial commit: migrated content from src/"
echo ""
echo "Pushing data repo to $DATA_REPO ..."
git remote add origin "$DATA_REPO"
git push -u origin main
echo ""
# ── Fix permissions ───────────────────────────────────────────
echo "Fixing permissions..."
cd "$SRC_DIR"
"$BASE_DIR/bin/python2.7" website/fixperms.py
echo ""
# ── Done ──────────────────────────────────────────────────────
echo "=========================================="
echo "Migration complete!"
echo ""
echo "Remaining manual steps:"
echo ""
echo " 1. Push the src repo cleanup:"
echo " cd $SRC_DIR && git push"
echo ""
echo " 2. Set up auto-commit cron:"
echo " chmod +x $SRC_DIR/data-commit.sh"
echo " Add to /etc/cron.hourly/musicsite.sh:"
echo " /home/maint/music/src/data-commit.sh"
echo ""
echo " 3. Update Apache config:"
echo " Copy the pre-edited conf files from tmp/ on your dev machine:"
echo " scp tmp/httpd.conf server:/etc/httpd/conf/httpd.conf"
echo " scp tmp/httpd-le-ssl.conf server:/etc/httpd/conf/httpd-le-ssl.conf"
echo " Then validate and reload:"
echo " httpd -t && sudo systemctl reload httpd"
echo ""
echo " 4. Test the site — browse tunes, play a recording, create an event"
echo ""
echo "To ROLLBACK:"
echo " cd $DATA_DIR"
echo " for d in db tunes recordings config log; do mv \$d $SRC_DIR/; done"
echo " for d in events tokens; do mv \$d $SRC_DIR/website/; done"
echo " cd $SRC_DIR && git reset HEAD~1"
echo " # Then revert Apache config changes and reload httpd"