diff --git a/buildpkg b/buildpkg index f5c3a41..6e44a07 100755 --- a/buildpkg +++ b/buildpkg @@ -1,8 +1,8 @@ #!/bin/bash - -. /usr/share/scratchpkg/functions || exit 1 export LC_ALL=C + +. /usr/share/scratchpkg/functions || exit 1 updatemdsum() { @@ -364,24 +364,6 @@ checkdeps() { } -check_directory() { - - for dir in $WORK_DIR $SOURCE_DIR $PACKAGE_DIR $LOG_DIR; do - if [ ! -d $dir ]; then - msgwarn "Directory ${color_yellow}$dir${color_reset} not exist." - DIR_ERROR=yes - elif [ ! -w $dir ]; then - msgwarn "Directory ${color_yellow}$dir${color_reset} not writable." - DIR_ERROR=yes - elif [ ! -x $dir ] || [ ! -r $1 ]; then - msgwarn "Directory ${color_yellow}$dir${color_reset} not readable." - DIR_ERROR=yes - fi - done - - [ "$DIR_ERROR" ] && exitscript1 -} - # remove lock file and exit 1 exitscript1() { @@ -626,7 +608,10 @@ main() { SOURCE_DIR="$SOURCE_PKG" fi - check_directory + #check_directory + checkdirexist "$WORK_DIR" "$SOURCE_DIR" "$PACKAGE_DIR" "$LOG_DIR" + checkdirwrite "$WORK_DIR" "$SOURCE_DIR" "$PACKAGE_DIR" "$LOG_DIR" + checkdirread "$WORK_DIR" "$SOURCE_DIR" "$PACKAGE_DIR" "$LOG_DIR" loadspkgbuild diff --git a/functions/functions b/functions/functions index 0a56c4f..6b7404e 100644 --- a/functions/functions +++ b/functions/functions @@ -9,12 +9,21 @@ source "$FUNCTIONS/color" CONF_FILE="/etc/scratchpkg.conf" BUILD_SCRIPT="spkgbuild" -ROOT_DIR=/ -INDEX_DIR=/var/spkg/index -BACKUP_DIR=/var/spkg/backup -REJECTED_DIR=/var/spkg/rejected -LOG_DIR=/var/spkg/log -HOOK_DIR=/etc/hooks +ROOT_DIR="/" +INDEX_DIR="/var/lib/scratchpkg/index" + +PACKAGE_DIR="/var/cache/scratchpkg/packages" +SOURCE_DIR="/var/cache/scratchpkg/sources" +WORK_DIR="/tmp" +BACKUP_DIR="/var/cache/scratchpkg/backup" +REJECTED_DIR="/var/cache/scratchpkg/rejected" +LOG_DIR="/var/cache/scratchpkg/log" +HOOK_DIR="/etc/hooks" + +OPTIONS=(libtool emptydirs strip docs purge zipman buildflags makeflags) +PURGE_FILES=(usr/{,share/}info/dir) +DOC_DIRS=(usr/{,local/}{,share/}{doc,gtk-doc} opt/*/{doc,gtk-doc}) +MAN_DIRS=({usr{,/local}{,/share},opt/*}/man) if [ -f $CONF_FILE ]; then . $CONF_FILE @@ -234,3 +243,42 @@ build() { fi } + +checkdirexist() { + + for dir in "$@"; do + if [ ! -d $dir ]; then + msgwarn "Directory ${color_yellow}$dir${color_reset} not exist." + DIR_ERROR=yes + fi + done + + [ "$DIR_ERROR" ] && exit 1 + +} + +checkdirwrite() { + + for dir in "$@"; do + if [ ! -w $dir ]; then + msgwarn "Directory ${color_yellow}$dir${color_reset} not writable." + DIR_ERROR=yes + fi + done + + [ "$DIR_ERROR" ] && exit 1 + +} + +checkdirread() { + + for dir in "$@"; do + if [ ! -x $dir ] || [ ! -r $1 ]; then + msgwarn "Directory ${color_yellow}$dir${color_reset} not readable." + DIR_ERROR=yes + fi + done + + [ "$DIR_ERROR" ] && exit 1 + +} diff --git a/installpkg b/installpkg index e8c194a..ef83c6a 100755 --- a/installpkg +++ b/installpkg @@ -1,8 +1,8 @@ #!/bin/bash - -. /usr/share/scratchpkg/functions || exit 1 export LC_ALL=C + +. /usr/share/scratchpkg/functions || exit 1 spkglock() { @@ -527,8 +527,13 @@ main() { exit 0 fi + ### CHECK FOR ROOT ACCESS ### needroot "Installing package" - check_directory + + ### CHECK DIRECTORY ### + checkdirexist "$INDEX_DIR" "$BACKUP_DIR" "$REJECTED_DIR" + checkdirwrite "$INDEX_DIR" "$BACKUP_DIR" "$REJECTED_DIR" + checkdirread "$INDEX_DIR" "$BACKUP_DIR" "$REJECTED_DIR" ### CHECK FOR LOCK FILE ### if [ -f /tmp/spkg.lock ]; then diff --git a/removepkg b/removepkg index 9064fdd..54d2b77 100755 --- a/removepkg +++ b/removepkg @@ -1,8 +1,8 @@ #!/bin/bash - -. /usr/share/scratchpkg/functions || exit 1 export LC_ALL=C + +. /usr/share/scratchpkg/functions || exit 1 spkglock() { @@ -179,24 +179,6 @@ saferemove() { } -check_directory() { - - for dir in $INDEX_DIR $BACKUP_DIR $REJECTED_DIR; do - if [ ! -d $dir ]; then - msg "Directory ${color_yellow}$1${color_reset} not exist." - DIR_ERROR=yes - elif [ ! -w $dir ]; then - msg "Directory ${color_yellow}$1${color_reset} not writable." - DIR_ERROR=yes - elif [ ! -x $dir ] || [ ! -r $1 ]; then - msg "Directory ${color_yellow}$1${color_reset} not readable." - DIR_ERROR=yes - fi - done - - [ "$DIR_ERROR" ] && exit 1 -} - runremovehooks() { if [ "${#runthishook[@]}" -gt 0 ]; then @@ -277,28 +259,33 @@ main() { nocolor fi + ### CHECK FOR ROOT ACCESS ### needroot "Removing package" + ### CHECK DIRECTORY ### + checkdirexist "$INDEX_DIR" "$BACKUP_DIR" "$REJECTED_DIR" + checkdirwrite "$INDEX_DIR" "$BACKUP_DIR" "$REJECTED_DIR" + checkdirread "$INDEX_DIR" "$BACKUP_DIR" "$REJECTED_DIR" + + ### PACKAGE NAME ### if [ -z $RMNAME ]; then msgerr "Please state package name for remove." exit 1 fi - check_directory - - ### CHECK FOR LOCK FILE ### - if [ -f /tmp/spkg.lock ]; then - msgerr "Cant install/remove package simultaneously." - msgerr "remove ${color_yellow}/tmp/spkg.lock${color_reset} if no install/remove package process running." - exit 1 - fi - ### CHECK PACKAGE IN DATABASE ### if [ ! -d $INDEX_DIR/$RMNAME ]; then msg "Package ${color_red}$RMNAME${color_reset} not installed." exit 1 fi + ### CHECK FOR LOCK FILE ### + if [ -f /tmp/spkg.lock ]; then + msgerr "Cant install/remove package simultaneously." + msgerr "remove ${color_yellow}/tmp/spkg.lock${color_reset} if no install/remove package process running." + exit 1 + fi + ### GET NAME, VERSION, RELEASE FROM INSTALLED PACKAGE DATABASE ### getoldname $RMNAME diff --git a/scratch b/scratch index c30caee..103aea6 100755 --- a/scratch +++ b/scratch @@ -1,8 +1,41 @@ #!/bin/bash + +export LC_ALL=C . /usr/share/scratchpkg/functions || exit 1 -export LC_ALL=C +showinfo() { + + echo + echo " SCRATCHPKG CONFIG" + echo " -------------------------" + echo + echo "CFLAGS=$CFLAGS" + echo "CXXFLAGS=$CXXFLAGS" + echo "MAKEFLAGS=$MAKEFLAGS" + echo + echo "CONF_FILE=$CONF_FILE" + echo "BUILD_SCRIPT=$BUILD_SCRIPT" + echo + echo "ROOT_DIR=$ROOT_DIR" + echo "INDEX_DIR=$INDEX_DIR" + echo + echo "PACKAGE_DIR=$PACKAGE_DIR" + echo "SOURCE_DIR=$SOURCE_DIR" + echo "WORK_DIR=$WORK_DIR" + echo "BACKUP_DIR=$BACKUP_DIR" + echo "REJECTED_DIR=$REJECTED_DIR" + echo "LOG_DIR=$LOG_DIR" + echo "HOOK_DIR=$HOOK_DIR" + echo + echo "NO_EXTRACT=$NO_EXTRACT" + echo + echo "OPTIONS=${OPTIONS[@]}" + echo "PURGE_FILES=${PURGE_FILES[@]}" + echo "DOC_DIRS=${DOC_DIRS[@]}" + echo "MAN_DIRS=${MAN_DIRS[@]}" + +} listinstalled() { for installed in $(ls $INDEX_DIR); do @@ -532,6 +565,9 @@ parse_options() { -up|--update-ports) UPD_PORTS=yes ;; + --info) + SHOW_INFO=yes + ;; -c|--cat-port) if [ ! "$2" ]; then msg "Option '$1' require an argument (package to show its port script)" @@ -655,6 +691,14 @@ main() { nocolor fi + ### SHOW SCRATCHPKG INFO ### + if [ "$SHOW_INFO" ]; then + showinfo + exit 0 + fi + + checkdirexist "$INDEX_DIR" + ### UPDATE PORTS ### if [ $UPD_PORTS ]; then updports diff --git a/scratchpkg.conf b/scratchpkg.conf index e21ba53..c4e4279 100644 --- a/scratchpkg.conf +++ b/scratchpkg.conf @@ -1,19 +1,26 @@ -### CONFIGURATION FOR SCRATCHPKG (A SIMPLE PACKAGE MANAGER FOR LINUX FROM SCRATCH) ### +# +# Configuration file for scratchpkg +# CFLAGS="-O2 -march=x86-64 -pipe" CXXFLAGS="${CFLAGS}" MAKEFLAGS="-j2" -PACKAGE_DIR="/var/spkg/packages" -SOURCE_DIR="/var/spkg/sources" -WORK_DIR="/tmp" - PORT_REPO+=(/usr/ports/core) PORT_REPO+=(/usr/ports/xorg) PORT_REPO+=(/usr/ports/extra) +# PACKAGE_DIR="/var/spkg/packages" +# SOURCE_DIR="/var/spkg/sources" +# WORK_DIR="/tmp" +# BACKUP_DIR=/var/spkg/backup +# REJECTED_DIR=/var/spkg/rejected +# LOG_DIR=/var/spkg/log +# HOOK_DIR=/etc/hooks + +# OPTIONS=(libtool emptydirs strip docs purge zipman buildflags makeflags) +# PURGE_FILES=(usr/{,share/}info/dir) +# DOC_DIRS=(usr/{,local/}{,share/}{doc,gtk-doc} opt/*/{doc,gtk-doc}) +# MAN_DIRS=({usr{,/local}{,/share},opt/*}/man) + NO_EXTRACT=(usr/share/locale) -OPTIONS=(libtool emptydirs strip docs purge zipman buildflags makeflags) -PURGE_FILES=(usr/{,share/}info/dir) -DOC_DIRS=(usr/{,local/}{,share/}{doc,gtk-doc} opt/*/{doc,gtk-doc}) -MAN_DIRS=({usr{,/local}{,/share},opt/*}/man)