aboutsummarylogtreecommitdiffstats
path: root/haur
blob: 95636cd979a8d80a6fe27ece554d8b7ab1b0f42c (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
#!/usr/bin/env bash

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

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 [ $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