-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·155 lines (141 loc) · 6.06 KB
/
Copy pathinstall.sh
File metadata and controls
executable file
·155 lines (141 loc) · 6.06 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
#!/usr/bin/env bash
# ---------------------------------------------------------------------------
# AllConv installer — works on ANY Linux distribution
#
# Installs AllConv so you can run it from anywhere by typing:
# allconv (command-line tool)
# allconv --gui (graphical interface)
#
# It also adds "AllConv" to your application menu.
#
# This script only relies on things every Linux distro has:
# - python3 + pip
# - the freedesktop ~/.local/bin and ~/.local/share directories
# The only distro-specific part (installing Tkinter for the GUI) is
# auto-detected for apt, dnf, yum, pacman, zypper, apk, xbps, eopkg,
# emerge and nix.
#
# Usage: ./install.sh (normal install)
# ./install.sh --with-tk (also try to install Tkinter via sudo)
# ---------------------------------------------------------------------------
set -euo pipefail
SRC_DIR="$(cd "$(dirname "$0")" && pwd)"
SHARE_DIR="${XDG_DATA_HOME:-$HOME/.local/share}/allconv"
BIN_DIR="$HOME/.local/bin"
DESKTOP_DIR="${XDG_DATA_HOME:-$HOME/.local/share}/applications"
WITH_TK=0
[ "${1:-}" = "--with-tk" ] && WITH_TK=1
blue() { printf '\033[1;34m%s\033[0m\n' "$*"; }
green() { printf '\033[1;32m%s\033[0m\n' "$*"; }
warn() { printf '\033[1;33m%s\033[0m\n' "$*"; }
blue "Installing AllConv (works on any Linux distro)..."
# --- 0. sanity checks ------------------------------------------------------
if ! command -v python3 >/dev/null 2>&1; then
warn "python3 was not found. Please install Python 3.9+ using your distro's"
warn "package manager, then run this installer again."
exit 1
fi
# Make sure pip exists; bootstrap it if missing (works on any distro).
if ! python3 -m pip --version >/dev/null 2>&1; then
warn "pip not found — trying to bootstrap it with ensurepip..."
python3 -m ensurepip --user >/dev/null 2>&1 || true
fi
# --- helper: detect the distro's package manager + Tkinter package ---------
detect_tk_cmd() {
# Prints a ready-to-run install command for Tkinter on THIS distro.
if command -v apt-get >/dev/null 2>&1; then echo "sudo apt-get install -y python3-tk"
elif command -v apt >/dev/null 2>&1; then echo "sudo apt install -y python3-tk"
elif command -v dnf >/dev/null 2>&1; then echo "sudo dnf install -y python3-tkinter"
elif command -v yum >/dev/null 2>&1; then echo "sudo yum install -y python3-tkinter"
elif command -v pacman >/dev/null 2>&1; then echo "sudo pacman -S --noconfirm tk"
elif command -v zypper >/dev/null 2>&1; then echo "sudo zypper install -y python3-tk"
elif command -v apk >/dev/null 2>&1; then echo "sudo apk add python3-tkinter"
elif command -v xbps-install >/dev/null 2>&1; then echo "sudo xbps-install -y python3-tkinter"
elif command -v eopkg >/dev/null 2>&1; then echo "sudo eopkg install -y python3-tkinter"
elif command -v emerge >/dev/null 2>&1; then echo "sudo emerge dev-lang/python --newuse"
elif command -v nix-env >/dev/null 2>&1; then echo "nix-env -iA nixpkgs.python3"
else echo ""; fi
}
# --- 1. install python dependencies (portable via pip) ---------------------
blue "Installing Python dependencies (needs internet the first time)..."
if python3 -m pip install --user -r "$SRC_DIR/requirements.txt"; then
green "Dependencies installed."
else
warn "Could not install dependencies automatically (offline?)."
warn "Run this once you have internet:"
warn " python3 -m pip install --user -r requirements.txt"
fi
# --- 2. Tkinter for the GUI (the only distro-specific piece) ----------------
if python3 -c 'import tkinter' >/dev/null 2>&1; then
green "Tkinter present — GUI will work."
else
TK_CMD="$(detect_tk_cmd)"
if [ "$WITH_TK" = "1" ] && [ -n "$TK_CMD" ]; then
warn "Installing Tkinter with: $TK_CMD"
eval "$TK_CMD" || warn "Tkinter install failed; install it manually later."
else
warn "Tkinter is not installed (needed ONLY for the GUI; the CLI works without it)."
if [ -n "$TK_CMD" ]; then
warn "For your distro, install it with:"
warn " $TK_CMD"
warn "(or re-run: ./install.sh --with-tk to do it automatically)"
else
warn "Install the Tkinter package for your distro (often named python3-tk or python3-tkinter)."
fi
fi
fi
# --- 3. copy application files (portable location) -------------------------
mkdir -p "$SHARE_DIR"
rm -rf "$SHARE_DIR/allconv"
cp -r "$SRC_DIR/allconv" "$SHARE_DIR/"
green "Copied application to $SHARE_DIR"
# --- 4. create the 'allconv' command --------------------------------------
mkdir -p "$BIN_DIR"
cat > "$BIN_DIR/allconv" <<EOF
#!/usr/bin/env bash
# AllConv launcher (auto-generated by install.sh)
export PYTHONPATH="$SHARE_DIR\${PYTHONPATH:+:\$PYTHONPATH}"
exec python3 -m allconv.cli "\$@"
EOF
chmod +x "$BIN_DIR/allconv"
green "Created command: $BIN_DIR/allconv"
# --- 5. GUI launcher + application-menu entry (freedesktop standard) --------
cat > "$BIN_DIR/allconv-gui" <<EOF
#!/usr/bin/env bash
export PYTHONPATH="$SHARE_DIR\${PYTHONPATH:+:\$PYTHONPATH}"
exec python3 -m allconv.gui "\$@"
EOF
chmod +x "$BIN_DIR/allconv-gui"
mkdir -p "$DESKTOP_DIR"
cat > "$DESKTOP_DIR/allconv.desktop" <<EOF
[Desktop Entry]
Type=Application
Name=AllConv
GenericName=Document Converter
Comment=Convert between PDF, HTML and Markdown
Exec=$BIN_DIR/allconv-gui
Terminal=false
Categories=Utility;Office;
Keywords=pdf;html;markdown;convert;
EOF
# Refresh the menu database if the tool exists (harmless if it doesn't).
command -v update-desktop-database >/dev/null 2>&1 && \
update-desktop-database "$DESKTOP_DIR" >/dev/null 2>&1 || true
green "Added 'AllConv' to your application menu."
# --- 6. PATH check ---------------------------------------------------------
case ":$PATH:" in
*":$BIN_DIR:"*) : ;;
*)
warn ""
warn "$BIN_DIR is not on your PATH yet."
warn "Add this line to your shell config and restart the terminal:"
warn ' export PATH="$HOME/.local/bin:$PATH"'
warn " bash -> ~/.bashrc zsh -> ~/.zshrc fish -> ~/.config/fish/config.fish"
;;
esac
green ""
green "AllConv installed successfully!"
echo "Try it:"
echo " allconv --help"
echo " allconv report.pdf report.md"
echo " allconv --gui"