-
-
Notifications
You must be signed in to change notification settings - Fork 82
/
Copy pathinstall_extract.sh
70 lines (58 loc) · 2.06 KB
/
install_extract.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
#!/usr/bin/env bash
# Installer for the extract.sh script
#
# Example:
# $ install_extract.sh
#
# Author: Vitalii Tereshchuk, 2024
# Web: https://dotoca.net
# Github: https://github.com/xvoland/Extract/blob/master/extract.sh
#
TARGET_PATH="/usr/local/bin/extract"
SCRIPT_URL="https://raw.githubusercontent.com/xvoland/Extract/master/extract.sh"
TMP_SCRIPT="/tmp/extract.sh"
# Check if 'curl' is installed
if ! command -v curl &>/dev/null; then
echo "Error: 'curl' is required to download the script. Please install it first."
exit 1
fi
# Check if the script is already installed
if [ -f "$TARGET_PATH" ]; then
read -p "$TARGET_PATH already exists. Overwrite? (y/n): " choice
case "$choice" in
y|Y ) echo "Overwriting $TARGET_PATH..." ;;
n|N ) echo "Installation aborted."; exit 0 ;;
* ) echo "Invalid input. Installation aborted."; exit 1 ;;
esac
fi
# Download extract.sh script from GitHub
echo "Downloading extract.sh..."
if ! curl -L -o "$TMP_SCRIPT" "$SCRIPT_URL"; then
echo "Error: Failed to download extract.sh"
exit 1
fi
# List of required tools for extraction
REQUIRED_TOOLS=("unzip" "tar" "unrar" "gunzip" "7z" "unlzma" "bzip2" "xz" "cabextract" "zstd")
MISSING_TOOLS=()
# Check if required tools are installed
for tool in "${REQUIRED_TOOLS[@]}"; do
if ! command -v "$tool" &>/dev/null; then
MISSING_TOOLS+=("$tool")
fi
done
# Warn the user about missing tools but continue installation
if [ ${#MISSING_TOOLS[@]} -ne 0 ]; then
echo "Warning: The following tools are missing, some formats may not be supported:"
printf ' - %s\n' "${MISSING_TOOLS[@]}"
fi
# Check if the user has sudo privileges (if not root)
if [ "$(id -u)" -ne 0 ] && ! command -v sudo &>/dev/null; then
echo "Error: You need sudo privileges to install the script in $TARGET_PATH."
exit 1
fi
# Move the script to the target directory
echo "Installing extract.sh to $TARGET_PATH..."
sudo mv "$TMP_SCRIPT" "$TARGET_PATH"
# Set execute permissions
sudo chmod +x "$TARGET_PATH"
echo "Installation complete! Use 'extract' to extract files."