Repository navigation
Expand file tree
/
Copy pathsetup
More file actions
executable file
·153 lines (128 loc) · 4.82 KB
/
Copy pathsetup
File metadata and controls
executable file
·153 lines (128 loc) · 4.82 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
#!/bin/bash
# Setup script for the Window Positioning System
set -e
EXTENSION_DIR="$HOME/.local/share/gnome-shell/extensions/window-positioner@example.com"
BIN_DIR="$HOME/bin"
echo "Setting up Window Positioning System..."
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
CYAN='\033[0;36m'
YELLOW='\033[1;33m'
NC='\033[0m'
# Check if jq is installed
if ! command -v jq &> /dev/null; then
echo -e "${YELLOW}Installing jq...${NC}"
sudo apt update && sudo apt install -y jq
fi
# Create extension directory
echo -e "${CYAN}Creating extension directory...${NC}"
mkdir -p "$EXTENSION_DIR"
# Copy extension files (assuming they're in current directory)
echo -e "${CYAN}Installing extension files...${NC}"
# Track if extension files actually changed
EXTENSION_CHANGED=false
if [ -f "extension.js" ]; then
if [ ! -f "$EXTENSION_DIR/extension.js" ] || ! cmp -s "extension.js" "$EXTENSION_DIR/extension.js"; then
cp extension.js "$EXTENSION_DIR/"
EXTENSION_CHANGED=true
echo -e "${YELLOW}Updated extension.js${NC}"
else
echo -e "${GREEN}extension.js unchanged${NC}"
fi
else
echo -e "${RED}Error: extension.js not found in current directory${NC}"
echo "Please make sure you have the extension files in the current directory"
exit 1
fi
if [ -f "metadata.json" ]; then
if [ ! -f "$EXTENSION_DIR/metadata.json" ] || ! cmp -s "metadata.json" "$EXTENSION_DIR/metadata.json"; then
cp metadata.json "$EXTENSION_DIR/"
EXTENSION_CHANGED=true
echo -e "${YELLOW}Updated metadata.json${NC}"
else
echo -e "${GREEN}metadata.json unchanged${NC}"
fi
echo -e "${GREEN}Extension files processed${NC}"
else
echo -e "${RED}Error: metadata.json not found in current directory${NC}"
exit 1
fi
# Create bin directory if it doesn't exist
mkdir -p "$BIN_DIR"
# Copy main position script
echo -e "${CYAN}Installing position script...${NC}"
if [ -f "position" ]; then
cp position "$BIN_DIR/"
chmod +x "$BIN_DIR/position"
echo -e "${GREEN}Position script installed to $BIN_DIR/position${NC}"
else
echo -e "${RED}Error: position script not found${NC}"
exit 1
fi
# Check if ~/bin is in PATH
if [[ ":$PATH:" != *":$HOME/bin:"* ]]; then
echo -e "${YELLOW}Adding $HOME/bin to PATH...${NC}"
echo 'export PATH="$HOME/bin:$PATH"' >> "$HOME/.bashrc"
echo -e "${CYAN}Please run 'source ~/.bashrc' or restart your terminal${NC}"
fi
# Only create autostart setup if extension files changed
if [ "$EXTENSION_CHANGED" = true ]; then
# Create autostart directory if it doesn't exist
mkdir -p "$HOME/.config/autostart"
# Create self-destroying post-login script
echo -e "${CYAN}Creating auto-run post-login setup...${NC}"
cat > "$HOME/.config/autostart/window-positioner-setup.desktop" << 'EOF'
[Desktop Entry]
Type=Application
Name=Window Positioner Setup
Exec=/bin/bash -c 'sleep 3 && /tmp/window-positioner-post-login.sh'
Hidden=false
NoDisplay=false
X-GNOME-Autostart-enabled=true
EOF
# Create the actual script that will run once
cat > /tmp/window-positioner-post-login.sh << 'EOF'
#!/bin/bash
# Post-login setup for Window Positioning System - runs once and self-destructs
set -e
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
CYAN='\033[0;36m'
YELLOW='\033[1;33m'
NC='\033[0m'
# Enable extension
gnome-extensions disable window-positioner@example.com 2>/dev/null || true
gnome-extensions enable window-positioner@example.com
# Check if extension is enabled
sleep 2
if gnome-extensions list --enabled | grep -q window-positioner; then
status=$(gnome-extensions info window-positioner@example.com | grep "State:" | awk "{print \$2}")
if [ "$status" = "ACTIVE" ]; then
notify-send "Window Positioner" "Setup complete! Extension is ACTIVE." --icon=dialog-information
else
notify-send "Window Positioner" "Extension enabled but state is: $status" --icon=dialog-warning
fi
else
notify-send "Window Positioner" "Extension failed to enable. Check manually." --icon=dialog-error
fi
# Self-destruct: remove autostart file and this script
rm -f "$HOME/.config/autostart/window-positioner-setup.desktop"
rm -f "$0"
EOF
chmod +x /tmp/window-positioner-post-login.sh
fi
echo ""
echo -e "${GREEN}Setup complete!${NC}"
echo ""
# Only show restart message if extension files actually changed
if [ "$EXTENSION_CHANGED" = true ]; then
echo -e "${YELLOW}IMPORTANT: GNOME Shell restart required${NC}"
echo -e "${YELLOW}Log out and back in for extension changes to take effect${NC}"
echo -e "${YELLOW}Quick logout: gnome-session-quit --logout --no-prompt${NC}"
echo -e "${YELLOW}Verify notification indicates extension is ACTIVE after logging back in.${NC}"
else
echo -e "${GREEN}No extension changes detected - no restart required.${NC}"
echo -e "${CYAN}Your position script has been updated and is ready to use.${NC}"
fi