scripts

Scripts
git clone git://git.wimdupont.com/scripts.git
Log | Files | Refs | LICENSE

sinstaller (3025B)


      1 #!/bin/bash
      2 
      3 source ~/.config/scripts/properties
      4 
      5 all=0
      6 save_diff=0
      7 while getopts "as" arg; do
      8 	case $arg in
      9 		a) all=1;;
     10 		s) save_diff=1;;
     11 	esac
     12 done
     13 
     14 shift $((OPTIND-1))
     15 
     16 program=$1
     17 
     18 readonly ROOT_DIR=$HOME/repositories/suckless
     19 readonly GIT_BASE_URL=https://git.suckless.org
     20 
     21 PROGRAMS=(
     22 	"dmenu"
     23 	"dwm"
     24 	"dwmstatus"
     25 	"ii"
     26 	"libgrapheme"
     27 	"lchat"
     28 	"sic"
     29 	"slock"
     30 	"st"
     31 	"surf"
     32 	"sent"
     33 )
     34 
     35 PATCHES=(
     36 	#"st;https://st.suckless.org/patches/alpha_focus_highlight/st-focus-20230610-68d1ad9.diff"
     37 	"st;https://st.suckless.org/patches/scrollback/st-scrollback-0.9.2.diff"
     38 	"dwm;https://dwm.suckless.org/patches/statuspadding/dwm-statuspadding-6.3.diff"
     39 	"dwm;https://dwm.suckless.org/patches/alpha/dwm-fixborders-6.2.diff"
     40 	"slock;https://tools.suckless.org/slock/patches/background-image/slock-background-image-20220318-1c5a538.diff"
     41 	"surf;https://surf.suckless.org/patches/homepage/surf-2.0-homepage.diff"
     42 	"surf;https://surf.suckless.org/patches/playexternal/surf-playexternal-20190724-b814567.diff"
     43 	"surf;https://surf.suckless.org/patches/quit-hotkey/surf-quit_hotkey-20210830-11dca18.diff"
     44 )
     45 
     46 download(){
     47 	declare -r PROGRAM=$1
     48 
     49 	mkdir -p "${ROOT_DIR}"
     50 	mkdir -p "${ROOT_DIR}/patches/$PROGRAM"
     51 
     52 	cd "${ROOT_DIR}"
     53 
     54 	git clone "${GIT_BASE_URL}/$PROGRAM"
     55 	cd $PROGRAM
     56 	git checkout -b patched
     57 
     58 	download_patches "$PROGRAM"
     59 }
     60 
     61 download_patches(){
     62 	declare -r PROGRAM=$1
     63 	rm "$ROOT_DIR/patches/$PROGRAM/"*
     64 	i=0
     65 	for patch in "${PATCHES[@]}"
     66 	do
     67 		name=$(echo "$patch" | cut -f1 -d ';')
     68 		
     69 		if [[ "${name}" == "${PROGRAM}" ]]; then
     70 			((i++))
     71 			patch_url=$(echo "$patch" | cut -f2 -d ';')
     72 			curl "$patch_url" > "$ROOT_DIR/patches/$PROGRAM/$i-${patch_url##*/}"
     73 		fi
     74 	done
     75 }
     76 
     77 cleanup_and_patch(){
     78 	declare -r PROGRAM=$1
     79 	cd "${ROOT_DIR}/$PROGRAM" 	
     80 
     81 	git checkout patched
     82 
     83 	git reset --hard HEAD
     84 	git clean -xf
     85 
     86 	git checkout surf-webkit2
     87 	git checkout master
     88 	git pull
     89 
     90 	git branch -D patched
     91 	git checkout -b patched
     92 	
     93 	for file in "$ROOT_DIR/patches/$PROGRAM/"*; do
     94 		test -f $file || continue;
     95 		patch -i $file
     96 	done
     97 
     98 	git add .
     99 	git -c commit.gpgsign=false commit -m "patched"
    100 }
    101 
    102 patch_config(){
    103 	declare -r PROGRAM=$1
    104 	cd "${ROOT_DIR}/$PROGRAM" 	
    105 
    106 	git checkout patched
    107 
    108 	config_file="$ROOT_DIR/patches-config/$PROGRAM-config.diff"
    109 	test -f "$config_file" && patch -i "$config_file"
    110 }
    111 
    112 
    113 save_config(){
    114 	declare -r PROGRAM=$1
    115 	cd "${ROOT_DIR}/$PROGRAM" 	
    116 	#git add -N config.h #enable if you want config.h in diff instead of def.h
    117 	git diff > "$ROOT_DIR/patches-config/$PROGRAM-config.diff"
    118 }
    119 
    120 execute_installer(){
    121 	declare -r PROGRAM=$1
    122 
    123 	[[ ! -d "${ROOT_DIR}/$PROGRAM" ]] && download $PROGRAM
    124 	test "$save_diff" == 1 && save_config $PROGRAM
    125 	cleanup_and_patch $PROGRAM
    126 	patch_config $PROGRAM
    127 
    128 	cd "${ROOT_DIR}/$PROGRAM" 	
    129 	make
    130 	sudo make clean install
    131 }
    132 
    133 test "$all" == 0 && [ -z $program ] && notify-send "Insufficient parameters" "Either use -a for all or specifify program as arg." && exit 1;
    134 
    135 if [[ "$all" == 1 ]]; then
    136 	for i in "${PROGRAMS[@]}"
    137 	do
    138 		execute_installer $i
    139 	done
    140 else
    141 	execute_installer $program
    142 fi