123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173 |
- #!/bin/ksh
- #########################
- # Name: libdeblob.sh
- # Main: jadedctrl
- # Lisc: ISC
- # Desc: Functions to be
- # used for deblobbing
- # and rebranding OBSD
- # sources for the LBSD
- # project.
- #########################
- # Turns a file and it's path into a friendly filename
- # Usage: filetize $filepath
- filetize() {
- echo $1 | sed 's|/|\^|g'
- }
- # Vice-versa, clearly.
- # Usage: defiletize $filetizedpath
- unfiletize() {
- echo $1 | sed 's|\^|/|g'
- }
- # Prints $1 number of spaces.
- # Usage: space $number
- space() {
- i=0
- while [ $i != $1 ]
- do
- printf " "
- i=$((i+1))
- done
- }
- # Replace a string in a file
- # Usage: rep $replacee $replacer $file
- rep() {
- if [ -e "$PATCH_DIR/$(filetize "$3")" ]
- then
- sed 's^'"$1"'^'"$2"'^g' $PATCH_DIR/$(filetize "$3") > $PATCH_DIR/$(filetize "$3").tmp
- mv $PATCH_DIR/$(filetize "$3").tmp $PATCH_DIR/$(filetize "$3")
- diff ${SRC_DIR}/$3 $PATCH_DIR/$(filetize "$3") > $PATCH_DIR/$(filetize "$3").patch
- else
- sed 's^'"$1"'^'"$2"'^g' ${SRC_DIR}/${3} > $PATCH_DIR/$(filetize "$3")
- diff ${SRC_DIR}/$3 $PATCH_DIR/$(filetize "$3") > $PATCH_DIR/$(filetize "$3").patch
- fi
- }
- # Delete a string in a file
- # Usage: strdel $string $file
- strdel() {
- rep "$1" "" $2
- }
- # Inserts a new line after another
- # Usage: lineadd $string $newline $file
- lineadd() {
- if [ -e "$PATCH_DIR/$(filetize "$3")" ]
- then
- sed 's^'"$1"'^'"$1"' \
- '"$2"'^' $PATCH_DIR/$(filetize "$3") > $PATCH_DIR/$(filetize "$3").tmp
- mv $PATCH_DIR/$(filetize "$3").tmp $PATCH_DIR/$(filetize "$3")
- diff ${SRC_DIR}/$3 $PATCH_DIR/$(filetize "$3") > $PATCH_DIR/$(filetize "$3").patch
- else
- sed 's^'"$1"'^'"$1"' \
- '"$2"'^' ${SRC_DIR}/${3} > $PATCH_DIR/$(filetize "$3")
- diff ${SRC_DIR}/$3 $PATCH_DIR/$(filetize "$3") > $PATCH_DIR/$(filetize "$3").patch
- fi
- }
- # Removes a line.
- # Usage linedel $string $file
- linedel() {
- if [ -e "$PATCH_DIR/$(filetize "$2")" ]
- then
- grep -v "$1" $PATCH_DIR/$(filetize "$2") > $PATCH_DIR/$(filetize "$2").tmp
- mv $PATCH_DIR/$(filetize "$2").tmp $PATCH_DIR/$(filetize "$2")
- diff ${SRC_DIR}/$2 $PATCH_DIR/$(filetize "$2") > $PATCH_DIR/$(filetize "$2").patch
- else
- echo otherwise
- grep -v "$1" "${SRC_DIR}/$2" > $PATCH_DIR/$(filetize "$2")
- diff ${SRC_DIR}/$2 $PATCH_DIR/$(filetize "$2") > $PATCH_DIR/$(filetize "$2").patch
- echo otherhell
- fi
- }
- # "Copies" a dir
- # Usage: dircp $file $dest
- dircp() {
- if echo $1 | grep "^files/"
- then
- echo "FILES"
- cp -r "$1" "$PATCH_DIR/ADD_$(filetize "$2")"
- else
- echo "NO FILES"
- cp -r "${SRC_DIR}/$1" "$PATCH_DIR/ADD_$(filetize "$2")"
- fi
- }
- # "Copies" a file
- # Usage: filedel $file $dest
- filecp() {
- if echo $1 | grep "^files/"
- then
- echo "FILES"
- cp "$1" "$PATCH_DIR/ADD_$(filetize "$2")"
- else
- echo "FILES"
- cp "${SRC_DIR}/$1" "$PATCH_DIR/ADD_$(filetize "$2")"
- fi
- }
- # "Deletes" a file
- # Usage: filedel $file
- filedel() {
- echo $PATCH_DIR $1
- touch $PATCH_DIR/RM_$(filetize $1)
- }
- # Applies patches.
- apply() {
- for file in $PATCH_DIR/*
- do
- realname=$(echo $file | sed 's^.*/^^' | sed 's/ADD_//' | sed 's/RM_//')
- realname="$(unfiletize "$realname")"
- if echo "$file" | grep "RM_" > /dev/null
- then
- realname=$(echo "$realname" | sed 's/RM_//')
- echo "Deleting $realname..."
- if rm -rf ${SRC_DIR}/$realname
- then
- echo "$realname deleted" >> apply.log
- echo "$realname deleted"
- else
- echo "!!! $realname NOT deleted" >> apply.log
- echo "!!! $realname NOT deleted"
- fi
- elif echo "$file" | grep "ADD_" > /dev/null
- then
- realname=$(echo "$realname" | sed 's/ADD_//')
- echo "Copying $file to $realname..."
- if cp -r $file ${SRC_DIR}/$realname
- then
- echo "$realname copied from $file" >> apply.log
- else
- echo "!!! $realname NOT copied from $file" >> apply.log
- fi
- elif echo "$file" | grep ".patch$" > /dev/null
- then
- if patch "${SRC_DIR}/$(echo $realname | sed 's/\.patch//')" < $file
- then
- echo "${SRC_DIR}/$(echo $realname | sed 's/\.patch//') patched from $file" >> apply.log
- else
- echo "!!! ${SRC_DIR}/$(echo $realname | sed 's/\.patch//') NOT patched from $file" >> apply.log
- fi
- fi
- done
- }
- self_destruct_sequence() {
- echo "$1 will be deleted in three seconds."
- echo "CTRL-C now to avoid this fate!"
- echo "3"; sleep 1
- echo "2"; sleep 1
- echo "1"; sleep 1
- printf "0\nDestruction!"
- rm -rf "$1"
- }
|