File: install-plugins.sh

package info (click to toggle)
librime 1.13.1%2Bdfsg1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 7,896 kB
  • sloc: cpp: 34,796; ansic: 2,519; javascript: 443; sh: 225; makefile: 125
file content (50 lines) | stat: -rwxr-xr-x 1,276 bytes parent folder | download | duplicates (2)
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
#!/bin/bash

set -e

cd "$(dirname "$0")"

clone_options=(
    # for GitHub pull request #1, git checkout 1/merge
    --config 'remote.origin.fetch=+refs/pull/*:refs/remotes/origin/*'
    # shallow clone
    --depth 1
    # fetch all branches
    --no-single-branch
)

if [[ "${1}" =~ run=.* ]]; then
    custom_install="${1#run=}"
    shift
fi

for plugin in "$@"
do
    if [[ "${plugin}" =~ @ ]]; then
        slug="${plugin%@*}"
        branch="${plugin#*@}"
    else
        slug="${plugin}"
        branch=''
    fi
    plugin_project="${slug##*/}"
    plugin_dir="plugins/${plugin_project#librime-}"
    if [[ -d "${plugin_dir}" ]]
    then
        echo "Updating ${plugin} in ${plugin_dir}"
        if [[ -n "${branch}" ]]; then
            git -C "${plugin_dir}" checkout "${branch}"
        fi
        git -C "${plugin_dir}" pull
    else
        echo "Checking out ${plugin} to ${plugin_dir}"
        git clone "${clone_options[@]}" "https://github.com/${slug}.git" "${plugin_dir}"
        # pull request ref doesn't work with git clone --branch
        if [[ -n "${branch}" ]]; then
            git -C "${plugin_dir}" checkout "${branch}"
        fi
    fi
    if [[ -n "${custom_install}" ]]; then
        ${custom_install} "${plugin}" "${plugin_dir}"
    fi
done