make_inkscape 5.08 KB
Newer Older
Maren Hachmann's avatar
Maren Hachmann committed
1 2
#!/bin/bash

3
# Copyright (c) 2017-2018 Maren Hachmann
4
#
Maren Hachmann's avatar
Maren Hachmann committed
5 6 7 8 9 10
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
11
#
Maren Hachmann's avatar
Maren Hachmann committed
12 13
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
14
#
Maren Hachmann's avatar
Maren Hachmann committed
15 16 17 18 19 20 21 22 23 24
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.

# -------------------

25 26 27 28 29 30 31 32 33 34
# Determine the real location of the script (this is for running via symlink)
SCRIPT_PATH="${BASH_SOURCE[0]}"
while [ -h "$SCRIPT_PATH" ]; do
  # resolve $SCRIPT_PATH until the file is no longer a symlink
  SCRIPT_DIR="$( cd -P "$( dirname "$SCRIPT_PATH" )" >/dev/null && pwd )"
  SCRIPT_PATH="$(readlink "$SCRIPT_PATH")"
  # if $SCRIPT_DIR was a relative symlink, we need to resolve it relative to the path where the symlink file was located
  [[ $SCRIPT_PATH != /* ]] && SCRIPT_DIR="$SCRIPT_DIR/$SCRIPT_PATH"
done
SCRIPT_DIR="$( cd -P "$( dirname "$SCRIPT_PATH" )" >/dev/null && pwd )"
Maren Hachmann's avatar
Maren Hachmann committed
35

36 37
# import settings
source $SCRIPT_DIR/make_ink_config
Maren Hachmann's avatar
Maren Hachmann committed
38

39 40
# Needed for version numbers and unique directories
DATE=$(date +%Y.%m.%d.%H.%M.%S)
41

42
MARKER="-->"
43

Maren Hachmann's avatar
Maren Hachmann committed
44 45 46 47 48 49 50 51 52 53
# Get into correct directory
cd $SOURCE_DIR

# don't update everything just yet, to not mess up revision numbers for later comparison
git fetch

# select correct branch
if [ $# -eq 0 ]
  then
    BRANCH="master"
54
elif [ $# -gt 0 ]
Maren Hachmann's avatar
Maren Hachmann committed
55 56 57 58
  then
    BRANCH=$1;
    if [ ! "`git branch --list -r origin/${BRANCH} `" ]
      then
59
        echo "Sorry, the selected branch $BRANCH doesn't exist in the remote repository. Please select a different branch."
Maren Hachmann's avatar
Maren Hachmann committed
60 61
        exit 1;
    fi
62 63 64 65 66 67 68
    if [ $# -eq 2 ]
      then
        if [ $2 = '-f' ]
          then
            FORCE=1
        fi
    fi
Maren Hachmann's avatar
Maren Hachmann committed
69
else
Maren Hachmann's avatar
Maren Hachmann committed
70
  echo "Too many arguments. This program takes either the name of a branch and an optional -f, or no argument to default to the master branch.";
Maren Hachmann's avatar
Maren Hachmann committed
71 72 73
  exit 1;
fi

74
echo "$MARKER Branch $BRANCH selected."
Maren Hachmann's avatar
Maren Hachmann committed
75

76 77 78
# This would be the safer way to do it, only doesn't work on Ubuntu 16.04
# with git 2.7.4...:
# git submodule deinit --all
Maren Hachmann's avatar
Maren Hachmann committed
79

80 81
# yeah...this is what git suggests to get rid of the submodule:
rm -r -f share/extensions
Maren Hachmann's avatar
Maren Hachmann committed
82

83 84 85
# cleanup, so there won't be anything to commit, causing git to refuse switching branches
git checkout -- .
git clean -d -f
Maren Hachmann's avatar
Maren Hachmann committed
86

Maren Hachmann's avatar
Maren Hachmann committed
87 88 89 90
# get into correct branch
git checkout $BRANCH;

# check if there are new commits
91 92 93
REVISION_OLD=$(git log -1 --format="%h")
git pull
git submodule update --init --recursive
Maren Hachmann's avatar
Maren Hachmann committed
94 95 96

REVISION=$(git log -1 --format="%h")

97 98
$INSTALL_DIR=$INSTALL_TO/inkscape_$BRANCH

Maren Hachmann's avatar
Maren Hachmann committed
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
if [ ! -f "$INSTALL_DIR/bin/inkscape" ] || [ ! -f "$SOURCE_DIR/build/bin/inkscape" ] || [ ! "$REVISION" == "$REVISION_OLD" ]; then
    echo "$MARKER Update in progress..."
else
    echo "$MARKER No update needed! Your installation is already up-to-date."
    exit 0
fi

# Collect info about this version

REMOTE=$(git remote get-url origin)

# Delete any previous builds, if they exist
echo "$MARKER Removing old build directory..."
rm -rf build
mkdir build
cd build

# Build
echo "$MARKER Configuring and compiling..."
cmake -DCMAKE_INSTALL_PREFIX=$INSTALL_DIR ..
make -j3

# Create description file
echo "Inkscape Development version as of $DATE, revision $REVISION" > description-pak

# Create directory where to save the package
125 126
PACKAGE_DIR=$SAVE_DEBS_TO/$BRANCH_$DATE
mkdir -p $PACKAGE_DIR
Maren Hachmann's avatar
Maren Hachmann committed
127 128 129

# Build the .deb package
echo "$MARKER Building Debian package..."
130
checkinstall -y -D --fstrans=yes --install=no --pkgname inkscape-$BRANCH --pkgversion $DATE$REVISION --nodoc --maintainer "$USER" --arch amd64 --pakdir $PACKAGE_DIR --pkgsource "$REMOTE" --exclude="$SOURCE_DIR/.git"
Maren Hachmann's avatar
Maren Hachmann committed
131 132

# Create user configuration directory, if doesn't exist
133 134
PROFILE_DIR=$SAVE_PROFILES_TO/inkscape_$BRANCH

Maren Hachmann's avatar
Maren Hachmann committed
135 136 137 138 139
mkdir -p $PROFILE_DIR

# Install new package
echo "$MARKER Installing new version..."
notify-send 'Build Completed!' 'Please enter your password to install.' --icon=dialog-information
140
sudo dpkg -i $PACKAGE_DIR/inkscape-*.deb
Maren Hachmann's avatar
Maren Hachmann committed
141 142 143

INK_PROG="$INSTALL_DIR/bin/inkscape"
INK_DIR="$INSTALL_DIR/bin"
144
STARTER_FILE=$STARTER_FILE_PATH/Run_Ink_$BRANCH
Maren Hachmann's avatar
Maren Hachmann committed
145 146 147 148

# Create start script
echo "#!/bin/bash

149
export INKSCAPE_PROFILE_DIR="$PROFILE_DIR";PATH=$INK_DIR:\$PATH;$INK_PROG" > $STARTER_FILE
Maren Hachmann's avatar
Maren Hachmann committed
150 151 152 153 154 155 156 157 158 159

# Make start script executable
chmod +x $STARTER_FILE

echo "Start your Inkscape installation by executing

$STARTER_FILE

The .deb package that has been built is available in

160
$SAVE_DEBS_TO"
Maren Hachmann's avatar
Maren Hachmann committed
161 162

notify-send 'Package installed!' 'Enjoy running your new Inkscape build!' --icon=dialog-information