aboutsummaryrefslogtreecommitdiff
path: root/scripts/installer.sh
blob: de89e5789ecca1c91b96c7d30ec52a383916e63b (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
#!/bin/sh
# gsocial-cli -- installer.sh
# A simple script to install/uninstall/upgrade gsocial-cli systemwide
# This script is part of the gsocial-cli project
# Author: ziggys
# License: The Drunken BEER License v 1.1 (https://git.p4g.club/git/beer/about)

# scriptinfo
SCRIPTNAME="${0##*/}"
SCRIPTNAME="${SCRIPTNAME%%.sh}"
VERSION="0.6.0"      # Show command: shows configuration, accounts and history
AUTHOR="ziggys"
LICENSE="The Drunken BEER License v 1.1 (https://git.p4g.club/git/beer/about)"

# usage
usage () {
test $# = 0 || printf "%s %s\\n" "${SCRIPTNAME}" "$@"
cat << EOF | fold -s
${PSCRIPT%%.sh}-${SCRIPTNAME} version ${VERSION}
  by ${AUTHOR}
  License: ${LICENSE}

gsocial-cli-${SCRIPTNAME} 
  is a simple script to install/uninstall gsocial-cli systemwide
 
Usage:   ${SCRIPTNAME} [option] <args>
   or:   ${SCRIPTNAME} -h

Options
   -p, --prefix   <PATH>     Install gsocial-cli in PATH (e.g. '/usr/bin/')
   -u, --uninstall           Uninstall gsocial-cli from where it's installed
   -h   HELP                 Print this help and exit


WARNING:
This script is part of the gsocial-cli project and its intended to be
executed only for gsocial-cli installation purposes. Please, refer to
gsocial-cli repositories to learn about this script and its parent project.

Website:
Oficial: https://git.p4g.club/git/gsocial-cli
Mirror: https://gitgud.io/ziggys/gsocial-cli

EOF
exit 0
}

# install
install () {
  PWD="$(pwd)"
  PPWD="${PWD%%/scripts}"
  test "${PPWD}" != "${PWD}" && cd ..
  ISX="$(find "${PSCRIPT}" -perm /a=x)"
  test -z "${ISX}" && chmod +x "${PSCRIPT}"
  sudo cp "${PSCRIPT}" "${PREFIX}${PSCRIPT%%.sh}"
  WHERE="$(which gsocial-cli)"
  test ! -z "${WHERE}" && printf "\\e%sDone!\\n" "${good_c}"
  exit 0
}

# uninstall
uninstall () {
  test -f "${PREFIX}" && sudo rm -f "${PREFIX}"
  WHERE="$(which gsocial-cli)"
  test -z "${WHERE}" && printf "\\e%sDone!\\n" "${good_c}"
  exit 0
}

# colors for stdout
good_c="[0;32m"
warn_c="[0;33m"
diee_c="[0;31m"
info_c="[1;30m"

# read options from commandline
PSCRIPT="gsocial-cli.sh"
ACTION="$1"

test -z "${ACTION}" && usage "$@"
case "${ACTION}" in
  "-p" | "--prefix" )
    PREFIX="$2" ;
    printf "\\e%sgsocial-cli-%s\\e[0m v%s\\n\\n" \
      "${good_c}" "${SCRIPTNAME}" "${VERSION}"
    printf "Installing \\e%s%s\\e[0m in \\e%s%s\\n\\e[0m" \
      "${good_c}" "${PSCRIPT%%.sh}" "${good_c}" "${PREFIX}"
    install
    ;;

  "-u" | "--uninstall" )
    PREFIX="$(which gsocial-cli)"
    printf "\\e%sgsocial-cli-%s\\e[0m v%s\\n\\n" \
      "${good_c}" "${SCRIPTNAME}" "${VERSION}"

    test -z "${PREFIX}" \
      && printf "\\e%sfatal: \\e%s%s\\e%s is not installed\\e[0m\\n" \
        "${diee_c}" "${warn_c}" "${PSCRIPT%%.sh}" "${info_c}" \
      && exit 0

    printf "Uninstalling \\e%s%s\\e[0m from \\e%s%s\\n\\e[0m" \
        "${good_c}" "${PSCRIPT%%.sh}" "${good_c}" "${PREFIX}"
    uninstall
    ;;
  
  "-h" | "--help" ) usage "$@" ;;
esac

exit 0