aboutsummarylogtreecommitdiffstats
path: root/haur
blob: e023d661547a27f3bf5510b71cb2df55433ab8ce (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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
#!/usr/bin/env bash

if [ -f "$HOME"/.config/haurrc ]; then
  # shellcheck source=src/.config/haurrc
  source "$HOME"/.config/haurrc
else
  if [ -f /etc/haurrc ]; then
    source /etc/haurrc
  else
    echo "fatal: No configuration file found"
    exit 1
  fi
fi

if [ ! $HAUR_NO_COLORS == "y" ]; then
  if test -t 1; then

    # see if it supports colors...
    ncolors=$(tput colors 2>/dev/null)

    if test -n "$ncolors" && test $ncolors -ge 8; then
      # bold="$(tput bold 2>/dev/null)"
      # underline="$(tput smul 2>/dev/null)"
      # standout="$(tput smso 2>/dev/null)"
      normal="$(tput sgr0 2>/dev/null)"
      # black="$(tput setaf 0 2>/dev/null)"
      red="$(tput setaf 1 2>/dev/null)"
      # green="$(tput setaf 2 2>/dev/null)"
      # yellow="$(tput setaf 3 2>/dev/null)"
      blue="$(tput setaf 4 2>/dev/null)"
      # magenta="$(tput setaf 5 2>/dev/null)"
      # cyan="$(tput setaf 6 2>/dev/null)"
      # white="$(tput setaf 7 2>/dev/null)"
    fi
  fi
fi

REMOVE=false
CLEAR_CACHE=false
UPDATE=false

for arg in "$@"; do
  shift
  case "$arg" in
    "--update") set -- "$@" "-u" ;;
    "--remove") set -- "$@" "-r" ;;
    "--clear-cache") set -- "$@" "-c" ;;
    "--help") set -- "$@" "-h" ;;
    "--"*) echo "Invalid Option: ${arg}" ; exit 1 ;;
    *) set -- "$@" "$arg"
  esac
done
shift $((OPTIND -1))

while getopts ":urch" opt; do
  case $opt in
    u )
      UPDATE=true
      ;;
    r )
      REMOVE=true
      ;;
    c )
      CLEAR_CACHE=true
      ;;
    h )
      echo "Usage: haur [--remove | -r] | [--clear-cache | -c] [--update | -u] <package names>"
      exit 0
      ;;
    \?)
      echo "${red}Invalid Option: -$OPTARG${normal}" 1>&2
      exit 1
      ;;
    esac
done
shift $((OPTIND -1))

if [ $HAUR_ALWAYS_CLEAR_CACHE == "y" ]; then
  CLEAR_CACHE=true
fi

if [ $REMOVE == true ]; then
  for PACKAGE_NAME in "$@"; do
    echo "${blue}Removing $PACKAGE_NAME...${normal}"
    sudo pacman -Rns $PACKAGE_NAME
    echo $PACKAGE_NAME > ~/.haur_cache
  done
  if [ $CLEAR_CACHE == true ]; then
    if test -f "$HOME/.haur_cache"; then
      echo "${blue}Clearing cache...${normal}"
      while IFS= read -r line || [[ -n "$line" ]]; do
        echo "${blue}Removing $line${normal}"
        rm -rf $HOME/.haur/$line
      done < "$HOME/.haur_cache"
      rm ~/.haur_cache
    else
      echo "${blue}Nothing to clear${normal}"
    fi
  fi
elif [ $UPDATE == true ]; then
  for PACKAGE_NAME in "$@"; do
    echo "${blue}Updating $PACKAGE_NAME...${normal}"
    cd ~/.haur
    cd $PACKAGE_NAME
    git pull origin master
    rm -rf pkg src
    rm -f *.pkg.tar.gz
    makepkg -si
  done
  if [ $CLEAR_CACHE == true ]; then
    if test -f "$HOME/.haur_cache"; then
      echo "${blue}Clearing cache...${normal}"
      while IFS= read -r line || [[ -n "$line" ]]; do
        echo "${blue}Removing $line${normal}"
        rm -rf $HOME/.haur/$line
      done < "$HOME/.haur_cache"
      rm ~/.haur_cache
    else
      echo "${blue}Nothing to clear${normal}"
    fi
  fi
else
  if [ $CLEAR_CACHE == true ]; then
    if test -f "$HOME/.haur_cache"; then
      echo "${blue}Clearing cache...${normal}"
      while IFS= read -r line || [[ -n "$line" ]]; do
        echo "${blue}Removing $line${normal}"
        rm -rf $HOME/.haur/$line
      done < "$HOME/.haur_cache"
      rm ~/.haur_cache
    else
      echo "${blue}Nothing to clear${normal}"
    fi
  fi
  for PACKAGE_NAME in "$@"; do
    echo "${blue}Installing $PACKAGE_NAME...${normal}"
    mkdir -p ~/.haur
    cd ~/.haur
    git clone https://aur.archlinux.org/$PACKAGE_NAME.git
    cd $PACKAGE_NAME
    makepkg -si
  done
fi