summarylogtreecommitdiffstats
path: root/cloudtolocalllm.install
blob: ee50eedcc913fc2a6a1292f166358c5b890a6cc0 (plain)
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
231
232
233
234
235
236
237
238
239
240
241
#!/bin/bash

# CloudToLocalLLM AUR Package Installation Script
# Handles post-installation, post-upgrade, and post-removal tasks

# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color

# Logging functions
log_info() {
    echo -e "${BLUE}[INFO]${NC} $1"
}

log_success() {
    echo -e "${GREEN}[SUCCESS]${NC} $1"
}

log_warning() {
    echo -e "${YELLOW}[WARNING]${NC} $1"
}

log_error() {
    echo -e "${RED}[ERROR]${NC} $1"
}

# Update system caches and databases
update_system_caches() {
    log_info "Updating system caches and databases..."
    
    # Update icon cache
    if command -v gtk-update-icon-cache >/dev/null 2>&1; then
        if gtk-update-icon-cache -q -t -f /usr/share/icons/hicolor 2>/dev/null; then
            log_success "Icon cache updated successfully"
        else
            log_warning "Failed to update icon cache (non-critical)"
        fi
    else
        log_warning "gtk-update-icon-cache not found, skipping icon cache update"
    fi
    
    # Update desktop database
    if command -v update-desktop-database >/dev/null 2>&1; then
        if update-desktop-database -q /usr/share/applications 2>/dev/null; then
            log_success "Desktop database updated successfully"
        else
            log_warning "Failed to update desktop database (non-critical)"
        fi
    else
        log_warning "update-desktop-database not found, skipping desktop database update"
    fi
    
    # Update MIME database
    if command -v update-mime-database >/dev/null 2>&1; then
        if update-mime-database /usr/share/mime 2>/dev/null; then
            log_success "MIME database updated successfully"
        else
            log_warning "Failed to update MIME database (non-critical)"
        fi
    else
        log_warning "update-mime-database not found, skipping MIME database update"
    fi
}

# Check system tray support
check_system_tray_support() {
    log_info "Checking system tray support..."
    
    # Check for common desktop environments
    if [[ -n "$KDE_SESSION_VERSION" ]] || [[ "$XDG_CURRENT_DESKTOP" == *"KDE"* ]]; then
        log_info "KDE Plasma detected - system tray should work with libayatana-appindicator"
        if ! pacman -Qi libayatana-appindicator >/dev/null 2>&1; then
            log_warning "libayatana-appindicator not found - system tray may not work properly"
        fi
    elif [[ "$XDG_CURRENT_DESKTOP" == *"GNOME"* ]]; then
        log_info "GNOME detected - system tray requires AppIndicator extension"
        log_info "Install: https://extensions.gnome.org/extension/615/appindicator-support/"
    elif [[ "$XDG_CURRENT_DESKTOP" == *"XFCE"* ]]; then
        log_info "XFCE detected - system tray should work natively"
    elif [[ "$XDG_CURRENT_DESKTOP" == *"i3"* ]] || [[ "$XDG_CURRENT_DESKTOP" == *"sway"* ]]; then
        log_info "Tiling window manager detected - system tray support varies"
        log_info "Consider using a status bar with system tray support (e.g., waybar, polybar)"
    else
        log_info "Desktop environment: ${XDG_CURRENT_DESKTOP:-unknown}"
        log_info "System tray support depends on your desktop environment"
    fi
}

# Display installation information
display_installation_info() {
    echo
    echo "=== CloudToLocalLLM Installation Complete ==="
    echo
    log_success "CloudToLocalLLM has been installed successfully!"
    echo
    echo "Getting Started:"
    echo "  • Launch from applications menu: 'CloudToLocalLLM'"
    echo "  • Or run from terminal: 'cloudtolocalllm'"
    echo "  • The application will start minimized to system tray by default"
    echo "  • If system tray issues occur: 'DISABLE_SYSTEM_TRAY=true cloudtolocalllm'"
    echo
    echo "Key Features:"
    echo "  • Multi-tenant streaming LLM management"
    echo "  • System tray integration with monochrome icons"
    echo "  • Platform-specific UI logic (desktop vs web)"
    echo "  • Secure authentication and user isolation"
    echo "  • Direct Ollama connectivity for desktop use"
    echo
    echo "Configuration:"
    echo "  • Settings: Access via system tray menu or main interface"
    echo "  • LLM Provider: Configure in Settings → LLM Provider Settings"
    echo "  • System Tray: Right-click tray icon for context menu"
    echo
    echo "For Ollama Integration:"
    echo "  • Install Ollama: 'yay -S ollama' or from https://ollama.ai"
    echo "  • Start Ollama service: 'sudo systemctl enable --now ollama'"
    echo "  • Test connection in CloudToLocalLLM settings"
    echo
    echo "Troubleshooting:"
    echo "  • System tray crashes: Run 'DISABLE_SYSTEM_TRAY=true cloudtolocalllm' to disable"
    echo "  • Debug system tray: Run 'DEBUG_SYSTEM_TRAY=true cloudtolocalllm' for detailed logs"
    echo "  • System tray not visible: Check desktop environment compatibility above"
    echo "  • Connection issues: Verify Ollama is running on localhost:11434"
    echo "  • Authentication problems: Check internet connection for web features"
    echo
    echo "Documentation: https://github.com/imrightguy/CloudToLocalLLM"
    echo "Issues: https://github.com/imrightguy/CloudToLocalLLM/issues"
    echo
}

# Display upgrade information
display_upgrade_info() {
    echo
    echo "=== CloudToLocalLLM Upgrade Complete ==="
    echo
    log_success "CloudToLocalLLM has been upgraded successfully!"
    echo
    echo "What's New in This Version:"
    echo "  • Enhanced UI restructuring with dedicated LLM provider settings"
    echo "  • Platform-specific connection logic (web proxy vs direct desktop)"
    echo "  • Professional 'Coming Soon' placeholders for cloud features"
    echo "  • Improved system tray integration with monochrome icons"
    echo "  • Comprehensive Linux packaging pipeline"
    echo "  • Zero deprecation warnings with tray_manager fixes"
    echo
    echo "Important Changes:"
    echo "  • Ollama testing moved to Settings → LLM Provider Settings"
    echo "  • Basic sync functionality included, advanced cloud sync available as premium feature"
    echo "  • Enhanced cross-platform compatibility"
    echo
    echo "If you experience any issues after the upgrade:"
    echo "  • Restart the application"
    echo "  • Check Settings → LLM Provider Settings for new configuration options"
    echo "  • Report issues: https://github.com/imrightguy/CloudToLocalLLM/issues"
    echo
}

# Post-installation hook
post_install() {
    update_system_caches
    check_system_tray_support
    display_installation_info
}

# Post-upgrade hook
post_upgrade() {
    update_system_caches
    check_system_tray_support
    display_upgrade_info
}

# Pre-removal hook
pre_remove() {
    log_info "Preparing to remove CloudToLocalLLM..."
    
    # Kill any running instances
    if pgrep -f cloudtolocalllm >/dev/null 2>&1; then
        log_info "Stopping running CloudToLocalLLM instances..."
        pkill -f cloudtolocalllm 2>/dev/null || true
        sleep 2
        
        # Force kill if still running
        if pgrep -f cloudtolocalllm >/dev/null 2>&1; then
            log_warning "Force stopping CloudToLocalLLM instances..."
            pkill -9 -f cloudtolocalllm 2>/dev/null || true
        fi
    fi
    
    log_info "CloudToLocalLLM processes stopped"
}

# Post-removal hook
post_remove() {
    log_info "Cleaning up after CloudToLocalLLM removal..."
    
    # Update system caches
    update_system_caches
    
    # Note about user data
    echo
    echo "=== CloudToLocalLLM Removal Complete ==="
    echo
    log_info "CloudToLocalLLM has been removed from your system"
    echo
    echo "User Data:"
    echo "  • Configuration files may remain in ~/.config/cloudtolocalllm/"
    echo "  • User data may remain in ~/.local/share/cloudtolocalllm/"
    echo "  • Remove manually if desired: rm -rf ~/.config/cloudtolocalllm ~/.local/share/cloudtolocalllm"
    echo
    echo "Thank you for using CloudToLocalLLM!"
    echo
}

# Handle different installation phases
case "$1" in
    configure)
        # This is called during package installation
        post_install
        ;;
    upgrade)
        # This is called during package upgrade
        post_upgrade
        ;;
    remove)
        # This is called before package removal
        pre_remove
        ;;
    purge)
        # This is called after package removal
        post_remove
        ;;
    *)
        # Default case - treat as installation
        post_install
        ;;
esac

exit 0