-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdev.sh
More file actions
230 lines (195 loc) · 8.06 KB
/
dev.sh
File metadata and controls
230 lines (195 loc) · 8.06 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
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
#!/bin/bash
# Development Environment Bootstrapping Script
# Goal: Idempotently install development-specific applications on top of a
# baseline Omarchy system configured by the main setup.sh script.
# Prerequisites: The main setup.sh script must have been run successfully.
# --- 1. Environment & Setup Phase ---
# Define fixed repository path relative to the user's home directory (~/Code/linux)
REPO_PATH="$HOME/Code/linux"
# Define target directories using $HOME for portability
DEVSQL_DIR="$HOME/Containers/devsql"
SYSTEMD_USER_DIR="$HOME/.config/systemd/user"
# Function to safely create all required directories
create_dirs() {
echo "Ensuring target directories exist..."
mkdir -p "$DEVSQL_DIR"
mkdir -p "$SYSTEMD_USER_DIR"
mkdir -p "$HOME/.config/hypr"
}
# Function to copy files from the repo to the target location, overwriting if changed
create_copy() {
local SOURCE=$1
local TARGET=$2
# If target exists and is identical, skip
if [ -e "$TARGET" ]; then
if command -v cmp >/dev/null 2>&1 && cmp -s "$SOURCE" "$TARGET"; then
echo "Unchanged: $(basename "$SOURCE") already at $TARGET"
return 0
fi
# Overwrite existing target (no backup as requested)
cp -a "$SOURCE" "$TARGET"
echo "Overwrote: $(basename "$SOURCE") -> $TARGET"
return 0
fi
cp -a "$SOURCE" "$TARGET"
echo "Copied: $(basename "$SOURCE") -> $TARGET"
}
# Run the directory creation
create_dirs
# Check if a key package from setup.sh is installed.
# We use beekeeper-studio-bin as an indicator that setup.sh has been run.
if ! yay -Q "beekeeper-studio-bin" >/dev/null 2>&1; then
echo "--------------------------------------------------------"
echo "ERROR: Prerequisite 'beekeeper-studio-bin' not found."
echo "Please run the main setup.sh script first before running this script."
echo "--------------------------------------------------------"
exit 1
fi
# Initial Confirmation and Safety Check
echo "--------------------------------------------------------"
echo "Setting Up Development Environment"
echo "Repo Path: $REPO_PATH"
echo "--------------------------------------------------------"
read -r -p "Do you want to proceed with development package installation? (y/N): " response
if [[ "$response" != "y" && "$response" != "Y" ]]; then
echo "Setup cancelled by user."
exit 0
fi
# --- 2. System Package Management Phase ---
# Install Packages from dev/pkglist.txt
echo -e "\n--- Installing/Updating Development Packages ---"
echo "Installing applications..."
while IFS= read -r PACKAGE; do
case "$PACKAGE" in
""|"#"*) continue ;;
esac
# Check if package is already installed
WAS_INSTALLED=false
if yay -Q "$PACKAGE" >/dev/null 2>&1; then
WAS_INSTALLED=true
fi
# For already installed packages, check quietly first if they're up to date
if [ "$WAS_INSTALLED" = true ]; then
QUIET_CHECK=$(yay -S --needed --noconfirm "$PACKAGE" 2>&1)
if echo "$QUIET_CHECK" | grep -qi "up to date.*skipping\|nothing to do\|there is nothing to do"; then
VERSION=$(yay -Q "$PACKAGE" 2>/dev/null | cut -d' ' -f2)
echo "Skipped: $PACKAGE (already updated) - $VERSION"
continue
fi
fi
# Run yay with real-time output for packages that need installation/update
TEMP_OUTPUT=$(mktemp)
echo "Installing $PACKAGE..."
yay -S --needed --noconfirm "$PACKAGE" 2>&1 | tee "$TEMP_OUTPUT"
YAY_EXIT_CODE=${PIPESTATUS[0]}
rm -f "$TEMP_OUTPUT"
if [ "$YAY_EXIT_CODE" -eq 0 ]; then
VERSION=$(yay -Q "$PACKAGE" 2>/dev/null | cut -d' ' -f2)
echo "Installed: $PACKAGE - $VERSION"
else
echo "Failed to install: $PACKAGE"
echo "---"
fi
done < "$REPO_PATH/dev/pkglist.txt"
# 2.1 Install Composer Global Packages
echo -e "\n--- Installing Composer Global Packages ---"
while IFS= read -r PACKAGE; do
case "$PACKAGE" in
""|"#"*) continue ;;
esac
# Check if package is already installed
if composer global show "$PACKAGE" >/dev/null 2>&1; then
VERSION=$(composer global show "$PACKAGE" 2>/dev/null | grep 'versions' | awk '{print $3}')
echo "Skipped: $PACKAGE (already installed) - $VERSION"
else
echo "Installing $PACKAGE..."
if composer global require "$PACKAGE" --no-interaction; then
VERSION=$(composer global show "$PACKAGE" 2>/dev/null | grep 'versions' | awk '{print $3}')
echo "Installed: $PACKAGE - $VERSION"
else
echo "Failed to install: $PACKAGE"
fi
fi
done < "$REPO_PATH/dev/composer.txt"
# Ensure composer bin is in PATH
if [[ ":$PATH:" != *":$HOME/.config/composer/vendor/bin:"* ]]; then
echo -e "\nNote: Add Composer bin directory to your PATH by adding this to your shell config:"
# shellcheck disable=SC2016
echo 'export PATH="$HOME/.config/composer/vendor/bin:$PATH"'
fi
# --- 3. Development SQL Container Setup ---
echo -e "\n--- Setting Up Development SQL Container ---"
# Define source and target paths
COMPOSE_SOURCE="$REPO_PATH/dev/devsql/podman-compose.yml"
COMPOSE_DEST="$DEVSQL_DIR/podman-compose.yml"
SERVICE_FILE="$SYSTEMD_USER_DIR/container-devsql.service"
OLD_SERVICE_FILE="$SYSTEMD_USER_DIR/container-global_mysql_server.service"
# 3.1 Clean up old service if it exists
if [ -f "$OLD_SERVICE_FILE" ]; then
echo "Removing old MySQL service..."
systemctl --user disable container-global_mysql_server.service 2>/dev/null || true
systemctl --user stop container-global_mysql_server.service 2>/dev/null || true
rm -f "$OLD_SERVICE_FILE"
echo "Removed: container-global_mysql_server.service"
fi
# 3.2 Deploy podman-compose.yml
COMPOSE_CHANGED=false
if [ ! -f "$COMPOSE_DEST" ] || ! cmp -s "$COMPOSE_SOURCE" "$COMPOSE_DEST"; then
create_copy "$COMPOSE_SOURCE" "$COMPOSE_DEST"
COMPOSE_CHANGED=true
fi
# 3.3 Start the container with podman-compose
# Check if container is already running
if podman ps --format "{{.Names}}" | grep -q "^devsql$"; then
echo "Container devsql is already running"
# If compose file changed, restart the container
if [ "$COMPOSE_CHANGED" = true ]; then
echo "Compose file changed, restarting container..."
(cd "$DEVSQL_DIR" && podman-compose down && podman-compose up -d)
sleep 2
fi
else
echo "Starting devsql container..."
if (cd "$DEVSQL_DIR" && podman-compose up -d); then
echo "Container started successfully"
sleep 2
else
echo "ERROR: Failed to start devsql container"
exit 1
fi
# Verify container is running
if ! podman ps --format "{{.Names}}" | grep -q "^devsql$"; then
echo "ERROR: Container 'devsql' is not running"
echo "Check logs with: podman logs devsql"
exit 1
fi
fi
# 3.4 Generate systemd service file
if [ ! -f "$SERVICE_FILE" ] || [ "$COMPOSE_CHANGED" = true ]; then
echo "Generating systemd service file..."
if (cd "$DEVSQL_DIR" && podman generate systemd --name devsql --files --new); then
if [ -f "$DEVSQL_DIR/container-devsql.service" ]; then
mv "$DEVSQL_DIR/container-devsql.service" "$SERVICE_FILE"
echo "Generated: container-devsql.service"
else
echo "WARNING: Service file was not created in expected location"
fi
else
echo "WARNING: Failed to generate systemd service file"
fi
else
echo "Skipped: systemd service file (already exists)"
fi
# 3.5 Enable the systemd service
systemctl --user daemon-reload
systemctl --user enable container-devsql.service 2>/dev/null
echo "Enabled: container-devsql.service"
# --- 4. Configuration Deployment Phase (Dotfiles) ---
echo -e "\n--- Updating Configuration Files ---"
# 4.1 Deploy Custom Hyprland Autostart Config
create_copy "$REPO_PATH/dev/config/hypr/autostart.conf" "$HOME/.config/hypr/autostart.conf"
# --- 5. Completion ---
echo -e "\n--------------------------------------------------------"
echo "✨ DEVELOPMENT SETUP COMPLETE! ✨"
echo "All development tools and packages are installed."
echo "--------------------------------------------------------"