summarylogtreecommitdiffstats
path: root/hysteria.install
blob: ee08d7d7a30ce657ba1f84bf47538099063ae40c (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
_hysteria_user="hysteria"
_hysteria_homedir="/var/lib/hysteria"

has_command() {
  local _command=$1
  type -P "$_command" > /dev/null 2>&1
}
tput() {
  if has_command tput; then
    command tput "$@"
  fi
}
all_off="$(tput sgr0)"
bold="${all_off}$(tput bold)"
red="${bold}$(tput setaf 1)"
blue="${bold}$(tput setaf 4)"
yellow="${bold}$(tput setaf 3)"
note() {
    printf "${blue}==>${yellow} NOTE:${bold} $1${all_off}\n"
}
warn() {
    printf "${blue}==>${red} WARN:${bold} $1${all_off}\n"
}

has_prefix() {
    local _s="$1"
    local _prefix="$2"

    if [[ -z "$_prefix" ]]; then
        return 0
    fi

    if [[ -z "$_s" ]]; then
        return 1
    fi

    [[ "x$_s" != "x${_s#"$_prefix"}" ]]
}

_hysteria_ensure_usermod() {
  local _origin_homedir=$(eval echo ~"$_hysteria_user")
  # in the old version, homedir is not specified in the sysusers.conf
  # and therefore set to / by default.
  if [[ "$_origin_homedir" == "/" ]]; then
    usermod -d "$_hysteria_homedir" "$_hysteria_user"
    note "The homedir of user $_hysteria_user has been changed from $_origin_homedir to $_hysteria_homedir"
  fi
}

_hysteria_incompatible_upgrade_warning() {
  note "Hysteria is upgraded to the Hysteria 2."
  warn "Hysteria 2 uses a completely redesigned protocol & config, which is NOT compatible with the version 1.x.x in any way."
  warn "If you do not intend to migrate to Hysteria 2, please downgrade this package to version 1.3.5."
  warn "Alternatively, there is also a \"hysteria${red}1${bold}\" and \"hysteria${red}1${bold}-bin\" package in the AUR, which provides the final version of Hysteria v1 and can be installed side by side with this package."
}

post_install() {
  _hysteria_ensure_usermod
}

post_upgrade() {
  local _new_version="$1"
  local _old_version="$2"

  post_install

  if has_prefix "$_new_version" "2." && has_prefix "$_old_version" "1."; then
    _hysteria_incompatible_upgrade_warning
  fi
}