summarylogtreecommitdiffstats
path: root/willow.install
blob: 849df958eb2b0415f34126bfc27df500bece7c48 (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
post_install() {
    # Color codes
    local RED='\033[0;31m'
    local GREEN='\033[0;32m'
    local YELLOW='\033[1;33m'
    local BLUE='\033[0;34m'
    local BOLD='\033[1m'
    local NC='\033[0m' # No Color
    
    echo ""
    echo -e "${BOLD}===================================================================${NC}"
    echo -e "${BOLD}Willow Installation Complete${NC}"
    echo -e "${BOLD}===================================================================${NC}"
    echo ""
    
    # Auto-setup configuration
    if [ ! -f "$HOME/.config/willow/config.json" ]; then
        printf "Setting up configuration...\n"
        mkdir -p "$HOME/.config/willow"
        cp /usr/share/willow/config.json "$HOME/.config/willow/"
        echo -e "${GREEN}${NC} Configuration created at ~/.config/willow/config.json"
    fi
    
    # Auto-setup context configuration for smart workflows
    if [ ! -f "$HOME/.config/willow/context.json" ]; then
        cp /usr/share/willow/context.json "$HOME/.config/willow/"
        echo -e "${GREEN}${NC} Context configuration created at ~/.config/willow/context.json"
    fi
    
    # Check for whisper model
    if [ ! -f "$HOME/.local/share/willow/models/ggml-tiny.en.bin" ]; then
        echo ""
        printf "Whisper model not found. Download now? [Y/n] "
        read -r response
        response=${response:-Y}
        if [[ "$response" =~ ^[Yy]$ ]]; then
            printf "\nDownloading ggml-tiny.en model (~75MB)...\n"
            mkdir -p "$HOME/.local/share/willow/models"
            if curl -fL --progress-bar -o "$HOME/.local/share/willow/models/ggml-tiny.en.bin" \
                "https://huggingface.co/ggerganov/whisper.cpp/resolve/main/ggml-tiny.en.bin"; then
                echo -e "${GREEN}${NC} Model downloaded successfully"
            else
                echo -e "${RED}${NC} Download failed. Run later: willow-download-model"
            fi
        else
            printf "\nSkipped. Download later with: willow-download-model\n"
        fi
    else
        echo -e "${GREEN}${NC} Whisper model already installed"
    fi
    
    echo ""
    echo -e "${BOLD}-------------------------------------------------------------------${NC}"
    echo -e "${YELLOW}IMPORTANT: Manual Steps Required${NC}"
    echo -e "${BOLD}-------------------------------------------------------------------${NC}"
    echo ""
    echo -e "${BLUE}1. Enable GNOME extension:${NC}"
    echo "   gnome-extensions enable willow@saim"
    echo ""
    echo -e "${BLUE}2. Start the service (from a GNOME graphical session):${NC}"
    echo "   systemctl --user start willow.service"
    echo ""
    echo -e "${BLUE}3. Enable ydotool for keyboard simulation (Wayland):${NC}"
    echo "   sudo systemctl enable --now ydotool"
    echo "   sudo usermod -aG input \$USER"
    echo "   (Then log out and back in)"
    echo ""
    echo -e "${YELLOW}Note:${NC} The service requires a running GNOME session with D-Bus."
    echo "      If installing via SSH, complete steps 1-2 after logging into GNOME."
    echo ""
    echo -e "${BOLD}Configure preferences:${NC}"
    echo "  gnome-extensions prefs willow@saim"
    echo ""
    echo -e "${BOLD}Smart Workflows Available:${NC}"
    echo "  • Say 'open [app]' to launch any installed app"
    echo "  • Say 'search [engine] for [query]' to search the web"
    echo "  • Customize in ~/.config/willow/context.json"
    echo ""
    echo "Documentation: /usr/share/doc/willow/"
    echo -e "${BOLD}===================================================================${NC}"
    echo ""
}

post_upgrade() {
    # Color codes
    local GREEN='\033[0;32m'
    local YELLOW='\033[1;33m'
    local BOLD='\033[1m'
    local NC='\033[0m'
    
    echo ""
    echo -e "${BOLD}===================================================================${NC}"
    echo -e "${BOLD}Willow Upgraded${NC}"
    echo -e "${BOLD}===================================================================${NC}"
    echo ""
    echo -e "${YELLOW}Restart the service to apply changes:${NC}"
    echo "  systemctl --user restart willow.service"
    echo ""
    echo -e "${YELLOW}Note:${NC} Run from a GNOME graphical session, not SSH/terminal"
    echo -e "${BOLD}===================================================================${NC}"
    echo ""
}

pre_remove() {
    if systemctl --user is-active --quiet willow.service 2>/dev/null; then
        printf "Stopping Willow service...\n"
        systemctl --user stop willow.service 2>/dev/null || true
    fi
    systemctl --user disable willow.service 2>/dev/null || true
}

post_remove() {
    # Color codes
    local GREEN='\033[0;32m'
    local BOLD='\033[1m'
    local NC='\033[0m'
    
    echo ""
    echo -e "${BOLD}===================================================================${NC}"
    echo -e "${BOLD}Willow Removed${NC}"
    echo -e "${BOLD}===================================================================${NC}"
    echo ""
    
    # Disable extension if it exists
    if command -v gnome-extensions &> /dev/null; then
        gnome-extensions disable willow@saim 2>/dev/null || true
    fi
    
    printf "Remove configuration files? [y/N] "
    read -r response
    if [[ "$response" =~ ^[Yy]$ ]]; then
        rm -rf "$HOME/.config/willow" 2>/dev/null && echo -e "${GREEN}${NC} Configuration removed" || true
    else
        echo "Configuration kept at: ~/.config/willow"
    fi
    
    printf "Remove whisper models (~75MB)? [y/N] "
    read -r response
    if [[ "$response" =~ ^[Yy]$ ]]; then
        rm -rf "$HOME/.local/share/willow" 2>/dev/null && echo -e "${GREEN}${NC} Models removed" || true
    else
        echo "Models kept at: ~/.local/share/willow"
    fi
    
    echo ""
    echo "Willow has been successfully removed."
    echo -e "${BOLD}===================================================================${NC}"
    echo ""
}