-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathspm
executable file
·228 lines (210 loc) · 11.8 KB
/
spm
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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
#!/bin/bash -e
# Title: spm
# Description: Downloads and installs AppImages and precompiled tar archives. Can also upgrade and remove installed packages.
# Dependencies: GNU coreutils, tar, wget
# Author: simonizor
# Website: http://www.simonizor.gq
# License: GPL v2.0 only
X="0.6.4"
# Set spm version
ARG="$1"
PKG_INPUT="$2"
CONFDIR="$HOME/.config/spm"
SKIP_DEP_CHECKS="FALSE"
CLR_CLEAR="$(tput sgr0)"
CLR_BLUE="$(tput setaf 4)"
CLR_LGREEN="$(tput setaf 10)"
CLR_GREEN="$(tput setaf 2)"
CLR_LCYAN="$(tput setaf 14)"
CLR_CYAN="$(tput setaf 6)"
CLR_RED="$(tput setaf 1)"
if [ "$EUID" = "0" ]; then # Prevent spm from being ran as root
echo "Do not run spm as root!"
exit 1
fi
if [ -f ~/.config/spm/spm.conf ]; then
. ~/.config/spm/spm.conf
fi
case $ARG in
-v|--verbose)
ARG="$2"
PKG_INPUT="$3"
set -v
;;
-d|--debug)
ARG="$2"
PKG_INPUT="$3"
set -x
;;
-n|--noexec)
ARG="$2"
PKG_INPUT="$3"
set -v
set -n
;;
esac
if [ ! -d "$CONFDIR" ]; then # Create dirs for configs, config files, and download package lists if they don't exist
echo "spm is being ran for the first time."
echo "Creating config directories..."
mkdir "$CONFDIR"
mkdir "$CONFDIR"/tarinstalled
mkdir "$CONFDIR"/appimginstalled
mkdir "$CONFDIR"/tarupgrades
mkdir "$CONFDIR"/appimgupgrades
mkdir "$CONFDIR"/cache
echo "CONFDIR="\"$CONFDIR\""" > "$CONFDIR"/spm.conf
echo "GITHUB_TOKEN="\"\""" >> "$CONFDIR"/spm.conf
echo "SKIP_DEP_CHECKS="\"FALSE\""" >> "$CONFDIR"/spm.conf
echo "CLR_BLUE="\"$(tput setaf 4)\""" >> "$CONFDIR"/spm.conf
echo "CLR_LGREEN="\"$(tput setaf 10)\""" >> "$CONFDIR"/spm.conf
echo "CLR_GREEN="\"$(tput setaf 2)\""" >> "$CONFDIR"/spm.conf
echo "CLR_LCYAN="\"$(tput setaf 14)\""" >> "$CONFDIR"/spm.conf
echo "CLR_CYAN="\"$(tput setaf 6)\""" >> "$CONFDIR"/spm.conf
echo "CLR_RED="\"$(tput setaf 1)\""" >> "$CONFDIR"/spm.conf
echo "First run operations complete!"
fi
if [ ! -f "$CONFDIR/AppImages.yml" ]; then
echo "Downloading AppImages.yml from spm github..."
wget --quiet "https://raw.githubusercontent.com/simoniz0r/spm-repo/master/AppImages.yml" -O "$CONFDIR"/AppImages.yml
echo "Downloading tar-pkgs.yml from spm github repo..."
wget --quiet "https://raw.githubusercontent.com/simoniz0r/spm-repo/master/tar-pkgs.yml" -O "$CONFDIR"/tar-pkgs.yml
fi
REALPATH="$(readlink -f $0)"
RUNNING_DIR="$(dirname "$REALPATH")" # Find directory script is running from
if [ -f "$RUNNING_DIR/ssft.sh" ]; then
source "$RUNNING_DIR"/ssft.sh
SSFT_FRONTEND="text"
else
echo "${CLR_RED}Missing required file $RUNNINGDIR/ssft.sh; exiting...${CLR_CLEAR}"
rm -rf "$CONFDIR"/cache/*
exit 1
fi
if [ -f $RUNNING_DIR/spmfunctions.sh ]; then # Check to make sure spmfunctions.sh exists and is up to date
FUNCTIONS_VER="$(cat "$RUNNING_DIR"/spmfunctions.sh | sed -n 9p | cut -f2 -d'"')"
if [ "$X" != "$FUNCTIONS_VER" ]; then
ssft_display_error "${CLR_RED}spmfunctions.sh $FUNCTIONS_VER version does not match $X !" "spmfunctions.sh is out of date! Please download the full release of spm from https://github.com/simoniz0r/spm/releases !${CLR_CLEAR}"
exit 1
fi
else
ssft_display_error "${CLR_RED}Missing required file $RUNNING_DIR/spmfunctions.sh !" "spmfunctions.sh is missing! Please download the full release of spm from https://github.com/simoniz0r/spm/releases !${CLR_CLEAR}"
exit 1
fi
source "$RUNNING_DIR"/spmfunctions.sh || { ssft_display_error "${CLR_RED}Error sourcing spmfunctions.sh" "Sourcing spmfunctions.sh failed; exiting...${CLR_CLEAR}"; rm -rf "$CONFDIR"/cache/*; exit 1; } # import functions from spmfunctions.sh
spmdepchecksfunc || { ssft_display_error "${CLR_RED}Error loading spmfunctions.sh" "Could not load $RUNNING_DIR/spmfunctions.sh; exiting...${CLR_CLEAR}"; exit 1; } # Check for deps, exit if not present
if type spm >/dev/null 2>&1 && [ -f ~/.zshrc ] && ! grep -q 'spm.comp' ~/.zshrc; then # If using zsh and spm is installed, add tab completions for spm
wget --quiet "https://raw.githubusercontent.com/simoniz0r/spm/master/spm.comp" -O "$CONFDIR"/spm.comp
echo "" >> ~/.zshrc
echo "if [ -f "$CONFDIR"/spm.comp ]; then" >> ~/.zshrc
echo " source "$CONFDIR"/spm.comp" >> ~/.zshrc
echo " compdef _spm spm" >> ~/.zshrc
echo "fi" >> ~/.zshrc
echo "" >> ~/.zshrc
fi
appimgfunctioncheckfunc # Check to make sure appimgfunctions.sh exists and is up to date
source "$RUNNING_DIR"/appimgfunctions.sh || { ssft_display_error "${CLR_RED}Error sourcing appimgfunctions.sh" "Sourcing appingfunctions.sh failed; exiting...${CLR_CLEAR}"; rm -rf "$CONFDIR"/cache/*; exit 1; } # import functions from appimgfunctions.sh
appimgfunctionsexistsfunc || { ssft_display_error "${CLR_RED}Error loading appimgfunctions.sh" "Could not load $RUNNING_DIR/appimgfunctions.sh; exiting...${CLR_CLEAR}"; exit 1; }
tarfunctioncheckfunc # Check to make sure tarfunctions.sh exists and is up to date
source "$RUNNING_DIR"/tarfunctions.sh || { ssft_display_error "${CLR_RED}Error sourcing tarfunctions.sh" "Sourcing tarfunctions.sh failed; exiting...${CLR_CLEAR}"; rm -rf "$CONFDIR"/cache/*; exit 1; } # import functions from tarfunctions.sh
tarfunctionsexistfunc || { ssft_display_error "${CLR_RED}Error loading tarfunctions.sh" "Could not load $RUNNING_DIR/tarfunctions.sh; exiting...${CLR_CLEAR}"; exit 1; }
spmlockfunc # Create "$CONFDIR"/cache/spm.lock file and prevent multiple instances by checking if it exists before running
printf '%s\n' "
A new version of spm has been released that is not compatible with this version. This version of spm will no longer be maintained.
It is advised to remove all applications that are installed with this version of spm and update to the new version from
https://github.com/simoniz0r/spm/releases
"
if [ -z "$GITHUB_TOKEN" ]; then # Display github rate limit by using wget to show https://api.github.com/rate_limit
wget -S --spider "https://api.github.com/rate_limit" -o "$CONFDIR"/cache/rate.limit
echo "Github API rate limit: $(grep -m 1 '.*X-RateLimit-Remaining:*.' "$CONFDIR"/cache/rate.limit | cut -f4 -d" ")/60 until $(date -d@$(grep -m 1 '.*X-RateLimit-Reset:*.' "$CONFDIR"/cache/rate.limit | cut -f4 -d" ") +"%T, %F")." || { echo "Github rate limit check failed; exiting..."; rm -rf "$CONFDIR"/cache/*; exit 1; }
else
wget -S --spider --quiet --auth-no-challenge --header="Authorization: token "$GITHUB_TOKEN"" "https://api.github.com/rate_limit" -o "$CONFDIR"/cache/rate.limit || { echo "Github rate limit check failed; exiting..."; rm -rf "$CONFDIR"/cache/*; exit 1; }
echo "Github API rate limit : $(grep -m 1 '.*X-RateLimit-Remaining:*.' "$CONFDIR"/cache/rate.limit | cut -f4 -d" ")/5000 until $(date -d@$(grep -m 1 '.*X-RateLimit-Reset:*.' "$CONFDIR"/cache/rate.limit | cut -f4 -d" ") +"%T, %F")."
fi
if [ "$(grep -m 1 '.*X-RateLimit-Remaining:*.' "$CONFDIR"/cache/rate.limit | cut -f4 -d" ")" = "0" ]; then # Attempt to exit to prevent errors if user's github rate limit has been used up
ssft_display_error "${CLR_RED}Github API rate limit reached! Try again at $(date -d@$(grep -m 1 '.*X-RateLimit-Reset:*.' "$CONFDIR"/cache/rate.limit | cut -f4 -d" "))." "If you haven't already, you can add your token to $CONFDIR/spm.conf to avoid hitting the rate limit.${CLR_CLEAR}"
rm -rf "$CONFDIR"/cache/* # Remove any files in cache before exiting
exit 1
fi
echo
case $ARG in
install|-i|appimg-install|-ai|tarinstall|-ti) # Check if package is in either list and rout install to relevant function
if [ -z "$PKG_INPUT" ]; then
ssft_display_error "${CLR_RED}Error" "Package input required; exiting...${CLR_CLEAR}"
rm -rf "$CONFDIR"/cache/*
exit 1
fi
TESTPKG="$PKG_INPUT"
installstartfunc || { ssft_display_error "${CLR_RED}Error" "Install failed; exiting...${CLR_CLEAR}"; rm -rf "$CONFDIR"/cache/*; exit 1; } # Check package lists and route install to relevant function
rm -rf "$CONFDIR"/cache/* # Remove any files in cache before exiting
exit 0
;;
update|-upd) # Update package lists and check for package upgrades
spmvercheckfunc || { ssft_display_error "${CLR_RED}Error" "spm version check failed; exiting...${CLR_CLEAR}"; rm -rf "$CONFDIR"/cache/*; exit 1; } # Check spm version and let user know if it is out of date
updatestartfunc "$PKG_INPUT" || { sssft_display_error "${CLR_RED}Error" "Upgrade check failed; exiting...${CLR_CLEAR}"; rm -rf "$CONFDIR"/cache/*; exit 1; } # Send input to relevant update function or run both if no input
rm -rf "$CONFDIR"/cache/* # Remove any files in cache before exiting
exit 0
;;
update-force|-uf|appimg-update-force|-auf|tar-update-force|-tuf) # Force AppImage to be marked for upgrade
if [ -z "$PKG_INPUT" ]; then
ssft_display_error "${CLR_RED}Error" "Package input required; exiting...${CLR_CLEAR}"
rm -rf "$CONFDIR"/cache/* # Remove any files in cache before exiting
exit 1
fi
TESTUF="$PKG_INPUT"
updateforcestartfunc || { ssft_display_error "${CLR_RED}Error" "Update force failed; exiting...${CLR_CLEAR}"; rm -rf "$CONFDIR"/cache/*; exit 1; }
rm -rf "$CONFDIR"/cache/* # Remove any files in cache before exiting
exit 0
;;
upgrade|-upg) # upgrade packages to latest version if marked for upgrade
upgradestartfunc "$PKG_INPUT" || { ssft_display_error "${CLR_RED}Error" "Upgrade failed; exiting...${CLR_CLEAR}"; rm -rf "$CONFDIR"/cache/*; exit 1; }
rm -rf "$CONFDIR"/cache/* # Remove any files in cache before exiting
exit 0
;;
remove|-r|appimg-remove|-ar|tar-remove|-tr)
if [ -z "$PKG_INPUT" ]; then
ssft_display_error "${CLR_RED}Error" "Package input required; exiting...${CLR_CLEAR}"
rm -rf "$CONFDIR"/cache/* # Remove any files in cache before exiting
exit 1
fi
TESTREM="$PKG_INPUT"
removestartfunc || { ssft_display_error "${CLR_RED}Error" "Package remove failed; exiting...${CLR_CLEAR}"; rm -rf "$CONFDIR"/cache/*; exit 1; }
rm -rf "$CONFDIR"/cache/* # Remove any files in cache before exiting
exit 0
;;
list|-l) # List installed packages or info about specified package
INSTIMG="$PKG_INPUT"
TARPKG="$PKG_INPUT"
liststartfunc || { ssft_display_error "${CLR_RED}Error" "List failed; exiting...${CLR_CLEAR}"; rm -rf "$CONFDIR"/cache/*; exit 1; } # Send package input to relevant list function or run both if no input
rm -rf "$CONFDIR"/cache/* # Remove any files in cache before exiting
exit 0
;;
list-installed|-li) # List information about installed packages
listinstalledfunc | less -R
rm -rf "$CONFDIR"/cache/* # Remove any files in cache before exiting
exit 0
;;
search|-s) # Use grep to search package lists based on user input and output matching packages and which list they are in
if cat "$CONFDIR"/AppImages.yml | cut -f1 -d":" | grep -q "$PKG_INPUT"; then
echo "$(tput bold)${CLR_GREEN}AppImage(s)${CLR_CLEAR}:"
cat "$CONFDIR"/AppImages.yml | cut -f1 -d":" | grep "$PKG_INPUT"
echo
fi
if echo "$TAR_LIST" | grep -q "$PKG_INPUT"; then
echo "$(tput bold)${CLR_CYAN}tar package(s)${CLR_CLEAR}:"
echo "$TAR_LIST" | grep "$PKG_INPUT"
echo
fi
rm -rf "$CONFDIR"/cache/* # Remove any files in cache before exiting
exit 0
;;
man|-m) # run man $RUNNING_DIR/spm.1 to show spm's man file
man $RUNNING_DIR/spm.1
rm -rf "$CONFDIR"/cache/* # Remove any files in cache before exiting
exit 0
;;
*) # Any unknown arguments go to help func
helpfunc
rm -rf "$CONFDIR"/cache/* # Remove any files in cache before exiting
exit 0
;;
esac
set -