-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtimelog.install
More file actions
executable file
·185 lines (155 loc) · 6 KB
/
timelog.install
File metadata and controls
executable file
·185 lines (155 loc) · 6 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
#!/usr/bin/env bash
set -euo pipefail
# ============================================================================
# timelog - Installer Script
# Version: 2.2.0
# Generated by make-awesome.py
# ============================================================================
VERSION="2.2.0"
APPNAME="timelog"
BASE_URL="https://raw.githubusercontent.com/linuxcaffe/tw-timelog-hook/main"
# Colors
RED='\033[0;31m'
GREEN='\033[0;32m'
BLUE='\033[0;34m'
NC='\033[0m'
tw_msg() { echo -e "${BLUE}[tw]${NC} $*"; }
tw_success() { echo -e "${GREEN}[tw] [OK]${NC} $*"; }
tw_error() { echo -e "${RED}[tw] [FAIL]${NC} $*" >&2; }
# Debug support
DEBUG_LEVEL="${TW_DEBUG:-0}"
debug_msg() {
local msg="$1"
local level="${2:-1}"
if [[ $DEBUG_LEVEL -ge $level ]]; then
echo -e "${BLUE}[DEBUG-$level]${NC} $msg" >&2
fi
}
debug_msg "Starting installer with DEBUG_LEVEL=$DEBUG_LEVEL" 1
# Directories
HOME="${HOME:-$(eval echo ~$USER)}"
TASKRC="${HOME}/.taskrc"
TASK_DIR="${HOME}/.task"
HOOKS_DIR="${TASK_DIR}/hooks"
SCRIPTS_DIR="${TASK_DIR}/scripts"
CONFIG_DIR="${TASK_DIR}/config"
DOCS_DIR="${TASK_DIR}/docs"
# ============================================================================
# Installation Function
# ============================================================================
install() {
tw_msg "Installing timelog v$VERSION..."
debug_msg "Starting installation" 1
# Create directories
tw_msg "Creating directories..."
mkdir -p "$HOOKS_DIR" "$SCRIPTS_DIR" "$CONFIG_DIR" "$DOCS_DIR"
debug_msg "Directories created" 2
tw_msg "Downloading files..."
debug_msg "Using BASE_URL: $BASE_URL" 2
# Migrate: remove the old hook replaced by on-modify_timelog.py
if [[ -f "$HOOKS_DIR/on-modify-timeclock.py" ]]; then
rm -f "$HOOKS_DIR/on-modify-timeclock.py"
tw_msg "Removed old hook: on-modify-timeclock.py"
fi
debug_msg "Downloading hook: on-exit_stop-started.sh" 2
curl -fsSL "$BASE_URL/on-exit_stop-started.sh" -o "$HOOKS_DIR/on-exit_stop-started.sh" || {
tw_error "Failed to download on-exit_stop-started.sh"
debug_msg "Download failed: on-exit_stop-started.sh" 1
return 1
}
chmod +x "$HOOKS_DIR/on-exit_stop-started.sh"
debug_msg "Installed hook: $HOOKS_DIR/on-exit_stop-started.sh" 2
debug_msg "Downloading hook: on-modify_timelog.py" 2
curl -fsSL "$BASE_URL/on-modify_timelog.py" -o "$HOOKS_DIR/on-modify_timelog.py" || {
tw_error "Failed to download on-modify_timelog.py"
debug_msg "Download failed: on-modify_timelog.py" 1
return 1
}
chmod +x "$HOOKS_DIR/on-modify_timelog.py"
debug_msg "Installed hook: $HOOKS_DIR/on-modify_timelog.py" 2
debug_msg "Downloading config: timelog.rc" 2
curl -fsSL "$BASE_URL/timelog.rc" -o "$CONFIG_DIR/timelog.rc" || {
tw_error "Failed to download timelog.rc"
debug_msg "Download failed: timelog.rc" 1
return 1
}
debug_msg "Installed config: $CONFIG_DIR/timelog.rc" 2
# Add config to .taskrc
tw_msg "Checking .taskrc for existing config include..."
if ! grep -q "timelog.rc" "$TASKRC" 2>/dev/null; then
echo "include ~/.task/config/timelog.rc" >> "$TASKRC"
tw_msg "Added config include to .taskrc"
debug_msg "Added to .taskrc: include ~/.task/config/timelog.rc" 2
else
tw_msg "Config already in .taskrc"
debug_msg "Config already present in .taskrc: timelog.rc" 2
fi
tw_msg "Downloading documentation..."
curl -fsSL "$BASE_URL/README.md" -o "$DOCS_DIR/timelog_README.md" 2>/dev/null || true
debug_msg "Downloaded doc: $DOCS_DIR/timelog_README.md" 2
# Track in manifest
debug_msg "Writing to manifest" 2
MANIFEST_FILE="${HOME}/.task/config/.tw_manifest"
TIMESTAMP=$(date -u +"%Y-%m-%dT%H:%M:%SZ")
mkdir -p "$(dirname "$MANIFEST_FILE")"
echo "$APPNAME|$VERSION|$HOOKS_DIR/on-exit_stop-started.sh||$TIMESTAMP" >> "$MANIFEST_FILE"
debug_msg "Manifest entry: $HOOKS_DIR/on-exit_stop-started.sh" 3
echo "$APPNAME|$VERSION|$HOOKS_DIR/on-modify_timelog.py||$TIMESTAMP" >> "$MANIFEST_FILE"
debug_msg "Manifest entry: $HOOKS_DIR/on-modify_timelog.py" 3
echo "$APPNAME|$VERSION|$CONFIG_DIR/timelog.rc||$TIMESTAMP" >> "$MANIFEST_FILE"
debug_msg "Manifest entry: $CONFIG_DIR/timelog.rc" 3
echo "$APPNAME|$VERSION|$DOCS_DIR/timelog_README.md||$TIMESTAMP" >> "$MANIFEST_FILE"
debug_msg "Manifest entry: $DOCS_DIR/timelog_README.md" 3
debug_msg "Installation complete" 1
tw_success "Installed timelog v$VERSION"
echo ""
tw_msg "Documentation: $DOCS_DIR/timelog_README.md"
echo ""
return 0
}
# ============================================================================
# Removal Function
# ============================================================================
remove() {
tw_msg "Removing timelog..."
debug_msg "Starting removal" 1
MANIFEST_FILE="${HOME}/.task/config/.tw_manifest"
if [ ! -f "$MANIFEST_FILE" ]; then
tw_error "Manifest file not found"
return 1
fi
# Remove files based on manifest
grep "^$APPNAME|" "$MANIFEST_FILE" | cut -d"|" -f3 | while read -r file; do
if [ -f "$file" ]; then
rm "$file"
debug_msg "Removed: $file" 2
tw_msg "Removed: $(basename $file)"
fi
done
# Remove from manifest
sed -i.bak "/^$APPNAME|/d" "$MANIFEST_FILE"
debug_msg "Removed from manifest" 2
# Remove config from .taskrc
if grep -q "timelog.rc" "$TASKRC" 2>/dev/null; then
sed -i.bak "/timelog.rc/d" "$TASKRC"
tw_msg "Removed config from .taskrc"
debug_msg "Removed from .taskrc: timelog.rc" 2
fi
tw_success "Removed timelog"
return 0
}
# ============================================================================
# Main
# ============================================================================
case "${1:-install}" in
install)
install
;;
remove|uninstall)
remove
;;
*)
echo "Usage: $0 {install|remove}"
exit 1
;;
esac