scripts

random scripts
git clone https://git.parazyd.org/scripts
Log | Files | Refs

supadd (1113B)


      1 #!/bin/sh
      2 #
      3 # parazyd - (c) wtfpl 2016
      4 # edit sup's bins
      5 
      6 supsrc="/home/parazyd/src/INSTALLED/sup"
      7 
      8 printsettings() {
      9 	cat <<EOF
     10 /* sup's configuration file */
     11 
     12 /* (un)comment flags below to remove functionalities */
     13 #define HASH 1
     14 #define DAEMON 0
     15 /* #define DEBUG 0 */
     16 
     17 #ifndef FLAGSONLY
     18 
     19 #define USER 1000
     20 #define GROUP -1
     21 
     22 #define SETUID 0
     23 #define SETGID 0
     24 
     25 #define CHROOT ""
     26 #define CHRDIR ""
     27 
     28 static struct rule_t rules[] = {
     29 	/* allow user to run these programs when found in path location */
     30 EOF
     31 }
     32 
     33 printentry() {
     34 	cat <<EOF
     35 	{ USER, GROUP, "$(basename $bin)", "$bin", "$shasum" },
     36 EOF
     37 }
     38 
     39 printrest() {
     40 	cat <<EOF
     41 
     42 	{ 0 },
     43 };
     44 
     45 #endif
     46 EOF
     47 }
     48 
     49 getsha() {
     50 	shasum=$(sha256sum $bin | awk '{print $1}')
     51 	test -n "$shasum" || exit 1
     52 }
     53 
     54 bin="$PWD/$1"
     55 getsha
     56 
     57 if grep "$bin" $supsrc/allowed.txt >/dev/null ; then
     58 	grep -v "$bin" $supsrc/allowed.txt > /tmp/allowed.txt
     59 	mv /tmp/allowed.txt $supsrc/allowed.txt
     60 fi
     61 
     62 printentry >> $supsrc/allowed.txt
     63 printsettings | cat - $supsrc/allowed.txt > $supsrc/config.h
     64 printrest >> $supsrc/config.h
     65 cat $supsrc/allowed.txt
     66 
     67 cd $supsrc && exec sh -c 'sudo make clean install'