Skip to content

Commit

Permalink
[CHORE] build.sh improve + security info
Browse files Browse the repository at this point in the history
  • Loading branch information
nots1dd committed Jul 28, 2024
1 parent 632905d commit 8b3edca
Show file tree
Hide file tree
Showing 3 changed files with 125 additions and 15 deletions.
21 changes: 17 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,15 @@ Lightweight and Fast as FUCK file manager written in C with ncurses library

LiteFM cannot be installed in any UNIX-like distribution but can be easily built!

> DEPS
> ![NOTE]
>
> Dependencies to install for LiteFM:
>
> CMake / Make
>
> Ncurses library (libncurses-dev for debian)
>
> libarchive (for extraction of archives)
> libarchive (for extraction and compression)
>
> A C compiler (like GCC)
>
Expand All @@ -51,7 +53,7 @@ Building with Make:

-> To cleanup, run `make clean`

> [!TIP]
> [!NOTE]
> Building LiteFM with build.sh
>
> chmod +x build.sh
Expand All @@ -60,6 +62,17 @@ Building with Make:
>
> Thats all! Enjoy LiteFM
## SECURITY

As this is a file manager that is able to perform some VERY cool and dangerous tasks like deleting any directory recursively, I definitely have tried to set up security measures to avoid any form of code vulnerability or CWE.

Other steps I plan on taking to ensure that you are always in control of the file manager are:

1. Setting up a log file to keep track of every change being made to any inode in your filesystem. [priority/high]
2. Possibly set up a trash system so that accidental deletion of any file/dir can be restored [priority/low]

Check out `SECURITY.md` for the security policy that this repository follows.

## FUTURE

This file manager is far from done there are a lot of cool and essential features that are planned:
Expand All @@ -74,6 +87,6 @@ This file manager is far from done there are a lot of cool and essential feature

- [ ] Bugfixes and massive code refactor

- [ ] Improve the build script
- [x] Improve the build script

- [ ] Integration of adding a text editor
117 changes: 107 additions & 10 deletions build.sh
Original file line number Diff line number Diff line change
@@ -1,9 +1,101 @@
# !/bin/bash
#!/bin/bash

# Define colors
GREEN="\e[32m"
RED="\e[31m"
PINK="\e[35m"
RESET="\e[0m"

# Function to detect the package manager and distribution
detect_distro() {
if command -v dpkg-query &> /dev/null; then
echo "debian"
elif command -v rpm &> /dev/null; then
echo "rpm"
elif command -v pacman &> /dev/null; then
echo "arch"
else
echo "unsupported"
fi
}

# Function to check if a package is installed
check_package_installed() {
local distro="$1"
local package="$2"

if [ "$distro" == "debian" ]; then
dpkg-query -W -f='${Status}' "$package" 2>/dev/null | grep -c "ok installed"
elif [ "$distro" == "rpm" ]; then
rpm -q "$package" &> /dev/null
elif [ "$distro" == "arch" ]; then
pacman -Q "$package" &> /dev/null
else
echo "Unsupported package manager."
return 1
fi
}

# Function to install packages based on the distribution
install_packages() {
local distro="$1"
shift
local packages=("$@")

echo -e "${PINK}Installing missing packages: ${packages[*]}${RESET}"
if [ "$distro" == "debian" ]; then
sudo apt-get update
sudo apt-get install -y "${packages[@]}"
elif [ "$distro" == "rpm" ]; then
sudo yum install -y "${packages[@]}"
elif [ "$distro" == "arch" ]; then
sudo pacman -Syu --needed "${packages[@]}"
else
echo -e "${RED}Unsupported distribution.${RESET}"
exit 1
fi
}

# Title
echo "===================="
echo " LiteFM "
echo "===================="
echo -e "${GREEN}===================="
echo -e " LiteFM "
echo -e "====================${RESET}"

# Detect the distribution
distro=$(detect_distro)
if [ "$distro" == "unsupported" ]; then
echo -e "${RED}Unsupported Linux distribution.${RESET}"
exit 1
fi

echo -e "${PINK}Building for $distro...${RESET}"

# Define the required packages based on the distribution
if [ "$distro" == "debian" ]; then
required_packages=("libncurses-dev" "cmake" "make" "libarchive-dev")
elif [ "$distro" == "rpm" ]; then
required_packages=("ncurses" "cmake" "make" "libarchive")
elif [ "$distro" == "arch" ]; then
required_packages=("ncurses" "cmake" "make" "libarchive")
fi

# Check for required packages
missing_packages=()

for package in "${required_packages[@]}"; do
if check_package_installed "$distro" "$package"; then
echo -e "${GREEN}Package $package is already installed.${RESET}"
else
echo -e "${RED}Package $package is missing.${RESET}"
missing_packages+=("$package")
fi
done

if [ ${#missing_packages[@]} -ne 0 ]; then
install_packages "$distro" "${missing_packages[@]}"
else
echo -e "${GREEN}All required packages are already installed.${RESET}"
fi

# Prompt for build type
read -p "Enter the type of build (cmake or make): " build_type
Expand All @@ -15,21 +107,26 @@ if [ "$build_type" == "cmake" ]; then
elif [ "$build_type" == "make" ]; then
make
else
echo "Invalid build type. Please enter 'cmake' or 'make'."
echo -e "${RED}Invalid build type. Please enter 'cmake' or 'make'.${RESET}"
exit 1
fi

# Check if the build was successful
if [ $? -ne 0 ]; then
echo "Build failed."
echo -e "${RED}Build failed.${RESET}"
exit 1
fi

# Copy the man file and gzip it
sudo cp components/litefm.1 /usr/share/man/man1/
sudo gzip /usr/share/man/man1/litefm.1
echo -e "${PINK}============ MAN PAGE =============${RESET}"
read -p "Add manual page? (y/n) " confirm_man
if [ "$confirm_man" == "y" ]; then
sudo cp components/litefm.1 /usr/share/man/man1/
sudo gzip /usr/share/man/man1/litefm.1
fi

# Create alias in the appropriate shell configuration file
echo -e "${PINK}============= SETTING ALIAS =========${RESET}"
SHELL_NAME=$(basename "$SHELL")
case "$SHELL_NAME" in
bash)
Expand All @@ -39,8 +136,8 @@ case "$SHELL_NAME" in
echo "alias lfm='$(pwd)/build/litefm'" >> ~/.zshrc
;;
*)
echo "Shell $SHELL_NAME not supported for alias creation. Please create the alias manually."
echo -e "${RED}Shell $SHELL_NAME not supported for alias creation. Please create the alias manually.${RESET}"
;;
esac

echo "Build completed and man page installed. Please restart your terminal or source your rc file to use the litefm command."
echo -e "${GREEN}Build completed and man page installed. Please restart your terminal or source your rc file to use the litefm command.${RESET}"
2 changes: 1 addition & 1 deletion lfm.c
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ void get_file_info_popup(WINDOW *main_win, const char *path, const char *filenam

// Create a new window for displaying file information
int info_win_height = 10;
int info_win_width = (COLS / 3) - 4;
int info_win_width = (COLS / 3) + 4;
int info_win_y = (LINES - info_win_height) / 2;
int info_win_x = (COLS - info_win_width) / 2;

Expand Down

0 comments on commit 8b3edca

Please sign in to comment.