From ce01edc044b457043c79404ab861bf5a767dce96 Mon Sep 17 00:00:00 2001 From: azmandios Date: Wed, 15 Sep 2021 12:57:02 +0300 Subject: [PATCH] ADD updgit.sh --- README.MD | 4 ++ .../{alias fedora root => fedora_alias_root} | 0 alias/ubuntu_alias_root | 18 ++++++ scripts/updgit.sh | 55 +++++++++++++++++++ .../fedora_webdev_workspace.sh | 0 5 files changed, 77 insertions(+) create mode 100644 README.MD rename alias/{alias fedora root => fedora_alias_root} (100%) create mode 100644 alias/ubuntu_alias_root create mode 100644 scripts/updgit.sh rename webdev_workspace.sh => workspace_install/fedora_webdev_workspace.sh (100%) mode change 100755 => 100644 diff --git a/README.MD b/README.MD new file mode 100644 index 0000000..731218c --- /dev/null +++ b/README.MD @@ -0,0 +1,4 @@ +# Скрипты для настройки Linux окружения + +## Скрипты +`updgit` -- рекурсивное обновление git репозиториев в папке до актуальных коммитов \ No newline at end of file diff --git a/alias/alias fedora root b/alias/fedora_alias_root similarity index 100% rename from alias/alias fedora root rename to alias/fedora_alias_root diff --git a/alias/ubuntu_alias_root b/alias/ubuntu_alias_root new file mode 100644 index 0000000..c0cf932 --- /dev/null +++ b/alias/ubuntu_alias_root @@ -0,0 +1,18 @@ +alias upd='apt update -y && apt upgrade -y && snap refresh --list' +alias c='clear' +alias ai='apt install $args -y' +alias rm='rm -i' +alias cp='cp -i' +alias mv='mv -i' +alias ls='ls --color=auto' +alias cd..='cd ..' +alias ..='cd ..' +alias ...='cd ../../../' +alias grep='grep --color=auto' +alias egrep='egrep --color=auto' +alias fgrep='fgrep --color=auto' +alias mkdir='mkdir -pv' +alias diff='colordiff' +alias ports='netstat -tulanp' +alias header='curl -I' +alias wget='wget -c' diff --git a/scripts/updgit.sh b/scripts/updgit.sh new file mode 100644 index 0000000..f6a93c7 --- /dev/null +++ b/scripts/updgit.sh @@ -0,0 +1,55 @@ +#!/bin/bash +# Usage: +# ./update_git_repos.sh [parent_directory] +# example usage: +# ./update_git_repos.sh C:/GitProjects/ [MAKE SURE YOU USE / SLASHES] + +updateRepo() { + local dir="$1" + local original_dir="$2" + cd $dir # switch to the git repo + repo_url=$(git config --get remote.origin.url) + + echo "****************************************************************************" + echo "Updating Repo: $dir with url: $repo_url" + echo "Starting update in $PWD" + + main_branch="master" + if [ "$repo_url" == "git@someserver:repo/repo.git" ]; then # if you have a repo where the primary branch isnt master + $main_branch="trunk" + fi + + # update the repo, then stash any local changes + echo -e "\ncalling: git fetch --all && git stash" + (git fetch --all && git stash) + current_branch=$(git rev-parse --abbrev-ref HEAD) + + # switch to master/trunk branch and rebase it, then switch back to original branch + if [ $current_branch != $main_branch ]; then + echo -e "\ncalling: git checkout $main_branch && git rebase && git checkout $current_branch" + (git checkout $main_branch && git rebase && git checkout $current_branch) + fi + + # rebase the original branch and then stash pop back to original state + echo -e "\ncalling: git rebase && git stash pop on branch: $current_branch" + (git rebase && git stash pop ) + + #switch back to the starting directory + cd $original_dir + echo "" +} + +directory_to_update=${1} + +if [ -z "$directory_to_update" ] ; then + echo "no directory passed in, using current directory" + directory_to_update=$PWD +fi +echo "Updating git repo's in directory: $directory_to_update" +count=0 +for dir in $(find $directory_to_update -maxdepth 4 -type d -name .git | xargs -n 1 dirname); do + updateRepo $dir $directory_to_update #& #uncomment to make it run in multiple threads, meh + ((count+=1)) +done + +echo "$count local git repos have been updated!" \ No newline at end of file diff --git a/webdev_workspace.sh b/workspace_install/fedora_webdev_workspace.sh old mode 100755 new mode 100644 similarity index 100% rename from webdev_workspace.sh rename to workspace_install/fedora_webdev_workspace.sh