/
init_repo.sh
143 lines (107 loc) · 3.92 KB
/
init_repo.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
#!/bin/bash
# This script initializes the Export Layers git repository.
orig_cwd="$(pwd)"
# Install required programs/packages
# If supported package managers are not available (apt-get), developer has to
# install missing packages manually.
function command_exists()
{
command -v "$1" > /dev/null 2>&1
return $?
}
if command_exists 'apt-get'; then
required_packages='git
ruby
ruby-dev
build-essential
patch
zlib1g-dev
liblzma-dev
libgmp-dev
libffi-dev
gcc
python
python-pip
gimp'
sudo apt-get install -y $required_packages
else
required_packages='git
ruby
python27
python-pip
gimp'
echo 'Make sure the following packages are installed:'
echo "$required_packages"
echo ''
echo -n "If you have all required packages installed, press 'y', otherwise press any key to terminate the script and install the packages manually: "
read -n 1 key_pressed
echo ''
if [ "${key_pressed,,}" != 'y' ]; then
echo "Terminating script. Please install packages listed above before running the script." 1>&2
exit 1
fi
fi
# Installation of Ruby and Python packages
sudo gem install bundler
python_modules='pathspec
pathlib
requests
simplejson
mock
parameterized
psutil
pyyaml
GitPython'
sudo pip install $python_modules
# GIMP initialization
gimp_version_major_minor="$(gimp --version | sed 's/.*version \([0-9][0-9]*.[0-9][0-9]*\).*$/\1/')"
if [ "$gimp_version_major_minor" = "2.8" ]; then
gimp_local_dirpath="$HOME"'/.gimp-2.8'
elif [[ ! "$gimp_version_major_minor" < "2.9" ]]; then
gimp_local_dirpath="$HOME"'/.config/GIMP/'"$gimp_version_major_minor"
else
echo "Unsupported version of GIMP ($gimp_version_major_minor). Please install GIMP version 2.8 or later."
exit 1
fi
plugin_main_repo_dirname='plug-ins - Export Layers'
plugin_page_branch_name='gh-pages'
repo_url='https://github.com/kamilburda/gimp-export-layers.git'
repo_dirpath="$gimp_local_dirpath"'/'"$plugin_main_repo_dirname"
gimprc_filename='gimprc'
gimprc_filepath="$gimp_local_dirpath"'/'"$gimprc_filename"
system_gimprc_filepath='/etc/gimp/2.0/gimprc'
if [ ! -f "$gimprc_filepath" ]; then
echo "$gimprc_filename"' does not exist, running GIMP...'
gimp --no-interface --new-instance --batch-interpreter='python-fu-eval' --batch 'pdb.gimp_quit(0)'
fi
if [ ! -f "$gimprc_filepath" ]; then
echo "$gimprc_filename"' still does not exist, creating new file'
plugin_dirpaths_from_system_gimprc="$(grep -oE '\(plug-in-path ".*"\)' "$system_gimprc_filepath" | sed -r 's/\(plug-in-path "(.*)"\)/\1/')"
echo 'Adding repository path to the list of plug-in directories in '"$gimprc_filename"
echo '(plug-in-path "'"$plugin_dirpaths_from_system_gimprc"':'"$repo_dirpath"'")' > "$gimprc_filepath"
else
repo_dirpath_in_gimprc="$(grep -oE '\(plug-in-path ".*'"$repo_dirpath"'"\)' "$gimprc_filepath")"
if [ ! "$repo_dirpath_in_gimprc" ]; then
echo 'Adding repository path to the list of plug-in directories in '"$gimprc_filename"
sed -i -r -e 's:(\(plug-in-path ".*)("\)):\1\:'"$repo_dirpath"'\2:' "$gimprc_filepath"
fi
fi
# Repository initialization
echo 'Cloning main branch of '"$repo_url"' into '\'"$repo_dirpath"\'
git clone --recurse-submodules -- "$repo_url" "$repo_dirpath"
cd "$repo_dirpath"
echo 'Setting up git hooks'
ln -s 'git_hooks/commit_msg.py' '.git/hooks/commit-msg'
ln -s 'git_hooks/pre_commit.py' '.git/hooks/pre-commit'
echo 'Enabling core.autocrlf in git config'
git config --local 'core.autocrlf' 'true'
cd 'docs'
echo 'Cloning '"$plugin_page_branch_name"' branch of '"$repo_url"' into '\'"$repo_dirpath"'/docs/'"$plugin_page_branch_name"\'
git clone --branch "$plugin_page_branch_name" -- "$repo_url" "$plugin_page_branch_name"
cd "$plugin_page_branch_name"
echo 'Setting up git hooks for branch '"$plugin_page_branch_name"
ln -s "$repo_dirpath"'/git_hooks/commit_msg.py' '.git/hooks/commit-msg'
echo 'Enabling core.autocrlf in git config for branch '"$plugin_page_branch_name"
git config --local 'core.autocrlf' 'true'
bundle install
cd "$orig_cwd"