-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup
executable file
·171 lines (145 loc) · 4.7 KB
/
setup
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
#!/bin/bash
INSTALL_PATH="/usr/local"
FORCE_INSTALL=false
# List of required Python modules
REQUIRED_PYTHON_MODULES=(
"gi"
"PyYAML"
"psutil"
"argparse" # argparse is part of standard library (Python >= 2.7) but including for safety
)
show_help() {
echo "Usage: ./setup.sh [OPTION]..."
echo "Install or uninstall WineCharm."
echo ""
echo "Options:"
echo " -i, --install Install WineCharm"
echo " -u, --uninstall Uninstall WineCharm"
echo " -p, --prefix PATH Specify installation prefix (default: /usr/local)"
echo " -f, --force Force installation even if dependencies are not met"
echo " -h, --help Display this help and exit"
}
check_dependencies() {
local missing_programs=()
if ! command -v "flatpak-spawn" &> /dev/null; then
local required_programs=(
'exiftool'
'wine'
'winetricks'
'wrestool'
'icotool'
'pgrep'
'gnome-terminal'
'xdg-open'
)
for prog in "${required_programs[@]}"; do
if ! command -v "$prog" &> /dev/null; then
missing_programs+=("$prog")
fi
done
fi
if [ ${#missing_programs[@]} -ne 0 ]; then
echo "The following required programs are missing:"
for prog in "${missing_programs[@]}"; do
echo " - $prog"
done
echo ""
echo "Please install them before proceeding or use the -f or --force option to install WineCharm anyway."
echo ""
echo "on Debian:"
echo "sudo dpkg --add-architecture i386 && sudo apt update -y
sudo apt install zenity wine wine32 wine64 winetricks libimage-exiftool-perl icoutils gnome-terminal wget zstd winbind python3-yaml python3-psutil"
#return 1
fi
return 0
}
check_python_dependencies() {
local missing_modules=()
# Adjust the module name for PyYAML to 'yaml', as that's the correct import name.
for module in "${REQUIRED_PYTHON_MODULES[@]}"; do
if [ "$module" == "PyYAML" ]; then
python3 -c "import yaml" &> /dev/null
else
python3 -c "import $module" &> /dev/null
fi
if [ $? -ne 0 ]; then
missing_modules+=("$module")
fi
done
if [ ${#missing_modules[@]} -ne 0 ]; then
echo "The following required Python modules are missing:"
for module in "${missing_modules[@]}"; do
echo " - $module"
done
echo ""
echo "You can install them using pip:"
echo " pip3 install ${missing_modules[*]}"
return 1
fi
return 0
}
install_files() {
echo "Installing WineCharm to $INSTALL_PATH..."
install -Dm755 winecharm.py "$INSTALL_PATH/bin/winecharm"
install -Dm644 io.github.fastrizwaan.WineCharm.svg "$INSTALL_PATH/share/icons/hicolor/scalable/apps/io.github.fastrizwaan.WineCharm.svg"
install -Dm755 io.github.fastrizwaan.WineCharm.desktop "$INSTALL_PATH/share/applications/io.github.fastrizwaan.WineCharm.desktop"
install -Dm644 org.winehq.Wine.png "$INSTALL_PATH/share/icons/hicolor/128x128/apps/org.winehq.Wine.png"
echo "WineCharm installed successfully."
}
uninstall_files() {
echo "Uninstalling WineCharm from $INSTALL_PATH..."
rm -f "$INSTALL_PATH/bin/winecharm"
rm -f "$INSTALL_PATH/share/icons/hicolor/scalable/apps/io.github.fastrizwaan.WineCharm.svg"
rm -f "$INSTALL_PATH/share/applications/io.github.fastrizwaan.WineCharm.desktop"
rm -f "$INSTALL_PATH/share/icons/hicolor/128x128/apps/org.winehq.Wine.png"
echo "WineCharm uninstalled successfully."
}
# Parse command-line arguments
while [[ $# -gt 0 ]]; do
key="$1"
case $key in
-i|--install)
ACTION="install"
shift
;;
-u|--uninstall)
ACTION="uninstall"
shift
;;
-p|--prefix)
INSTALL_PATH="$2"
shift
shift
;;
-f|--force)
FORCE_INSTALL=true
shift
;;
-h|--help)
show_help
exit 0
;;
*)
echo "Unknown option: $key"
show_help
exit 1
;;
esac
done
if [ -z "$ACTION" ]; then
show_help
exit 0
fi
if [ "$ACTION" == "install" ]; then
if ! check_dependencies && [ "$FORCE_INSTALL" = false ]; then
echo "Dependencies are not satisfied. Use -f or --force to force the installation."
exit 1
fi
if ! check_python_dependencies && [ "$FORCE_INSTALL" = false ]; then
echo "Python dependencies are not satisfied. Use -f or --force to force the installation."
exit 1
fi
install_files
elif [ "$ACTION" == "uninstall" ]; then
uninstall_files
fi