|
#!/bin/bash |
|
|
|
# Function to log operations |
|
log_operation() { |
|
echo "$(date '+%Y-%m-%d %H:%M:%S') - $1" |
|
} |
|
|
|
|
|
# Function to log operations |
|
log_operation() { |
|
echo "$(date '+%Y-%m-%d %H:%M:%S') - $1" |
|
} |
|
|
|
# Default Git configuration |
|
default_username="albertprofe" |
|
default_email="albert@gmail.com" |
|
|
|
log_operation "Starting repository setup script" |
|
|
|
# Ask user if they want to change the default Git configuration |
|
echo "Default Git username is '$default_username'. Do you want to change it? (y/n)" |
|
read change_username |
|
|
|
if [[ $change_username == "y" || $change_username == "Y" ]]; then |
|
echo "Enter your Git username:" |
|
read git_username |
|
log_operation "Git username changed to $git_username" |
|
else |
|
git_username=$default_username |
|
log_operation "Using default Git username: $git_username" |
|
fi |
|
|
|
echo "Default Git email is '$default_email'. Do you want to change it? (y/n)" |
|
read change_email |
|
|
|
if [[ $change_email == "y" || $change_email == "Y" ]]; then |
|
echo "Enter your Git email:" |
|
read git_email |
|
log_operation "Git email changed to $git_email" |
|
else |
|
git_email=$default_email |
|
log_operation "Using default Git email: $git_email" |
|
fi |
|
|
|
# Ask user for local/remote folder/repo name |
|
echo "Enter the name for your local and remote repository:" |
|
read repo_name |
|
log_operation "Repository name set to: $repo_name" |
|
|
|
# Create local directory and initialize git |
|
mkdir $repo_name |
|
cd $repo_name |
|
git init |
|
log_operation "Local directory created and Git initialized in $repo_name" |
|
|
|
# Set up user and email |
|
git config user.name "$git_username" |
|
git config user.email "$git_email" |
|
log_operation "Git user.name and user.email configured" |
|
|
|
# Create remote GitHub repository |
|
gh repo create $repo_name --public |
|
log_operation "Remote GitHub repository created: $repo_name" |
|
|
|
# Add remote origin |
|
remote_url="https://github.com/$git_username/$repo_name.git" |
|
git remote add origin $remote_url |
|
log_operation "Remote origin added: $remote_url" |
|
|
|
# Create initial files |
|
echo "Lorem ipsum dolor sit amet" > file1.txt |
|
echo "Lorem ipsum dolor sit amet" >> file2.txt |
|
echo "Lorem ipsum dolor sit amet" > file3.txt |
|
log_operation "Created initial files: file1.txt, file2.txt, file3.txt" |
|
|
|
# Commit and push initial files |
|
git add . |
|
git commit -m "Initial commit with three files" |
|
git push -u origin master |
|
log_operation "Initial files committed and pushed to master branch" |
|
|
|
# Create /data directory |
|
mkdir -p data |
|
log_operation "Created /data directory" |
|
|
|
# Create 3 more files in /data |
|
echo "Consectetur adipiscing elit" > data/file4.txt |
|
echo "Sed do eiusmod tempor incididunt" >> data/file5.txt |
|
echo "Ut labore et dolore magna aliqua" > data/file6.txt |
|
log_operation "Created additional files in /data: file4.txt, file5.txt, file6.txt" |
|
|
|
# Commit and push new files |
|
git add . |
|
git commit -m "Add three more files in /data directory" |
|
git push origin master |
|
log_operation "Additional files in /data committed and pushed to master branch" |
|
|
|
# Create and switch to a new branch named test-branch |
|
git checkout -b test-branch |
|
log_operation "Created and switched to new branch: test-branch" |
|
|
|
# Create 3 text files in test-branch |
|
echo "Test file 1 content" > test1.txt |
|
echo "Test file 2 content" > test2.txt |
|
echo "Test file 3 content" > test3.txt |
|
log_operation "Created 3 new text files in test-branch" |
|
|
|
# Commit and push the new files in test-branch |
|
git add . |
|
git commit -m "Add three test files in test-branch" |
|
git push origin test-branch |
|
log_operation "Committed and pushed 3 new files to test-branch" |
|
|
|
# Switch back to master branch |
|
git checkout master |
|
log_operation "Switched back to master branch" |
|
|
|
# Create 4 commits with additional content to all files |
|
for i in {1..4} |
|
do |
|
echo "New content for commit $i" >> file1.txt |
|
echo "New content for commit $i" >> file2.txt |
|
echo "New content for commit $i" >> file3.txt |
|
echo "New content for commit $i" >> data/file4.txt |
|
echo "New content for commit $i" >> data/file5.txt |
|
echo "New content for commit $i" >> data/file6.txt |
|
git add . |
|
git commit -m "Commit $i: Add new content to all files" |
|
log_operation "Created local commit $i with new content in all files" |
|
done |
|
|
|
echo "Repository setup and additional operations complete!" |
|
log_operation "Repository setup and additional operations completed successfully" |
|
|
|
# Ask user to press any key to exit |
|
read -n 1 -s -r -p "Press any key to exit..." |
|
echo "" |
|
log_operation "Script execution ended" |
How to revoke rights: login and logout