Created
June 11, 2015 20:09
-
-
Save pschichtel/271cabe5c33c426ab527 to your computer and use it in GitHub Desktop.
This bash script fixes up the repositories in gitlab after restoring a backup in a new gitlab instance
This file contains hidden or 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 | |
gitlab_user="git" | |
if [[ "$(whoami)" == "$gitlab_user" ]] | |
then | |
echo "Searching for errors and corecting them" | |
else | |
echo "Nope, wrong user. Trying to login as $gitlab_user" | |
su "$gitlab_user" -c "$0" | |
exit $? | |
fi | |
echo "Correcting broken hook symlinks" | |
# | |
# Correct broken hook symlinks | |
### | |
old_target="/home/git/gitlab-shell/hooks" | |
new_target="/opt/gitlab/embedded/service/gitlab-shell/hooks" | |
while read -r link | |
do | |
target=$(readlink $link) | |
echo "$link -> $target" | |
if [[ "$target" == "$old_target" ]] | |
then | |
ln -sfnv "$new_target" "$link" | |
fi | |
done < <(find /var/opt/gitlab/git-data/repositories -type l -name hooks) | |
clear | |
echo "Removing backup origins from the repositories" | |
# | |
# Remove origins | |
### | |
while read -r config | |
do | |
if grep -iP "\[remote \"origin\"\]" "$config" | |
then | |
tmp="$(mktemp)" | |
head -n -2 "$config" > "$tmp" | |
mv "$tmp" "$config" | |
fi | |
done < <(find /var/opt/gitlab/git-data/repositories -type f -name config) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment