Skip to content

Commit

Permalink
Require root for certain ops, handle directory existence gracefully
Browse files Browse the repository at this point in the history
This resolves issue #1

Signed-off-by: Ikey Doherty <[email protected]>
  • Loading branch information
ikeydoherty committed Oct 19, 2015
1 parent 6e4f878 commit 6b76596
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion ur
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,17 @@ red="\e[31m"
yellow="\e[93m"
white="\e[0m"

function do_fail() {
echo "$*"
exit 1
}

function require_root() {
if [[ "${EUID}" -ne 0 ]]; then
do_fail "Must be root to use this function"
fi
}

function addtoupgradelist {
# Create a list of packages to pass to the upgrader
pkgname=$1
Expand Down Expand Up @@ -211,8 +222,12 @@ function do_search {
}

function do_updaterepo {
require_root
# Update repo database from server to local disk.
echo -e "${notice}Updating Repository..."
if [[ ! -d "/var/db/surt" ]]; then
mkdir -p "/var/db/surt" || do_fail "Unable to create /var/db/surt - check permissions"
fi
wget -q http://solus-us.tk/ur/index -O /var/db/surt/repo-index
echo -e "${notice}Repository Updated."
}
Expand Down Expand Up @@ -340,7 +355,7 @@ if [[ ! -d ~/.solus ]];then createpackagerfile
fi

# Check if repo index exists
if [[ ! -f /var/db/surt/repo-index ]];then echo -e "${notice}Repository index not present, fetching.";updaterepo
if [[ ! -f /var/db/surt/repo-index ]];then echo -e "${notice}Repository index not present, fetching.";do_updaterepo
fi

# Check if database exists if not create
Expand All @@ -351,9 +366,11 @@ arg="${1}"
shift
case "${arg}" in
install|it)
require_root
do_install $*
;;
upgrade|up)
require_root
do_upgrade $*
;;
search|sr)
Expand All @@ -366,6 +383,7 @@ case "${arg}" in
do_viewyml $*
;;
remove|rm)
require_root
do_remove $*
;;
update-repo|ur)
Expand Down

0 comments on commit 6b76596

Please sign in to comment.