mirror of
https://github.com/kuhyx/testsAndMisc.git
synced 2026-11-10 20:27:02 +01:00
Two levels of pure taxonomy carrying no information, and a 2-directory
cap leaves no room for them. Categories now sit directly under
linux_configuration/: features, fixes, utils, misc, fresh-install,
installers, diagnostics, gaming, boot_recovery, periodic_background, lib,
meta, tests. A script's own lib/ and tests/ are exempt from the cap, so
those stay put.
Depth violations 248 -> 139; roughly 40 of the remainder are inside
digital_wellbeing and hosts, deferred until the guard-lib repoint.
The moves are the easy half. What breaks is every path that counted
levels, and three classes of it had to be found by resolving paths rather
than reading diffs:
- 52 relative `source` lines for lib/common.sh and lib/android.sh. The
correct prefix differs per file: 40 were ../../ and 12 were ../../../,
so a blanket replace would have fixed one set and broken the other.
- REPO_ROOT in 7 fixes/lib/tests harnesses and setup_syncyomi_guard.sh,
each walking up four levels from a directory now two levels shallower.
This caused a real regression -- the fixes suite went red with
"log_warn: command not found" -- caught by running it and comparing
against the pre-move baseline worktree.
- conftest.py's sys.path entries, which took the pytest gate down with
14 collection errors, and the `# shellcheck source=` directives, which
took shellcheck down with SC1091.
16 symlinks in $HOME broke, including the entire i3blocks bar. All
repointed, and cpu_monitor/memory/disk/time/volume were run to confirm
they emit real output rather than merely resolving.
Verified: 1798 tests pass at 100% coverage, 8 of 9 lib/tests suites pass
(the ninth needs the coverage jail, identically at baseline), pre-commit
is clean, and the two untracked secret configs are still ignored after
their gitignore paths changed.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01PJrqKERAo5QUeEHWS5Asgp
242 lines
5.9 KiB
Bash
Executable File
242 lines
5.9 KiB
Bash
Executable File
#!/bin/bash
|
|
# Autostart unit and the installed/running checks.
|
|
#
|
|
# Sourced by setup_activitywatch.sh; split out to keep aw_service.sh under the
|
|
# 250-line cap. Sourced rather than run, so it inherits the caller's
|
|
# strict mode and the variables defined above the source line.
|
|
|
|
# Function to setup autostart
|
|
setup_autostart() {
|
|
echo ""
|
|
echo "5. Setting Up Autostart..."
|
|
echo "========================="
|
|
|
|
local autostart_dir="$USER_HOME/.config/autostart"
|
|
local desktop_file="$autostart_dir/activitywatch.desktop"
|
|
local i3_config="$USER_HOME/.config/i3/config"
|
|
|
|
# Method 1: XDG Autostart (works with most desktop environments)
|
|
if [[ $EUID -eq 0 ]]; then
|
|
sudo -u "$ACTUAL_USER" mkdir -p "$autostart_dir"
|
|
else
|
|
mkdir -p "$autostart_dir"
|
|
fi
|
|
|
|
# Create desktop file for autostart
|
|
cat >"$desktop_file" <<EOF
|
|
[Desktop Entry]
|
|
Type=Application
|
|
Name=ActivityWatch
|
|
Comment=Automated time tracker
|
|
Exec=aw-qt
|
|
Icon=activitywatch
|
|
Hidden=false
|
|
NoDisplay=false
|
|
X-GNOME-Autostart-enabled=true
|
|
StartupNotify=false
|
|
Terminal=false
|
|
Categories=Utility;
|
|
EOF
|
|
|
|
# Set proper ownership if running as root
|
|
if [[ $EUID -eq 0 ]]; then
|
|
chown "$ACTUAL_USER:$ACTUAL_USER" "$desktop_file"
|
|
fi
|
|
|
|
echo "✓ Created XDG autostart entry: $desktop_file"
|
|
|
|
# Method 2: i3 config autostart (specific to i3)
|
|
if [[ -f $i3_config ]]; then
|
|
# Check if autostart entry already exists
|
|
if ! grep -q "aw-qt" "$i3_config"; then
|
|
# Add autostart entry to i3 config
|
|
if [[ $EUID -eq 0 ]]; then
|
|
# Running as root
|
|
sudo -u "$ACTUAL_USER" bash -c "cat <<'EOF' >> '$i3_config'
|
|
|
|
# Auto-start ActivityWatch
|
|
exec --no-startup-id aw-qt
|
|
EOF"
|
|
else
|
|
{
|
|
printf '\n'
|
|
printf '# Auto-start ActivityWatch\n'
|
|
printf 'exec --no-startup-id aw-qt\n'
|
|
} >>"$i3_config"
|
|
fi
|
|
|
|
echo "✓ Added ActivityWatch to i3 config autostart"
|
|
else
|
|
echo "✓ ActivityWatch autostart already exists in i3 config"
|
|
fi
|
|
else
|
|
echo "! i3 config not found at $i3_config"
|
|
fi
|
|
}
|
|
|
|
# Function to create i3blocks status script
|
|
create_i3blocks_status() {
|
|
echo ""
|
|
echo "6. Creating i3blocks Status Script..."
|
|
echo "===================================="
|
|
|
|
local i3blocks_dir="$USER_HOME/.config/i3blocks"
|
|
local status_script="$i3blocks_dir/activitywatch_status.sh"
|
|
|
|
# Create i3blocks directory if it doesn't exist
|
|
if [[ $EUID -eq 0 ]]; then
|
|
sudo -u "$ACTUAL_USER" mkdir -p "$i3blocks_dir"
|
|
else
|
|
mkdir -p "$i3blocks_dir"
|
|
fi
|
|
|
|
# Create the status script
|
|
cat >"$status_script" <<'EOF'
|
|
#!/bin/bash
|
|
# ActivityWatch status script for i3blocks
|
|
# Shows ActivityWatch installation and running status
|
|
|
|
# Check if ActivityWatch is installed
|
|
check_installed() {
|
|
# Check if activitywatch-bin package is installed
|
|
if pacman -Qi activitywatch-bin &>/dev/null; then
|
|
return 0
|
|
fi
|
|
|
|
# Check if aw-qt binary exists
|
|
if command -v aw-qt &>/dev/null; then
|
|
return 0
|
|
fi
|
|
|
|
return 1
|
|
}
|
|
|
|
# Check if ActivityWatch is running
|
|
check_running() {
|
|
# Check for aw-qt process
|
|
if pgrep -f "aw-qt" >/dev/null 2>&1; then
|
|
return 0
|
|
fi
|
|
|
|
# Check for aw-server process
|
|
if pgrep -f "aw-server" >/dev/null 2>&1; then
|
|
return 0
|
|
fi
|
|
|
|
return 1
|
|
}
|
|
|
|
# Main logic
|
|
if ! check_installed; then
|
|
echo "AW uninstalled"
|
|
echo
|
|
echo "#FF0000" # Red
|
|
elif check_running; then
|
|
echo "AW on"
|
|
echo
|
|
echo "#00FF00" # Green
|
|
else
|
|
echo "AW off"
|
|
echo
|
|
echo "#FF0000" # Red
|
|
fi
|
|
EOF
|
|
|
|
chmod +x "$status_script"
|
|
|
|
# Set proper ownership if running as root
|
|
if [[ $EUID -eq 0 ]]; then
|
|
chown "$ACTUAL_USER:$ACTUAL_USER" "$status_script"
|
|
fi
|
|
|
|
echo "✓ Created i3blocks status script: $status_script"
|
|
|
|
# Show configuration instructions
|
|
echo ""
|
|
echo "To add to your i3blocks config, add this block:"
|
|
echo ""
|
|
echo "[activitywatch]"
|
|
echo "command=~/.config/i3blocks/activitywatch_status.sh"
|
|
echo "interval=10"
|
|
echo "color=#FFFFFF"
|
|
echo ""
|
|
}
|
|
|
|
# Function to test the setup
|
|
test_setup() {
|
|
echo ""
|
|
echo "7. Testing Setup..."
|
|
echo "=================="
|
|
|
|
echo "Installation status:"
|
|
if check_activitywatch_installed >/dev/null 2>&1; then
|
|
echo "✓ ActivityWatch is installed"
|
|
else
|
|
echo "✗ ActivityWatch is not installed"
|
|
fi
|
|
|
|
echo "Running status:"
|
|
if check_activitywatch_running >/dev/null 2>&1; then
|
|
echo "✓ ActivityWatch is running"
|
|
else
|
|
echo "✗ ActivityWatch is not running"
|
|
fi
|
|
|
|
echo "Autostart files:"
|
|
if [[ -f "$USER_HOME/.config/autostart/activitywatch.desktop" ]]; then
|
|
echo "✓ XDG autostart file exists"
|
|
else
|
|
echo "✗ XDG autostart file missing"
|
|
fi
|
|
|
|
if [[ -f "$USER_HOME/.config/i3/config" ]] && grep -q "aw-qt" "$USER_HOME/.config/i3/config"; then
|
|
echo "✓ i3 autostart configured"
|
|
else
|
|
echo "! i3 autostart may not be configured"
|
|
fi
|
|
|
|
echo "i3blocks status script:"
|
|
if [[ -x "$USER_HOME/.config/i3blocks/activitywatch_status.sh" ]]; then
|
|
echo "✓ i3blocks status script created"
|
|
echo "Testing status script:"
|
|
if [[ $EUID -eq 0 ]]; then
|
|
sudo -u "$ACTUAL_USER" "$USER_HOME/.config/i3blocks/activitywatch_status.sh"
|
|
else
|
|
"$USER_HOME/.config/i3blocks/activitywatch_status.sh"
|
|
fi
|
|
else
|
|
echo "✗ i3blocks status script missing"
|
|
fi
|
|
}
|
|
|
|
# Function to show final instructions
|
|
show_instructions() {
|
|
echo ""
|
|
echo "=========================================="
|
|
echo "ActivityWatch Setup Complete"
|
|
echo "=========================================="
|
|
echo "Summary:"
|
|
echo "✓ ActivityWatch installation checked/completed"
|
|
echo "✓ ActivityWatch startup configured"
|
|
echo "✓ Autostart configured (XDG + i3)"
|
|
echo "✓ i3blocks status script created"
|
|
echo ""
|
|
echo "Next steps:"
|
|
echo "1. Add the i3blocks configuration to your config file:"
|
|
echo " ~/.config/i3blocks/config"
|
|
echo ""
|
|
echo "2. Reload i3 configuration:"
|
|
echo " Super+Shift+R"
|
|
echo ""
|
|
echo "3. ActivityWatch web interface should be available at:"
|
|
echo " http://localhost:5600"
|
|
echo ""
|
|
echo "4. Check system tray for ActivityWatch icon"
|
|
echo ""
|
|
echo "Files created:"
|
|
echo " ~/.config/autostart/activitywatch.desktop"
|
|
echo " ~/.config/i3blocks/activitywatch_status.sh"
|
|
echo " ~/.config/i3/config (modified)"
|
|
echo ""
|
|
}
|