-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
installer.sh
205 lines (168 loc) · 7.32 KB
/
installer.sh
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
#!/bin/bash
: '
▀▀█▀▀ █▀▀ █▀▀█ █▀▄▀█ ▒█▀▀█ ▒█▀▀▄ ▒█▀▀▀ ▒█░░▒█ ░▀░ █▀▀ █░░░█ █▀▀ █▀▀█
░▒█░░ █▀▀ █▄▄▀ █░▀░█ ▒█▄▄█ ▒█░▒█ ▒█▀▀▀ ░▒█▒█░ ▀█▀ █▀▀ █▄█▄█ █▀▀ █▄▄▀
░▒█░░ ▀▀▀ ▀░▀▀ ▀░░░▀ ▒█░░░ ▒█▄▄▀ ▒█░░░ ░░▀▄▀░ ▀▀▀ ▀▀▀ ░▀░▀░ ▀▀▀ ▀░▀▀
*************************************************
TermPDF Viewer - view and navigate PDF files within the terminal.
*************************************************
* Simple: TermPDF Viewer is a Python program that enables users to
view and navigate PDF files directly within the terminal.
*************************************************
* Developed and engineered by:
* Felipe Alfonso Gonzalez <f.alfonso@res-ear.ch>
* Computer Science Engineer
* Chile
*************************************************
* Prerequisites:
* Python 3.x: The program is written in Python and requires a Python 3.x interpreter to run.
* PyMuPDF: A Python binding for the MuPDF library, used to handle PDF file rendering and interaction.
* You can install it using pip: pip install PyMuPDF
* Make sure to include the appropriate model or adapt it for your needs.
*************************************************
* How to run the TermPDF Viewer:
* Clone the TermPDF Viewer repository from GitHub.
* Navigate to the project directory:
* cd TermPDF-Viewer
* Install PyMuPDF library (if not already installed):
pip install PyMuPDF
* Run the TermPDF Viewer:
* python termpdf.py
* The TermPDF Viewer will start, allowing you to:
* Scan for PDF files in the current directory.
* Select a PDF file to view by entering its number.
* View the PDF with options to move back, forward, or return to the main menu.
* Quit and return to the main menu.
* To exit the TermPDF Viewer, use 'q' in the main menu.
*
*************************************************
* Important Notes:
* - The application has been tested on Linux and macOS.
* - For Windows, additional configurations may be required.
* - Make sure to fulfill the prerequisites before running the application.
* - For more information, please refer to the project documentation.
*************************************************
'
welcome_message() {
echo
echo "▀▀█▀▀ █▀▀ █▀▀█ █▀▄▀█ ▒█▀▀█ ▒█▀▀▄ ▒█▀▀▀ ▒█░░▒█ ░▀░ █▀▀ █░░░█ █▀▀ █▀▀█"
echo "░▒█░░ █▀▀ █▄▄▀ █░▀░█ ▒█▄▄█ ▒█░▒█ ▒█▀▀▀ ░▒█▒█░ ▀█▀ █▀▀ █▄█▄█ █▀▀ █▄▄▀"
echo "░▒█░░ ▀▀▀ ▀░▀▀ ▀░░░▀ ▒█░░░ ▒█▄▄▀ ▒█░░░ ░░▀▄▀░ ▀▀▀ ▀▀▀ ░▀░▀░ ▀▀▀ ▀░▀▀"
echo "-------------------------------------------------------------------------"
echo "TermPDF Viewer - view and navigate PDF files within the terminal."
echo "-------------------------------------------------------------------------"
echo "* Simple: TermPDF Viewer is a Python program that enables users to "
echo "* view and navigate PDF files directly within the terminal."
echo "-------------------------------------------------------------------------"
echo
echo "╭────────────-----────── TERMS OF USE ──────────----------───╮"
echo "│ This software is licensed under the MIT License. │"
echo "│ By Felipe Alfonso González - github.com/felipealfonsog │"
echo "│ Computer Science Engineer - Email: f.alfonso@res-ear.ch │"
echo "╰───────────────────────────────────────────────---------────╯"
echo
echo "Welcome to the TermPDF Viewer Installer!"
echo "This script will install the TermPDF Viewer program on your system."
echo "Please make sure you have the necessary permissions to perform the installation."
echo "Press Enter to continue or Ctrl+C to exit."
read
}
install_homebrew() {
if ! command -v brew &>/dev/null; then
echo "Homebrew not found. Installing Homebrew..."
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
fi
}
install_dependencies() {
if ! command -v python &>/dev/null; then
echo "Python not found. Installing Python..."
brew install python
else
echo "Python is already installed"
fi
if ! command -v pip &>/dev/null; then
echo "Pip not found. Installing pip..."
brew install python
else
echo "Pip is already installed"
fi
if ! pip show pymupdf &>/dev/null; then
echo "PyMuPDF not found. Installing PyMuPDF..."
pip install PyMuPDF
else
echo "PyMuPDF is already installed"
fi
if ! pip show termcolor &>/dev/null; then
echo "Termcolor library not found. Installing Termcolor..."
pip install termcolor
else
echo "Termcolor is already installed"
fi
}
download_wrp() {
local os=$(uname -s)
local installer_url="https://github.com/felipealfonsog/TermPDFViewer/raw/main/src/term-pdf-wrp.c"
if [[ "$os" == "Darwin" || "$os" == "Linux" ]]; then
echo "Downloading the term-pdf-wrp (Wrapper)..."
curl -o term-pdf-wrp.c -L "$installer_url"
else
echo "Unsupported platform."
exit 1
fi
}
download_termpdf() {
local os=$(uname -s)
local installer_url="https://github.com/felipealfonsog/TermPDFViewer/raw/main/src/termpdf.py"
if [[ "$os" == "Darwin" || "$os" == "Linux" ]]; then
echo "Downloading the termpdf..."
curl -o termpdf.py -L "$installer_url"
else
echo "Unsupported platform."
exit 1
fi
}
compile_term_pdf_wrapper() {
echo "Compiling term-pdf-wrapper..."
gcc -o term-pdf-wrapper term-pdf-wrp.c || {
echo "Error: Compilation failed."
exit 1
}
sudo chmod +x term-pdf-wrapper
echo "Compilation successful."
}
move_to_bin_directory() {
echo "Moving compiled binary to bin directory..."
sudo mv termpdf.py "/usr/local/bin"
sudo mv term-pdf-wrapper "/usr/local/bin/term-pdf"
sudo chmod +x "/usr/local/bin/termpdf.py"
sudo chmod +x "/usr/local/bin/term-pdf"
echo "Binary moved to '/usr/local/bin' and permissions set."
}
run_termpdf_viewer() {
echo "Running the TermPDF Viewer..."
#python3 /home/felipe/.config/termpdf.py
python3 /usr/local/bin/termpdf.py
echo "TermPDF Viewer executed."
}
remove_compiled_file() {
echo "Removing unnecessary files..."
rm -rf *.c
rm -rf *.py
rm installer.sh
echo "Cleanup complete."
}
set_permissions() {
echo "Setting permissions..."
# chmod 755 ./config/termpdf.py
echo "Permissions set."
}
welcome_message
install_dependencies
download_wrp
download_termpdf
compile_term_pdf_wrapper
move_to_bin_directory
# run_termpdf_viewer
remove_compiled_file
# set_permissions
echo "TermPDF Viewer has been successfully installed as 'term-pdf' command!"