summaryrefslogtreecommitdiff
path: root/bin/linux-sh-installer
blob: 59bdf8d0b030b5fc729e2db6f0da201d01ee5bae (plain)
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
#!/bin/bash

# This is a self-extracting archive that installs Ink/Stitch on your Linux
# system.  This first part is an installer, and after that is a .tar.zx file
# containing Ink/Stitch itself.
#
# To install, simply run this script:
#
#   sh inkstitch-<version>.sh
#
#
# EXPERT STUFF BELOW:
#
# If you'd rather install it yourself, run this script with --extract to
# produce the original inkstitch-<version>.tar.xz file in the current
# directory.
#
# This script will attempt to determine where to install Inkscape user
# extensions automatically.  If it gets it wrong, you can set one of these
# environment variables:
#
#   INKSCAPE_PATH (ex: /usr/bin/inkscape)
#     The path to the inkscape executable program.  This script will ask that program 
#     where to install extensions by passing it the --user-data-directory argument.
#
#   INKSCAPE_EXTENSIONS_PATH (ex: $HOME/.config/inkscape/extensions)
#     The path to the inkscape extensions directory.  Use this to bypass the
#     --user-data-directory method and specify a directory yourself.

die() {
  echo "$*"
  exit 1
}

extract() {
  ( grep -m1 '^__ARCHIVE__$' > /dev/null; cat ) < "$0"
}

find_inkscape() {
  # allow expert user override
  if [ -n "$INKSCAPE_PATH" ]; then
    echo "$INKSCAPE_PATH"
    return
  fi

  inkscape="$(which inkscape)"

  if [ -z "$inkscape" ]; then
    read -p "Please enter the path to the inkscape program executable (example: /usr/bin/inkscape): " inkscape
  fi

  if [ ! -x "$inkscape" ]; then
    die "Inkscape not found or not executable ($inkscape)"
  fi

  echo "$inkscape"
}

find_extensions_dir() {
  # allow expert user override
  if [ -n "$INKSCAPE_EXTENSIONS_PATH" ]; then
    echo "$INKSCAPE_EXTENSIONS_PATH"
    return
  fi

  inkscape="$(find_inkscape)"

  if [ -x "$inkscape" ]; then
    extensions_dir="$(inkscape --user-data-directory)/extensions"
  fi

  if [ -z "$extensions_dir" ]; then
    read -p "Please enter the inkscape user extensions directory (example: $HOME/.config/inkscape/extensions): " extensions_dir
  fi

  if [ -z "$extensions_dir" ]; then
    die "Aborting."
  fi

  mkdir -p "$extensions_dir" || die "unable to create $extensions_dir"

  echo "$extensions_dir"
}

remove_existing() {
  if [ -e "${1}/inkstitch" ]; then
    read -p "${1}/inkstitch exists already.  It must be removed in order to install $(basename ${0%.sh}).  Delete? [y/N] " yesno
    if [ "$yesno" != "y" -a "$yesno" != "Y" -a "$yesno" != "yes" ]; then
      die "Aborting."
    fi

    rm -rf "${1}/inkstitch"
  fi
}

install_inkstitch() {
  extensions_dir="$(find_extensions_dir)"
  echo "Installing Ink/Stitch to ${extensions_dir}/inkstitch"

  remove_existing "$extensions_dir"

  extract | tar -C "$extensions_dir" -Jxf - || die "error while extracting Ink/Stitch"

  echo "Ink/Stitch has been successfully installed.  Please restart Inkscape if it is already running."
}

if [ "$1" = "--extract" ]; then
  dest="${0%.sh}.tar.xz"
  extract > "$dest"
  echo "Ink/Stitch extracted to $dest"
else
  install_inkstitch
fi

exit 0

__ARCHIVE__