Add scripts for manipulating projects
authorOleg Broytman <phd@phdru.name>
Sun, 30 Apr 2017 12:15:39 +0000 (15:15 +0300)
committerOleg Broytman <phd@phdru.name>
Sun, 30 Apr 2017 12:15:39 +0000 (15:15 +0300)
Moved from git-scripts repo.

clone2current [new file with mode: 0755]
publish2web [new file with mode: 0755]
rename-project [new file with mode: 0755]

diff --git a/clone2current b/clone2current
new file mode 100755 (executable)
index 0000000..e79ec71
--- /dev/null
@@ -0,0 +1,38 @@
+#! /bin/sh
+
+if [ -z "$1" ]; then
+   echo "Usage: $0 repoistory [directories]" >&2
+   exit 1
+fi
+
+cd "$1" && source_dir="`pwd`" &&
+
+if [ ! -d ".git" ]; then
+   echo "$source_dir is not a repoistory (.git isn't found)" >&2
+   exit 1
+fi &&
+
+cd "$HOME"/current/projects &&
+directories="$2" &&
+if [ -n "$directories" ]; then
+   mkdir -p "$directories" && cd "$directories"
+fi &&
+
+dest_dir="`basename \"$source_dir\"`" &&
+git clone "$source_dir" "$dest_dir" &&
+
+cd "$dest_dir" &&
+pwd >> "`dirname \"$0\"`"/locate-all.list &&
+if [ "`cat \"$source_dir\"/.git/description`" = \
+   "Unnamed repository; edit this file 'description' to name the repository." ]
+then
+   `git var GIT_EDITOR` "$source_dir"/.git/description .git/description
+else
+   cp -p "$source_dir"/.git/description .git
+fi &&
+
+cd "$source_dir" &&
+if [ -n "$directories" ]; then
+   dest_dir="$directories/$dest_dir"
+fi &&
+exec git remote add current "$HOME"/current/projects/"$dest_dir"
diff --git a/publish2web b/publish2web
new file mode 100755 (executable)
index 0000000..9a74848
--- /dev/null
@@ -0,0 +1,53 @@
+#! /bin/sh
+
+if [ -z "$1" ]; then
+   echo "Usage: $0 repoistory [directories]" >&2
+   exit 1
+fi
+
+umask 022 &&
+cd "$1" && source_dir="`pwd`" &&
+
+if [ ! -d ".git" ]; then
+   echo "$source_dir is not a repoistory (.git isn't found)" >&2
+   exit 1
+fi &&
+
+cd "$HOME"/tmp &&
+dest_dir="`basename \"$source_dir\"`".git &&
+git clone --bare --config core.sharedRepository=0644 "$source_dir" "$dest_dir" &&
+
+cd "$dest_dir" &&
+git gc --aggressive &&
+git repack -a -d -f --depth=20 --window=250 &&
+git fsck --strict &&
+git config receive.updateserverinfo true && git update-server-info &&
+cp -p "$HOME"/Internet/WWW/htdocs/git.phdru.name/phdru.name/phdru.name.git/git-daemon-export-ok . &&
+if [ "`cat \"$source_dir\"/.git/description`" = \
+   "Unnamed repository; edit this file 'description' to name the repository." ]
+then
+   `git var GIT_EDITOR` "$source_dir"/.git/description description
+else
+   cp -p "$source_dir"/.git/description . && chmod a+r description
+fi &&
+if [ -f "$source_dir"/README.html ]; then
+   cp -p "$source_dir"/README.html . && chmod a+r README.html
+fi &&
+
+cd "$HOME"/Internet/WWW/htdocs/git.phdru.name &&
+directories="$2" &&
+if [ -n "$directories" ]; then
+   mkdir -p "$directories"
+fi &&
+
+cd "$HOME"/tmp &&
+mv "$dest_dir" "$HOME"/Internet/WWW/htdocs/git.phdru.name/"$directories" &&
+echo "$HOME"/Internet/WWW/htdocs/git.phdru.name/"$directories/$dest_dir" >> "`dirname \"$0\"`"/locate-all.list &&
+
+umask 077 &&
+cd "$source_dir" &&
+if [ -n "$directories" ]; then
+   dest_dir="$directories/$dest_dir"
+fi &&
+git remote add web "$HOME"/Internet/WWW/htdocs/git.phdru.name/"$dest_dir" &&
+exec git push --set-upstream web master
diff --git a/rename-project b/rename-project
new file mode 100755 (executable)
index 0000000..2eff036
--- /dev/null
@@ -0,0 +1,53 @@
+#! /bin/sh
+
+if [ -z "$2" -o -n "$3" ]; then
+   echo "Usage: $0 old_name new_name" >&2
+   exit 1
+fi
+
+old_name="$1"
+new_name="$2"
+
+fix_path() {
+   config_option="$1"
+   path="`git config --get $config_option`"
+   new_path="`echo \"$path\" | sed \"s@$old_name@$new_name@\"`"
+   git config "$config_option" "$new_path"
+}
+
+fix_files() {
+   replace "$old_name" "$new_name" "$@"
+}
+
+for project_dir in "$HOME"/prog/Python "$HOME"/current/projects \
+      "$HOME"/Internet/WWW/htdocs/git.phdru.name; do
+   cd "$project_dir" &&
+   if [ -d "$old_name" ]; then
+      mv "$old_name" "$new_name" &&
+      cd "$new_name"
+   elif [ -d "$old_name.git" ]; then
+      mv "$old_name".git "$new_name".git &&
+      cd "$new_name".git
+   else
+      continue
+   fi
+   for remote in `git remote`; do
+      fix_path "remote.$remote.url"
+   done
+   path="`git config --get --path htdocs.path`"
+   if [ -n "$path" ]; then
+      (
+         cd /home/phd/Internet/WWW/htdocs/phdru.name/Software/Python/ &&
+         if [ -d "$old_name" ]; then
+            mv "$old_name" "$new_name" &&
+            cd "$new_name" &&
+            mv "$old_name"-*.tar.bz2 "$new_name".tar.bz2 &&
+            fix_files index.tmpl
+         fi
+      ) &&
+      fix_path htdocs.path
+   fi
+   fix_files devscripts/README.html \
+      docs/conf.py docs/genapidocs docs/index.rst docs/install.rst \
+      README.txt mk-distr setup.py tox.ini
+done