Files
public-setupfiles/update-from_repo.sh
T

49 lines
1.4 KiB
Bash
Raw Normal View History

2024-05-09 15:48:15 -05:00
#!/bin/bash
2025-01-29 19:51:33 -06:00
# Detect if the system is Debian/Ubuntu-based or OpenWRT
if command -v apt &> /dev/null; then
PACKAGE_MANAGER="apt"
UPDATE_CMD="sudo apt update -y"
INSTALL_CMD="sudo apt install -y"
elif command -v opkg &> /dev/null; then
PACKAGE_MANAGER="opkg"
UPDATE_CMD="opkg update"
INSTALL_CMD="opkg install"
else
echo "Unsupported system. This script supports Debian/Ubuntu (apt) and OpenWRT (opkg)."
exit 1
fi
# Update package lists
echo "Updating package lists using $PACKAGE_MANAGER..."
$UPDATE_CMD
2024-05-09 16:22:56 -05:00
# Check if git is installed
if ! command -v git &> /dev/null; then
2025-01-29 19:51:33 -06:00
echo "Git is not installed. Installing git using $PACKAGE_MANAGER..."
$INSTALL_CMD git
else
echo "Git is already installed."
2024-05-09 16:22:56 -05:00
fi
2024-05-09 15:48:15 -05:00
# Specify the remote repository URL
2024-05-09 15:59:36 -05:00
remote_repo="https://github.com/wickedyoda/public-setupfiles.git"
2024-05-09 15:48:15 -05:00
# Specify the local file path
2024-05-10 22:55:20 -05:00
local_file="./public-setupfiles"
2024-05-09 15:48:15 -05:00
2024-05-09 16:02:52 -05:00
# Check if the local file path exists and is not empty
2025-01-29 19:51:33 -06:00
if [ -d "$local_file" ] && [ -n "$(ls -A $local_file 2>/dev/null)" ]; then
echo "Existing directory detected. Deleting $local_file..."
2024-05-09 16:22:56 -05:00
sudo rm -rf "$local_file"
2024-05-09 15:59:36 -05:00
fi
2024-05-09 16:02:52 -05:00
# Clone the remote repository to the local file path
2025-01-29 19:51:33 -06:00
echo "Cloning repository from $remote_repo to $local_file..."
2024-05-09 16:02:52 -05:00
git clone "$remote_repo" "$local_file"
2024-05-09 16:09:58 -05:00
2025-01-29 19:51:33 -06:00
# Make all files executable and set public ownership
echo "Setting permissions for $local_file..."
sudo chmod -R 777 "$local_file"
2024-05-09 16:22:56 -05:00
2025-01-29 19:51:33 -06:00
echo "Script execution completed successfully!"