Skip to content

Commit

Permalink
internal scripts FINALLY work
Browse files Browse the repository at this point in the history
  • Loading branch information
Hassunaama committed Sep 3, 2024
1 parent 69eb397 commit a3c391f
Show file tree
Hide file tree
Showing 2 changed files with 117 additions and 14 deletions.
72 changes: 58 additions & 14 deletions tools/internal/privateassetscommit.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,29 @@
set -e

if [ "$#" -ne 1 ]; then
echo "Usage: $0 destination_directory"
echo "Usage: $0 commit_message"
exit 1
fi

destination_directory="$1"
temp_directory="/tmp/axsion-pro-private-assets"
commit_message="$1"

if [ ! -d "$destination_directory" ]; then
echo "Error: Destination directory does not exist"
exit 1
# Remove existing temp directory if it exists
if [ -d "$temp_directory" ]; then
rm -rf "$temp_directory"
fi

echo "Cloning repo into temporary directory..."
git clone https://github.com/Axsoter/axsion-pro-private-assets.git "$temp_directory" --quiet
echo "Done!"

#

echo "Copying files to temp directory"

start_line=$(grep -n "# Private main website files" "$(pwd)/.gitignore" | cut -d: -f1)
if [ -z "$start_line" ]; then
echo "Error: Marker '# Private main website files' not found in the .gitignore (what the fuck?)"
echo "Error: Marker '# Private main website files' not found in the .gitignore."
exit 1
fi

Expand All @@ -25,16 +34,51 @@ start_line=$((start_line + 1))
awk "NR >= $start_line" "$(pwd)/.gitignore" | while read -r line; do
# Remove the leading slash from the path
relative_path="${line#/}"

# Full path to the file/directory
full_path="$(pwd)/$relative_path"

# Copy files or directories to the destination directory
if [ -e "$full_path" ]; then
cp -r "$full_path" "$destination_directory"
source_path="$(pwd)/$relative_path"
temp_path="$temp_directory/$relative_path"

if [ -d "$source_path" ]; then
echo "Copying directory '$relative_path'..."
# Ensure the target directory exists
mkdir -p "$temp_path"
# Copy the contents of the source directory to the target directory
cp -r "$source_path/"* "$temp_path/"
elif [ -f "$source_path" ]; then
echo "Copying file '$relative_path'..."
# Ensure the parent directory exists, not the file's directory itself
mkdir -p "$(dirname "$temp_path")"
# Copy the file
cp "$source_path" "$temp_path"
else
echo "Warning: $full_path does not exist."
echo "Warning: $source_path does not exist. (have you pulled anything yet?)"
fi
done

echo "Files copied to $destination_directory"
echo "Done!"

#

echo "Committing and pushing with message '$commit_message'..."

cd "$temp_directory"

# Stage all changes
git add .

# Commit the changes with the provided message
git commit -m "$commit_message" --quiet

# Push the changes to the remote repository
git push origin main --quiet

echo "Done!"

#

echo "Cleaning up..."

rm -rf "$temp_directory"

echo "All done!"
59 changes: 59 additions & 0 deletions tools/internal/privateassetspull.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,62 @@
#!/usr/bin/env bash

set -e

# Create a temporary directory
temp_directory="/tmp/axsion-pro-private-assets"

# Ensure the temporary directory doesn't exist before cloning
if [ -d "$temp_directory" ]; then
rm -rf "$temp_directory"
fi

echo "Cloning repo into temporary directory..."
git clone https://github.com/Axsoter/axsion-pro-private-assets.git "$temp_directory" --quiet
echo "Done!"

#

echo "Copying files from temp directory to current working directory..."

start_line=$(grep -n "# Private main website files" "$(pwd)/.gitignore" | cut -d: -f1)
if [ -z "$start_line" ]; then
echo "Error: Marker '# Private main website files' not found in the .gitignore."
exit 1
fi

start_line=$((start_line + 1))

awk "NR >= $start_line" "$(pwd)/.gitignore" | while read -r line; do
# Remove the leading slash from the path
relative_path="${line#/}"

# Full path to the file/directory in the temp directory
full_path="$temp_directory/$relative_path"
target_path="$(pwd)/$relative_path"

if [ -d "$full_path" ]; then
echo "Copying directory '$relative_path'..."
# Ensure the target directory exists
mkdir -p "$target_path"
# Copy the contents of the source directory to the target directory
cp -r "$full_path/" "$target_path/"
elif [ -f "$full_path" ]; then
echo "Copying file '$relative_path'..."
# Ensure the parent directory exists
mkdir -p "$(dirname "$target_path")"
# Copy the file
cp "$full_path" "$target_path"
else
echo "Warning: $full_path does not exist in the temp directory."
fi
done

echo "Done!"

#

echo "Cleaning up..."

rm -rf "$temp_directory"

echo "All done!"

0 comments on commit a3c391f

Please sign in to comment.