Created
July 16, 2012 21:51
-
-
Save Sliim/3125321 to your computer and use it in GitHub Desktop.
Just a script to manage github repositories
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
## | |
# This program is free software: you can redistribute it and/or modify | |
# it under the terms of the GNU General Public License as published by | |
# the Free Software Foundation, either version 3 of the License, or | |
# (at your option) any later version. | |
# | |
# This program is distributed in the hope that it will be useful, | |
# but WITHOUT ANY WARRANTY; without even the implied warranty of | |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
# GNU General Public License for more details. | |
# | |
# You should have received a copy of the GNU General Public License | |
# along with this program. If not, see <http://www.gnu.org/licenses/>. | |
## | |
# Author: Sliim <sliim@mailoo.org> | |
## | |
REPOSITORY_DIR=/opt/ | |
GITHUB_URL=https://github.com/ | |
PWD=`pwd` | |
function usage { | |
echo "Usage: $0 <command> [[options] *]" | |
echo "Available commands:" | |
echo -e "\t- install <github_uri> <dest_name>" | |
echo -e "\t- update <repository>" | |
echo -e "\t- update-all" | |
echo -e "\t- status <repository>" | |
echo -e "\t- status-all" | |
cd $PWD | |
exit 1 | |
} | |
function install { | |
if [ $# -eq 2 ]; then | |
git clone $GITHUB_URL$2.git | |
elif [ $# -eq 3 ]; then | |
git clone $GITHUB_URL$2.git $3 | |
else | |
usage | |
fi | |
} | |
function update { | |
if [ $# -ne 1 ]; then | |
usage | |
elif [ ! -d $REPOSITORY_DIR$1 ]; then | |
echo >&2 "Repository not found: $REPOSITORY_DIR$1" | |
fi | |
echo "Updating $1..." | |
cd $REPOSITORY_DIR$1 | |
git pull | |
cd $REPOSITORY_DIR | |
} | |
function update_all { | |
dir=( ${REPOSITORY_DIR}* ) | |
for ((i=0;i<${#dir[*]};i++)) | |
do | |
d=${dir[$i]} | |
if test -d "$d/.git"; then | |
update ${d:5} | |
fi | |
done | |
} | |
function status { | |
if [ $# -ne 1 ]; then | |
usage | |
elif [ ! -d $REPOSITORY_DIR$1 ]; then | |
echo >&2 "Repository not found: $REPOSITORY_DIR$1" | |
fi | |
echo "=================================" | |
echo "=====]> $1 Status:" | |
echo "=================================" | |
cd $REPOSITORY_DIR$1 | |
git status -sb | |
cd $REPOSITORY_DIR | |
} | |
function status_all { | |
dir=( ${REPOSITORY_DIR}* ) | |
for ((i=0;i<${#dir[*]};i++)) | |
do | |
d=${dir[$i]} | |
if test -d "$d/.git"; then | |
status ${d:5} | |
fi | |
done | |
} | |
if [ $# -gt 0 ]; then | |
cd $REPOSITORY_DIR | |
case $1 in | |
"install") install $@ ;; | |
"update") update $2 ;; | |
"update-all") update_all ;; | |
"status") status $2 ;; | |
"status-all") status_all ;; | |
*) usage ;; | |
esac | |
cd $PWD | |
exit 0 | |
fi | |
usage |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment