diff --git a/CHANGELOGS.md b/CHANGELOGS.md index 55176f7..90925ec 100644 --- a/CHANGELOGS.md +++ b/CHANGELOGS.md @@ -1,5 +1,8 @@ ## Changelogs +## 19-Nov-2023 +- Adjust dotfiles script to download from releases instead of from upstream + ## 14-Oct-2023 - initial release. Added swappy for screenshots diff --git a/install-scripts/00-hypr-pkgs.sh b/install-scripts/00-hypr-pkgs.sh index 9782447..fcfa441 100644 --- a/install-scripts/00-hypr-pkgs.sh +++ b/install-scripts/00-hypr-pkgs.sh @@ -14,7 +14,6 @@ Extra=( # packages neeeded hypr_package=( cliphist - curl dunst grim gvfs diff --git a/install-scripts/dotfiles.sh b/install-scripts/dotfiles.sh index 28663d8..06e5716 100644 --- a/install-scripts/dotfiles.sh +++ b/install-scripts/dotfiles.sh @@ -10,25 +10,88 @@ ORANGE=$(tput setaf 166) YELLOW=$(tput setaf 3) RESET=$(tput sgr0) -# Set the name of the log file to include the current date and time -LOG="install-$(date +'%d-%H%M%S')_dots.log" +printf "${NOTE} Downloading / Checking for existing Hyprland-Dots.tar.gz...\n" -printf "${NOTE} Downloading Hyprland dots...\n" +# Check if Hyprland-Dots.tar.gz exists +if [ -f Hyprland-Dots.tar.gz ]; then + printf "${NOTE} Hyprland-Dots.tar.gz found.\n" -if [ -d Hyprland-Dots ]; then - cd Hyprland-Dots - git stash - git pull - git stash apply - chmod +x copy.sh - ./copy.sh 2>&1 | tee -a "$LOG" -else - if git clone https://github.com/JaKooLit/Hyprland-Dots; then - cd Hyprland-Dots || exit 1 - chmod +x copy.sh - ./copy.sh 2>&1 | tee -a "$LOG" + # Get the version from the existing tarball filename + existing_version=$(echo Hyprland-Dots.tar.gz | grep -oP 'v\d+\.\d+\.\d+' | sed 's/v//') + + # Fetch the tag_name for the latest release using the GitHub API + latest_version=$(curl -s https://api.github.com/repos/JaKooLit/Hyprland-Dots/releases/latest | grep "tag_name" | cut -d '"' -f 4 | sed 's/v//') + + # Check if versions match + if [ "$existing_version" = "$latest_version" ]; then + echo -e "${OK} Hyprland-Dots.tar.gz is up-to-date with the latest release ($latest_version)." + + # Sleep for 10 seconds before exiting + printf "${NOTE} No update found. Sleeping for 10 seconds...\n" + sleep 10 + exit 0 else - echo -e "${ERROR} Can't download Hyprland-Dots" 2>&1 | tee -a "$LOG" + echo -e "${WARN} Hyprland-Dots.tar.gz is outdated (Existing version: $existing_version, Latest version: $latest_version)." + read -p "Do you want to upgrade to the latest version? (y/n): " upgrade_choice + if [ "$upgrade_choice" = "y" ]; then + echo -e "${NOTE} Proceeding to download the latest release." + + # Delete existing directories starting with JaKooLit-Hyprland-Dots + find . -type d -name 'JaKooLit-Hyprland-Dots*' -exec rm -rf {} + + rm -f Hyprland-Dots.tar.gz + printf "${WARN} Removed existing Hyprland-Dots.tar.gz.\n" + else + echo -e "${NOTE} User chose not to upgrade. Exiting..." + exit 0 + fi fi fi +printf "${NOTE} Downloading the latest Hyprland source code release...\n" + +# Fetch the tag name for the latest release using the GitHub API +latest_tag=$(curl -s https://api.github.com/repos/JaKooLit/Hyprland-Dots/releases/latest | grep "tag_name" | cut -d '"' -f 4) + +# Check if the tag is obtained successfully +if [ -z "$latest_tag" ]; then + echo -e "${ERROR} Unable to fetch the latest tag information." + exit 1 +fi + +# Fetch the tarball URL for the latest release using the GitHub API +latest_tarball_url=$(curl -s https://api.github.com/repos/JaKooLit/Hyprland-Dots/releases/latest | grep "tarball_url" | cut -d '"' -f 4) + +# Check if the URL is obtained successfully +if [ -z "$latest_tarball_url" ]; then + echo -e "${ERROR} Unable to fetch the tarball URL for the latest release." + exit 1 +fi + +# Get the filename from the URL and include the tag name in the file name +file_name="Hyprland-Dots-${latest_tag}.tar.gz" + +# Download the latest release source code tarball to the current directory +if curl -L "$latest_tarball_url" -o "$file_name"; then + # Extract the contents of the tarball + tar -xzf "$file_name" || exit 1 + + # delete existing Hyprland-Dots + rm -rf JaKooLit-Hyprland-Dots + + # Identify the extracted directory + extracted_directory=$(tar -tf "$file_name" | grep -o '^[^/]\+' | uniq) + + # Rename the extracted directory to JaKooLit-Hyprland-Dots + mv "$extracted_directory" JaKooLit-Hyprland-Dots || exit 1 + + cd "JaKooLit-Hyprland-Dots" || exit 1 + + # Set execute permission for copy.sh and execute it + chmod +x copy.sh + ./copy.sh 2>&1 | tee -a "../install-$(date +'%d-%H%M%S')_dots.log" + + echo -e "${OK} Latest source code release downloaded, extracted, and processed successfully." +else + echo -e "${ERROR} Failed to download the latest source code release." + exit 1 +fi