mirror of
https://github.com/kuhyx/scripts.git
synced 2026-11-10 20:07:12 +01:00
feat: simplify pacman wrapper installation
This commit is contained in:
parent
13c1512ce1
commit
389078a81f
@ -1,6 +1,13 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
# filepath: /home/kuhy/linux-configuration/scripts/install_pacman_wrapper.sh
|
# filepath: /home/kuhy/linux-configuration/scripts/install_pacman_wrapper.sh
|
||||||
|
|
||||||
|
# Auto-sudo functionality
|
||||||
|
if [ "$EUID" -ne 0 ]; then
|
||||||
|
echo "Executing with sudo..."
|
||||||
|
sudo "$0" "$@"
|
||||||
|
exit $?
|
||||||
|
fi
|
||||||
|
|
||||||
# Colors
|
# Colors
|
||||||
RED='\033[0;31m'
|
RED='\033[0;31m'
|
||||||
GREEN='\033[0;32m'
|
GREEN='\033[0;32m'
|
||||||
@ -34,55 +41,23 @@ echo -e "${BLUE}Copying wrapper script to ${WRAPPER_DEST}...${NC}"
|
|||||||
cp "$WRAPPER_SOURCE" "$WRAPPER_DEST"
|
cp "$WRAPPER_SOURCE" "$WRAPPER_DEST"
|
||||||
chmod +x "$WRAPPER_DEST"
|
chmod +x "$WRAPPER_DEST"
|
||||||
|
|
||||||
# Choose installation method
|
# Automatically use symbolic link installation method
|
||||||
echo -e "${YELLOW}Select installation method:${NC}"
|
echo -e "${YELLOW}Installing using symbolic link method...${NC}"
|
||||||
echo "1. Create alias in /etc/profile.d/ (recommended)"
|
|
||||||
echo "2. Create symbolic link (advanced)"
|
|
||||||
read -p "Enter choice (1-2): " choice
|
|
||||||
|
|
||||||
case $choice in
|
# Backup original pacman
|
||||||
1)
|
if [ ! -f "/usr/bin/pacman.orig" ]; then
|
||||||
# Create an alias file in /etc/profile.d/
|
echo -e "${BLUE}Backing up original pacman to /usr/bin/pacman.orig...${NC}"
|
||||||
echo -e "${BLUE}Creating system-wide alias...${NC}"
|
cp /usr/bin/pacman /usr/bin/pacman.orig
|
||||||
cat > /etc/profile.d/pacman-wrapper.sh << EOF
|
fi
|
||||||
#!/bin/bash
|
|
||||||
alias pacman='$WRAPPER_DEST'
|
# Update the PACMAN_BIN variable in the wrapper to point to the original
|
||||||
EOF
|
sed -i 's|PACMAN_BIN="\/usr\/bin\/pacman"|PACMAN_BIN="\/usr\/bin\/pacman.orig"|g' "$WRAPPER_DEST"
|
||||||
chmod +x /etc/profile.d/pacman-wrapper.sh
|
|
||||||
echo -e "${GREEN}Installation complete!${NC}"
|
# Create symbolic link
|
||||||
echo -e "${YELLOW}Note:${NC} You need to log out and log back in for the alias to take effect."
|
echo -e "${BLUE}Creating symbolic link...${NC}"
|
||||||
echo -e "Alternatively, run: ${CYAN}source /etc/profile.d/pacman-wrapper.sh${NC}"
|
ln -sf "$WRAPPER_DEST" /usr/bin/pacman
|
||||||
;;
|
echo -e "${GREEN}Installation complete!${NC}"
|
||||||
2)
|
echo -e "Pacman is now wrapped. The original pacman is available at ${CYAN}/usr/bin/pacman.orig${NC}"
|
||||||
# Create a symbolic link
|
|
||||||
echo -e "${YELLOW}Warning: This method replaces the pacman command directly.${NC}"
|
|
||||||
echo -e "Make sure your wrapper script is fully functional to avoid system issues."
|
|
||||||
read -p "Are you sure you want to continue? (y/N): " confirm
|
|
||||||
if [[ "$confirm" == [yY] || "$confirm" == [yY][eE][sS] ]]; then
|
|
||||||
# Backup original pacman
|
|
||||||
if [ ! -f "/usr/bin/pacman.orig" ]; then
|
|
||||||
echo -e "${BLUE}Backing up original pacman to /usr/bin/pacman.orig...${NC}"
|
|
||||||
cp /usr/bin/pacman /usr/bin/pacman.orig
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Update the PACMAN_BIN variable in the wrapper to point to the original
|
|
||||||
sed -i 's|PACMAN_BIN="\/usr\/bin\/pacman"|PACMAN_BIN="\/usr\/bin\/pacman.orig"|g' "$WRAPPER_DEST"
|
|
||||||
|
|
||||||
# Create symbolic link
|
|
||||||
echo -e "${BLUE}Creating symbolic link...${NC}"
|
|
||||||
ln -sf "$WRAPPER_DEST" /usr/bin/pacman
|
|
||||||
echo -e "${GREEN}Installation complete!${NC}"
|
|
||||||
echo -e "Pacman is now wrapped. The original pacman is available at ${CYAN}/usr/bin/pacman.orig${NC}"
|
|
||||||
else
|
|
||||||
echo -e "${YELLOW}Installation cancelled.${NC}"
|
|
||||||
exit 0
|
|
||||||
fi
|
|
||||||
;;
|
|
||||||
*)
|
|
||||||
echo -e "${RED}Invalid choice. Installation cancelled.${NC}"
|
|
||||||
exit 1
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
|
|
||||||
# Create uninstaller
|
# Create uninstaller
|
||||||
echo -e "${BLUE}Creating uninstaller...${NC}"
|
echo -e "${BLUE}Creating uninstaller...${NC}"
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user