stctpw.sh (2716B)
1 #!/bin/bash 2 3 # Vars 4 MODFILE="$HOME/config.def.h" 5 CURRENT_DIR=$PWD 6 ARG='' 7 TARGETDISTFILES='' 8 FETCHWEB=0 9 INSTALLPATCH=0 10 NUMARGS=0 11 12 # Functions 13 displayhelp() { 14 printf "Usage: stctpw.sh [OPTIONS] [ARGUMENT]\n" 15 printf "Create a diff file for a suckless program's config.h.\n\n" 16 printf "Mandatory options for long arguments are mandatory for short arguments too:\n" 17 printf "\t-f=[FILE]\t\tThe file to use to create a patch.\n" 18 printf "\t-w, --web\t\tDon't look for local distfiles; fetch them from the web instead.\n" 19 printf "\t-i, --install\t\tInstall the patch in the proper location (/etc/portage/patches/{CATEGORY}/{P}).\n" 20 printf "\t--help\t\t\tDisplay this help text.\n\n" 21 printf "Arguments should be lowercase names of suckless programs. The currently supported arguments are:\n" 22 printf "\tst\t- Simple Terminal\n" 23 printf "\tdwm\t- Dynamic Window Manager\n" 24 printf "\tdmenu\t- Dmenu\n" 25 printf "Copyright (c) 2020 Erik Letson, all rights reserved\n" 26 printf "This program is released under the MIT"'\\'"Expat license. See LICENSE file for details.\n" 27 return 0 28 } 29 30 multidistfileprompt() { 31 return 0 32 } 33 34 # Opts 35 while [[ "$#" -gt 0 ]]; do 36 case $1 in 37 -f) 38 MODFILE=$(realpath $2); shift ;; 39 -w|--web) 40 FETCHWEB=1 ;; 41 -i|--install) 42 INSTALLPATCH=1 ;; 43 --help) 44 displayhelp 45 exit 0 ;; 46 *) 47 ARG=$1 48 NUMARGS=$NUMARGS+1 49 if [[ $NUMARGS -eq 2 ]]; then 50 echo "Too many arguments!" 51 exit 1 52 fi 53 ;; 54 esac 55 shift 56 done 57 58 if [[ -z $ARG ]]; then 59 printf "No argument passed. Please provide the name of the suckless program you want to generate a patch for.\n" 60 printf "Try 'stctpw.sh --help' for more information.\n" 61 exit 1 62 fi 63 64 # Set up environment 65 mkdir -p /var/tmp/stctpw 66 cd /var/tmp/stctpw 67 68 # Get the archive (has potential interactive elements) 69 if [[ $FETCHWEB -ne 1 ]]; then 70 71 # Sub-process substitution so the vars work right 72 numlines=0 73 while read -r line; do 74 numlines=$numlines+1 75 TARGETDISTFILES="$TARGETDISTFILES $line" 76 done < <(find /var/cache/distfiles/ | grep "^/var/cache/distfiles/$ARG-") 77 78 if [[ $numlines -ge 2 ]]; then 79 multidistfileprompt $TARGETDISTFILES 80 fi 81 82 tar -xzf $TARGETDISTFILES 83 84 #TODO: This is not a good way to get the dir name... 85 dirname=$(ls) 86 87 cp -r $dirname a 88 cp -r $dirname b 89 cp $MODFILE b/config.def.h 90 diff -up a b > $CURRENT_DIR/config.patch 91 92 if [[ $INSTALLPATCH -eq 1 ]]; then 93 echo "Will install" 94 fi 95 96 cd /var/tmp 97 rm -rd stctpw 98 fi 99 unset numlines dirname