Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Should check to make sure ur is run as root #1

Open
krc4267 opened this issue Oct 19, 2015 · 2 comments
Open

Should check to make sure ur is run as root #1

krc4267 opened this issue Oct 19, 2015 · 2 comments

Comments

@krc4267
Copy link

krc4267 commented Oct 19, 2015

Just a suggestion- giving a permission denied message isn't great. Something like "Sorry, ur needs to be run as root" might be better :)

@ikeydoherty
Copy link
Collaborator

diff -ruNB a/ur b/ur
--- a/ur    2015-10-19 17:15:15.006304817 +0100
+++ b/ur    2015-10-19 17:15:28.209056360 +0100
@@ -11,6 +11,17 @@
 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
@@ -211,8 +222,12 @@
 }

 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."
 }
@@ -340,7 +355,7 @@
 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
@@ -351,9 +366,11 @@
 shift
 case "${arg}" in
     install|it)
+        require_root
         do_install $*
         ;;
     upgrade|up)
+        require_root
         do_upgrade $*
         ;;
     search|sr)
@@ -366,6 +383,7 @@
         do_viewyml $*
         ;;
     remove|rm)
+        require_root
         do_remove $*
         ;;
     update-repo|ur)

@ikeydoherty
Copy link
Collaborator

^ @Justinzobel might wanna add that. Also deals with mkdir -p issue

ikeydoherty added a commit that referenced this issue Oct 19, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants