Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 58 additions & 1 deletion INSTALL.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,75 @@ echo "Creating installer script..."
cat <<"EOF" >${HOME}/.capt/capt
#!/bin/bash

GREEN_COLOR="\033[1;32m"
YELLOW_COLOR="\033[1;33m"
BLUE_COLOR="\033[0;34m"
NO_COLOR="\033[0m"

cd ${HOME}/.capt/debs_temp
rm -rf *.deb

print_error() {
local RED_COLOR="\033[1;31m"
echo -e "${RED_COLOR}ERROR: ${NO_COLOR}$1"
}

does_package_exist() {
if [ ! $1 ]; then
print_error "Missing the package name..."
exit 1
fi
local name="$1"
local packages_list=$(apt-cache pkgnames "$name" | grep -x "$name" | wc -l)
if [ "$packages_list" -eq 0 ]; then
print_error "No result found..."
exit 1
elif [ "$packages_list" -gt 1 ]; then
print_error "Multiple packages match this name"
apt-cache pkgnames "$name" | grep -x "$name"
exit 1
fi
}

search_package() {
if [ ! $1 ]; then
print_error "Missing the search parameter..."
exit 1
fi
echo "Searching for the package..."
local search_results=$(apt-cache search --names-only $1)
local nb_packages=$(echo "$search_results" | wc -l)
if [ "$nb_packages" -eq 0 ]; then
print_error "No result found..."
exit 1
fi
echo "$search_results" | while read pkg description; do
echo -e "${GREEN_COLOR}${pkg}${NO_COLOR} ${description}"
done
echo -e "\n${YELLOW_COLOR}Found ${nb_packages} packages${NO_COLOR}"
}

if [[ $1 == "install" ]]; then
if [ ! $2 ]; then
print_error "Missing package name..."
exit 1
fi
does_package_exist $2
echo "Downloading prerequisites..."
apt-get download $(apt-cache depends --recurse --no-recommends --no-suggests --no-conflicts --no-breaks --no-replaces --no-enhances $2 | grep "^\w" | sort -u)
echo "Installing..."
find . -iname "*.deb" -type f -exec dpkg -x {} ${HOME}/.capt/root \;
echo "Finished installing, removing temp files..."
rm -rf *.deb
echo "Done"
elif [[ $1 == "search" ]]; then
if [ ! $2 ]; then
print_error "Missing the search parameter..."
exit 1
fi
search_package $2
else
echo "Capt only supports \`capt install\`"
echo "Capt only supports \`capt install and capt search\`"
fi

EOF
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ How to install `capt`\
Download & run `installer.sh`: `wget https://raw.githubusercontent.com/PanoramixDeDruide/Codam_apt/main/INSTALL.sh && chmod +x INSTALL.sh && ./INSTALL.sh`

How to check if the `apt` package of your choice is available\
-Run `apt-cache search <package-name>`
-Run `capt search <package-name>`

How to install a package\
-Run `capt install <package-name>`
Expand Down