16 Commits
0.2 ... 0.5

Author SHA1 Message Date
emmett1
9b186bfd31 add logging, --log 2020-03-13 17:20:31 +08:00
emmett1
8e8c62d338 xchroot: add '-l' to umount 2020-03-05 17:32:54 +08:00
emmett1
c8b2eca5ba updated 2020-02-25 23:59:33 +08:00
emmett1
a23a22c659 fix scratch_upgrade 2020-02-25 18:07:35 +08:00
emmett1
9a06fbd474 fix pkgadd 2020-02-19 17:03:24 +08:00
emmett1
7a91fbdcd4 replace type with command 2020-02-19 15:23:42 +08:00
emmett1
00e55a2473 replace type with command 2020-02-19 00:39:34 +08:00
emmett1
0ee256b921 fix 2020-02-17 23:58:18 +08:00
emmett1
424c56f075 fix typo 2020-02-12 23:48:17 +08:00
emmett1
0440395881 fix 2020-02-10 17:44:48 +08:00
emmett1
6dddc034f9 updated 2020-02-10 00:18:14 +08:00
emmett1
4d8f539f45 updated 2020-02-08 23:44:01 +08:00
emmett1
cfaca4e65f updated 2020-02-08 17:50:37 +08:00
emmett1
0a9cfce26a add xchroot script 2020-02-07 23:31:35 +08:00
emmett1
5eeb974b17 updated 2020-02-07 23:22:30 +08:00
emmett1
2e26f7c2f0 add package alias function 2020-02-06 13:35:11 +08:00
10 changed files with 402 additions and 182 deletions

View File

@@ -14,10 +14,10 @@ install -d ${DESTDIR}${REVDEPD}
install -dm777 ${DESTDIR}${CACHE_DIR}/packages install -dm777 ${DESTDIR}${CACHE_DIR}/packages
install -dm777 ${DESTDIR}${CACHE_DIR}/sources install -dm777 ${DESTDIR}${CACHE_DIR}/sources
install -dm777 ${DESTDIR}${CACHE_DIR}/log
install -dm777 ${DESTDIR}${CACHE_DIR}/work install -dm777 ${DESTDIR}${CACHE_DIR}/work
install -dm777 ${DESTDIR}${CACHE_DIR}/log
install -m755 revdep pkgadd pkgdel pkgbuild pkgquery scratch updateconf ${DESTDIR}${BINDIR} install -m755 xchroot revdep pkgadd pkgdel pkgbuild pkgquery scratch updateconf ${DESTDIR}${BINDIR}
install -m644 scratchpkg.conf scratchpkg.repo ${DESTDIR}${CONFDIR} install -m644 scratchpkg.conf scratchpkg.repo scratchpkg.alias ${DESTDIR}${CONFDIR}
install -m644 revdep.conf ${DESTDIR}${REVDEPCONF} install -m644 revdep.conf ${DESTDIR}${REVDEPCONF}

129
pkgadd
View File

@@ -43,7 +43,7 @@ msgwarn() {
echo "==> WARNING: $1" echo "==> WARNING: $1"
} }
help() { help() {
cat << EOF cat << EOF
Usage: Usage:
$(basename $0) [ <options> <package.spkg.txz> ] $(basename $0) [ <options> <package.spkg.txz> ]
@@ -70,9 +70,9 @@ extract_opts() {
--*) opts="$opts $1";; --*) opts="$opts $1";;
-*) char=${#1}; count=1 -*) char=${#1}; count=1
while [ "$count" != "$char" ]; do while [ "$count" != "$char" ]; do
count=$((count+1)) count=$((count+1))
opts="$opts -$(echo $1 | cut -c $count)" opts="$opts -$(echo $1 | cut -c $count)"
done;; done;;
*) opts="$opts $1" *) opts="$opts $1"
esac esac
shift shift
@@ -93,12 +93,12 @@ parse_opts() {
-h | --help) SHOWHELP=yes ;; -h | --help) SHOWHELP=yes ;;
--no-preinstall) NO_PREINSTALL=yes ;; --no-preinstall) NO_PREINSTALL=yes ;;
--no-postinstall) NO_POSTINSTALL=yes ;; --no-postinstall) NO_POSTINSTALL=yes ;;
--no-preupgrade) NO_PREUPGRADE=yes ;; --no-preupgrade) NO_PREUPGRADE=yes ;;
--no-postupgrade) NO_POSTUPGRADE=yes ;; --no-postupgrade) NO_POSTUPGRADE=yes ;;
--no-backup) NO_BACKUP=yes ;; --no-backup) NO_BACKUP=yes ;;
--root=*) ROOT_DIR="${1#*=}" ;; --root=*) ROOT_DIR="${1#*=}" ;;
*.spkg.tar.*) PKGNAME="$(realpath $1)" ;; *.spkg.tar.*) PKGNAME="$(realpath $1)" ;;
*) msg "Invalid option! ($1)"; exit 1 ;; *) msg "Invalid option! ($1)"; exit 1 ;;
esac esac
shift shift
done done
@@ -107,30 +107,31 @@ parse_opts() {
ret() { ret() {
# remove lock and all tmp files on exit # remove lock and all tmp files on exit
rm -f "$LOCK_FILE" "$TMP_PKGADD" "$TMP_PKGINSTALL" "$TMP_CONFLICT" rm -f "$ROOT_DIR/$LOCK_FILE" "$TMP_PKGADD" "$TMP_PKGINSTALL" "$TMP_CONFLICT"
exit $1 exit $1
} }
isinstalled() { isinstalled() {
if [ -s "$INDEX_DIR/$1/.pkginfo" ] && grep -q "$1" "$INDEX_DIR/$1/.pkginfo"; then if [ -s "$ROOT_DIR/$INDEX_DIR/$1/.pkginfo" ] && grep -q "$1" "$ROOT_DIR/$INDEX_DIR/$1/.pkginfo"; then
return 0 return 0
else else
return 1 return 1
fi fi
} }
run_scripts() {
if [ "$ROOT_DIR" ]; then
xchroot "$ROOT_DIR" sh $@
else
sh $@
fi
}
parse_opts $(extract_opts "$@") parse_opts $(extract_opts "$@")
INDEX_DIR="$ROOT_DIR/var/lib/scratchpkg/index" SCRATCHPKG_DIR="var/lib/scratchpkg"
LOCK_FILE="$ROOT_DIR/var/lib/scratchpkg/spkg.lock" INDEX_DIR="$SCRATCHPKG_DIR/index"
LOCK_FILE="$SCRATCHPKG_DIR/spkg.lock"
# disable pre/post install/upgrade script when install to custom root location
if [ "$ROOT_DIR" != "" ]; then
NO_PREINSTALL=yes
NO_POSTINSTALL=yes
NO_PREUPGRADE=yes
NO_POSTUPGRADE=yes
fi
# show help page # show help page
[ "$SHOWHELP" ] || [ -z "$PKGNAME" ] && { [ "$SHOWHELP" ] || [ -z "$PKGNAME" ] && {
@@ -138,25 +139,26 @@ fi
ret 0 ret 0
} }
[ -d "$INDEX_DIR" ] || { [ -d "$ROOT_DIR/$INDEX_DIR" ] || {
msgerr "Package's database directory not exist! ($INDEX_DIR)" msgerr "Package's database directory not exist! ($ROOT_DIR/$INDEX_DIR)"
ret 1 ret 1
} }
# check for root access, non-root only allowed if use custom --root= location # check for root access
[ "$(id -u)" = "0" ] || [ "$ROOT_DIR" ] || { [ "$(id -u)" = "0" ] || {
msgerr "Installing package need root access!" msgerr "Installing package need root access!"
ret 1 ret 1
} }
# check for lock file # check for lock file
[ -f "$LOCK_FILE" ] && { [ -f "$ROOT_DIR/$LOCK_FILE" ] && {
msgerr "Cant install/remove package simultaneously." msgerr "Cant install/remove package simultaneously."
msgerr "remove '$LOCK_FILE' if no install/remove package process running." msgerr "remove '$ROOT_DIR/$LOCK_FILE' if no install/remove package process running."
exit 1
} }
touch "$LOCK_FILE" 2>/dev/null || { touch "$ROOT_DIR/$LOCK_FILE" 2>/dev/null || {
msgerr "Cant create lock file in '$LOCK_FILE'." msgerr "Cant create lock file in '$ROOT_DIR/$LOCK_FILE'."
exit 1 exit 1
} }
@@ -173,11 +175,11 @@ release=${noextname##*-}
noextname=${noextname%-*} noextname=${noextname%-*}
version=${noextname##*-} version=${noextname##*-}
name=${noextname%-*} name=${noextname%-*}
# get package information if installed # get package information if installed
if isinstalled $name; then if isinstalled $name; then
iversion=$(grep ^version $INDEX_DIR/$name/.pkginfo | cut -d " " -f3-) iversion=$(grep ^version $ROOT_DIR/$INDEX_DIR/$name/.pkginfo | cut -d " " -f3-)
irelease=$(grep ^release $INDEX_DIR/$name/.pkginfo | cut -d " " -f3-) irelease=$(grep ^release $ROOT_DIR/$INDEX_DIR/$name/.pkginfo | cut -d " " -f3-)
ALREADYINSTALLED=yes ALREADYINSTALLED=yes
fi fi
@@ -200,9 +202,9 @@ if [ "$UPGRADE_PKG" ] || [ "$REINSTALL_PKG" ]; then
fi fi
fi fi
TMP_PKGADD="/tmp/.tmp_pkgadd.$$" TMP_PKGADD="$ROOT_DIR/$SCRATCHPKG_DIR/.tmp_pkgadd"
TMP_PKGINSTALL="/tmp/.tmp_pkginstall.$$" TMP_PKGINSTALL="$ROOT_DIR/$SCRATCHPKG_DIR/.tmp_pkginstall"
TMP_CONFLICT="/tmp/.tmp_conflict.$$" TMP_CONFLICT="$ROOT_DIR/$SCRATCHPKG_DIR/.tmp_conflict"
# check integrity of package and save list file/dirs to install in the meantime # check integrity of package and save list file/dirs to install in the meantime
tar -tf $PKGNAME > $TMP_PKGADD 2>/dev/null || { tar -tf $PKGNAME > $TMP_PKGADD 2>/dev/null || {
@@ -225,7 +227,7 @@ if [ ! "$IGNORE_CONFLICT" ]; then
fi fi
if [ -e "$ROOT_DIR/$line" ] || [ -L "$ROOT_DIR/$line" ]; then if [ -e "$ROOT_DIR/$line" ] || [ -L "$ROOT_DIR/$line" ]; then
if [ "$UPGRADE_PKG" ] || [ "$REINSTALL_PKG" ]; then if [ "$UPGRADE_PKG" ] || [ "$REINSTALL_PKG" ]; then
if ! grep -Fqx "$line" "$INDEX_DIR/$name/.files"; then if ! grep -Fqx "$line" "$ROOT_DIR/$INDEX_DIR/$name/.files"; then
echo "$line" echo "$line"
touch "$TMP_CONFLICT" touch "$TMP_CONFLICT"
fi fi
@@ -244,19 +246,19 @@ fi
# pre-install and pre-upgrade script # pre-install and pre-upgrade script
if grep -qx .pkginstall $TMP_PKGADD; then if grep -qx .pkginstall $TMP_PKGADD; then
TMP_PKGINSTALL_SCRIPT="/tmp/.tmp_pkgadd_installscript.$$" TMP_PKGINSTALL_SCRIPT="$SCRATCHPKG_DIR/pkgadd_installscript"
tar -xf "$PKGNAME" .pkginstall -O > "$TMP_PKGINSTALL_SCRIPT" tar -xf "$PKGNAME" .pkginstall -O > "$ROOT_DIR/$TMP_PKGINSTALL_SCRIPT"
if [ ! "$NO_PREINSTALL" ] && [ ! "$UPGRADE_PKG" ]; then if [ ! "$NO_PREINSTALL" ] && [ ! "$UPGRADE_PKG" ]; then
(cd "$ROOT_DIR"/ (cd "$ROOT_DIR"/
sh "$TMP_PKGINSTALL_SCRIPT" pre-install "$version" run_scripts "$TMP_PKGINSTALL_SCRIPT" pre-install "$version"
) )
fi fi
if [ "$UPGRADE_PKG" ] && [ ! "$NO_PREUPGRADE" ]; then if [ "$UPGRADE_PKG" ] && [ ! "$NO_PREUPGRADE" ]; then
(cd "$ROOT_DIR"/ (cd "$ROOT_DIR"/
sh "$TMP_PKGINSTALL_SCRIPT" pre-upgrade "$version" "$iversion" run_scripts "$TMP_PKGINSTALL_SCRIPT" pre-upgrade "$version" "$iversion"
) )
fi fi
rm -f "$TMP_PKGINSTALL_SCRIPT" rm -f "$ROOT_DIR/$TMP_PKGINSTALL_SCRIPT"
fi fi
# exclude .pkg* files when extract into system # exclude .pkg* files when extract into system
@@ -284,17 +286,18 @@ done
# remove old files from old package that not exist in new package # remove old files from old package that not exist in new package
if [ "$UPGRADE_PKG" ] || [ "$REINSTALL_PKG" ]; then if [ "$UPGRADE_PKG" ] || [ "$REINSTALL_PKG" ]; then
rmlist_file="/tmp/.rmlist_file.$$" rmlist_file="$ROOT_DIR/$SCRATCHPKG_DIR/.rmlist_file"
rmlist_dir="/tmp/.rmlist_dir.$$" rmlist_dir="$ROOT_DIR/$SCRATCHPKG_DIR/.rmlist_dir"
reserve_dir="/tmp/.reserve_dir.$$" reserve_dir="$ROOT_DIR/$SCRATCHPKG_DIR/.reserve_dir"
rmlist_all="/tmp/.rmlist_all.$$" rmlist_all="$ROOT_DIR/$SCRATCHPKG_DIR/.rmlist_all"
grep '/$' $INDEX_DIR/*/.files | grep -v $INDEX_DIR/$name/.files | awk -F : '{print $2}' | sort | uniq > $reserve_dir # get list reserved dirs grep '/$' $ROOT_DIR/$INDEX_DIR/*/.files \
grep -Fxv -f "$TMP_PKGINSTALL" $INDEX_DIR/$name/.files > $rmlist_all # get list files and dirs to remove | grep -v $ROOT_DIR/$INDEX_DIR/$name/.files \
grep -v '/$' "$rmlist_all" | tac > "$rmlist_file" # get files only to remove | awk -F : '{print $2}' \
grep -Fxv -f "$reserve_dir" "$rmlist_all" | grep '/$' | tac > "$rmlist_dir" # get dirs only (safe) to remove | sort \
# remove pseudo fs from remove list | uniq > $reserve_dir # get list reserved dirs
#sed '/^dev\//d;/^sys\//d;/^proc\//d;/^run\//d;/^tmp\//d' -i $rmlist_file grep -Fxv -f "$TMP_PKGINSTALL" $ROOT_DIR/$INDEX_DIR/$name/.files > $rmlist_all # get list files and dirs to remove
#sed '/^dev\//d;/^sys\//d;/^proc\//d;/^run\//d;/^tmp\//d' -i $rmlist_dir grep -v '/$' "$rmlist_all" | tac > "$rmlist_file" # get files only to remove
grep -Fxv -f "$reserve_dir" "$rmlist_all" | grep '/$' | tac > "$rmlist_dir" # get dirs only (safe) to remove
(cd "$ROOT_DIR"/ (cd "$ROOT_DIR"/
[ -s $rmlist_file ] && xargs -a $rmlist_file -d'\n' rm $VERBOSE_INSTALL [ -s $rmlist_file ] && xargs -a $rmlist_file -d'\n' rm $VERBOSE_INSTALL
[ -s $rmlist_dir ] && xargs -a $rmlist_dir -d'\n' rmdir $VERBOSE_INSTALL [ -s $rmlist_dir ] && xargs -a $rmlist_dir -d'\n' rmdir $VERBOSE_INSTALL
@@ -303,30 +306,30 @@ if [ "$UPGRADE_PKG" ] || [ "$REINSTALL_PKG" ]; then
fi fi
# register package into database # register package into database
rm -fr "$INDEX_DIR/$name" rm -fr "$ROOT_DIR/$INDEX_DIR/$name"
mkdir "$INDEX_DIR/$name" mkdir "$ROOT_DIR/$INDEX_DIR/$name"
echo "name = $name" > "$INDEX_DIR/$name/.pkginfo" echo "name = $name" > "$ROOT_DIR/$INDEX_DIR/$name/.pkginfo"
echo "version = $version" >> "$INDEX_DIR/$name/.pkginfo" echo "version = $version" >> "$ROOT_DIR/$INDEX_DIR/$name/.pkginfo"
echo "release = $release" >> "$INDEX_DIR/$name/.pkginfo" echo "release = $release" >> "$ROOT_DIR/$INDEX_DIR/$name/.pkginfo"
install -m644 "$TMP_PKGINSTALL" "$INDEX_DIR/$name/.files" install -m644 "$TMP_PKGINSTALL" "$ROOT_DIR/$INDEX_DIR/$name/.files"
for ii in $(grep ^.pkg* $TMP_PKGADD); do for ii in $(grep ^.pkg* $TMP_PKGADD); do
pkgfiles="$pkgfiles $ii" pkgfiles="$pkgfiles $ii"
done done
if [ "$pkgfiles" ]; then if [ "$pkgfiles" ]; then
tar -x -f "$PKGNAME" -C "$INDEX_DIR/$name" $pkgfiles >/dev/null 2>&1 tar -x -f "$PKGNAME" -C "$ROOT_DIR/$INDEX_DIR/$name" $pkgfiles >/dev/null 2>&1
fi fi
if [ -f "$INDEX_DIR/$name/.pkginstall" ]; then if [ -f "$ROOT_DIR/$INDEX_DIR/$name/.pkginstall" ]; then
if [ ! "$NO_POSTINSTALL" ] && [ ! "$UPGRADE_PKG" ]; then if [ ! "$NO_POSTINSTALL" ] && [ ! "$UPGRADE_PKG" ]; then
(cd "$ROOT_DIR"/ (cd "$ROOT_DIR"/
sh "$INDEX_DIR/$name/.pkginstall" post-install "$version" run_scripts "$INDEX_DIR/$name/.pkginstall" post-install "$version"
) )
fi fi
if [ "$UPGRADE_PKG" ] && [ ! "$NO_POSTUPGRADE" ]; then if [ "$UPGRADE_PKG" ] && [ ! "$NO_POSTUPGRADE" ]; then
(cd "$ROOT_DIR"/ (cd "$ROOT_DIR"/
sh "$INDEX_DIR/$name/.pkginstall" post-upgrade "$version" "$iversion" run_scripts "$INDEX_DIR/$name/.pkginstall" post-upgrade "$version" "$iversion"
) )
fi fi
fi fi

View File

@@ -98,9 +98,14 @@ download_src() {
FILENAME=$(basename $FILE) FILENAME=$(basename $FILE)
SRCURL=$FILE SRCURL=$FILE
fi fi
[ "$DOWNLOAD_PROG" = "auto" ] && {
command -v curl >/dev/null && DOWNLOAD_PROG=curl
command -v wget >/dev/null && DOWNLOAD_PROG=wget
}
case $DOWNLOAD_PROG in case $DOWNLOAD_PROG in
curl) DLCMD="curl -C - -L --fail --ftp-pasv --retry 3 --retry-delay 3 -o $SOURCE_DIR/$FILENAME.partial $CURL_OPTS" ;; curl) DLCMD="curl -C - -L --fail --ftp-pasv --retry 3 --retry-delay 3 -o $SOURCE_DIR/$FILENAME.partial $CURL_OPTS" ;;
wget) DLCMD="wget -c --passive-ftp --no-directories --tries=3 --waitretry=3 --output-document=$SOURCE_DIR/$FILENAME.partial $WGET_OPTS" ;; wget) DLCMD="wget -c --passive-ftp --no-directories --tries=3 --waitretry=3 --output-document=$SOURCE_DIR/$FILENAME.partial $WGET_OPTS" ;;
*) msgerr "No download agent found"; abort 1;;
esac esac
if [ "$FILENAME" != "$FILE" ]; then if [ "$FILENAME" != "$FILE" ]; then
if [ ! -f "$SOURCE_DIR/$FILENAME" ] || [ "$REDOWNLOAD_SOURCE" ]; then if [ ! -f "$SOURCE_DIR/$FILENAME" ] || [ "$REDOWNLOAD_SOURCE" ]; then
@@ -158,7 +163,7 @@ prepare_src() {
if [ "$FILENAME" != "$FILE" ] && [ "$nxt" != 1 ]; then if [ "$FILENAME" != "$FILE" ] && [ "$nxt" != 1 ]; then
case $FILENAME in case $FILENAME in
*.tar|*.tar.gz|*.tar.Z|*.tgz|*.tar.bz2|*.tbz2|*.tar.xz|*.txz|*.tar.lzma|*.zip|*.rpm) *.tar|*.tar.gz|*.tar.Z|*.tgz|*.tar.bz2|*.tbz2|*.tar.xz|*.txz|*.tar.lzma|*.zip|*.rpm)
if [ $(type -p bsdtar) ]; then if [ $(command -v bsdtar) ]; then
COMMAND="bsdtar -p -o -C $SRC -xf $FILENAME" COMMAND="bsdtar -p -o -C $SRC -xf $FILENAME"
else else
COMMAND="tar -p -o -C $SRC -xf $FILENAME" COMMAND="tar -p -o -C $SRC -xf $FILENAME"
@@ -291,6 +296,24 @@ backupconf() {
done done
} }
removedocs() {
for i in doc gtk-doc info; do
rm -fr \
usr/share/$i \
usr/$i \
usr/local/$i \
usr/local/share/$i
done
}
removelocales() {
rm -fr \
usr/share/locale \
usr/locale \
usr/local/locale \
usr/local/share/locale
}
packaging() { packaging() {
for FILE in $INCLUDEINPKG; do for FILE in $INCLUDEINPKG; do
if [ -f $FILE ]; then if [ -f $FILE ]; then
@@ -316,6 +339,8 @@ packaging() {
[ "$KEEP_LIBTOOL" = 0 ] && removelibtool [ "$KEEP_LIBTOOL" = 0 ] && removelibtool
[ "$STRIP_BINARY" = 1 ] && strip_files [ "$STRIP_BINARY" = 1 ] && strip_files
[ "$ZIP_MAN" = 1 ] && compressinfomanpages [ "$ZIP_MAN" = 1 ] && compressinfomanpages
[ "$KEEP_DOCS" = 0 ] && removedocs
[ "$KEEP_LOCALES" = 0 ] && removelocales
if [ "${#backup[@]}" -gt 0 ]; then if [ "${#backup[@]}" -gt 0 ]; then
backupconf backupconf
@@ -395,7 +420,7 @@ check_buildscript() {
elif [ -z "$release" ]; then elif [ -z "$release" ]; then
msgerr "'release' is empty!" msgerr "'release' is empty!"
exit 1 exit 1
elif [ "$(type -t build)" != "function" ]; then elif [ ! "$(command -v build)" ]; then
msgerr "'build' function not exist!" msgerr "'build' function not exist!"
exit 1 exit 1
elif echo "$version" | grep -q '-'; then elif echo "$version" | grep -q '-'; then
@@ -427,6 +452,10 @@ set_options() {
!makeflags) MAKE_FLAGS=0 ;; !makeflags) MAKE_FLAGS=0 ;;
checksum) CHECK_MDSUM=1 ;; checksum) CHECK_MDSUM=1 ;;
!checksum) CHECK_MDSUM=0 ;; !checksum) CHECK_MDSUM=0 ;;
docs) KEEP_DOCS=1 ;;
!docs) KEEP_DOCS=0 ;;
locales) KEEP_LOCALES=1 ;;
!locales) KEEP_LOCALES=0 ;;
esac esac
done done
} }
@@ -641,6 +670,7 @@ main() {
abort 0 abort 0
fi fi
else else
msg "Building '$name-$version-$release'..."
download_src download_src
prepare_src prepare_src
run_build run_build
@@ -666,10 +696,10 @@ PKGBUILD_BSCRIPT="spkgbuild"
SOURCE_DIR="/var/cache/scratchpkg/sources" SOURCE_DIR="/var/cache/scratchpkg/sources"
PACKAGE_DIR="/var/cache/scratchpkg/packages" PACKAGE_DIR="/var/cache/scratchpkg/packages"
WORK_DIR="/var/cache/scratchpkg/work" WORK_DIR="/var/cache/scratchpkg/work"
DOWNLOAD_PROG="wget" DOWNLOAD_PROG="auto"
COMPRESSION_MODE="xz" COMPRESSION_MODE="xz"
OPTIONS="!libtool emptydirs strip zipman buildflags makeflags checksum" OPTIONS="!libtool emptydirs strip zipman buildflags makeflags checksum !docs !locales"
INCLUDEINPKG="install readme mkdirs" INCLUDEINPKG="install readme mkdirs"

84
pkgdel
View File

@@ -74,7 +74,7 @@ extract_opts() {
echo $opts echo $opts
} }
parse_opts() { parse_opts() {
if [ -z "$1" ]; then if [ -z "$1" ]; then
SHOWHELP=yes SHOWHELP=yes
else else
@@ -83,62 +83,64 @@ parse_opts() {
-h | --help) SHOWHELP=yes ;; -h | --help) SHOWHELP=yes ;;
-v | --verbose) VERBOSE_REMOVE="-v" ;; -v | --verbose) VERBOSE_REMOVE="-v" ;;
--no-preremove) NO_PREREMOVE=yes ;; --no-preremove) NO_PREREMOVE=yes ;;
--no-postremove) NO_POSTREMOVE=yes ;; --no-postremove) NO_POSTREMOVE=yes ;;
--root=*) ROOT_DIR="${1#*=}" ;; --root=*) ROOT_DIR="${1#*=}" ;;
-*) msg "Invalid option: ($1)"; exit 1 ;; -*) msg "Invalid option: ($1)"; exit 1 ;;
*) RMNAME=$1 ;; *) RMNAME=$1 ;;
esac esac
shift shift
done done
fi fi
} }
ret() { ret() {
# remove lock file on exit # remove lock file on exit
rm -f "$LOCK_FILE" "$reserve" "$dirs" "$remove" "$files" rm -f "$ROOT_DIR/$LOCK_FILE" "$reserve" "$dirs" "$remove" "$files"
exit $1 exit $1
} }
isinstalled() { isinstalled() {
if [ -s "$INDEX_DIR/$1/.pkginfo" ] && grep -q "$1" "$INDEX_DIR/$1/.pkginfo"; then if [ -s "$ROOT_DIR/$INDEX_DIR/$1/.pkginfo" ] && grep -q "$1" "$ROOT_DIR/$INDEX_DIR/$1/.pkginfo"; then
return 0 return 0
else else
return 1 return 1
fi fi
} }
run_scripts() {
if [ "$ROOT_DIR" ]; then
xchroot "$ROOT_DIR" sh $@
else
sh $@
fi
}
parse_opts $(extract_opts "$@") parse_opts $(extract_opts "$@")
INDEX_DIR="$ROOT_DIR/var/lib/scratchpkg/index" INDEX_DIR="var/lib/scratchpkg/index"
LOCK_FILE="$ROOT_DIR/var/lib/scratchpkg/spkg.lock" LOCK_FILE="var/lib/scratchpkg/spkg.lock"
# disable pre/post remove script when remove from custom root location
if [ "$ROOT_DIR" != "" ]; then
NO_PREREMOVE=yes
NO_POSTREMOVE=yes
fi
# show help page # show help page
[ "$SHOWHELP" ] || [ -z "$RMNAME" ] && { [ "$SHOWHELP" ] || [ -z "$RMNAME" ] && {
help help
ret 0 ret 0
} }
# check for root access, non-root only allowed if use custom --root= location # check for root access
[ "$(id -u)" = "0" ] || [ "$ROOT_DIR" ] || { [ "$(id -u)" = "0" ] || {
echo "Removing package need root access!" echo "Removing package need root access!"
ret 1 ret 1
} }
# check for lock file # check for lock file
[ -f "$LOCK_FILE" ] && { [ -f "$ROOT_DIR/$LOCK_FILE" ] && {
msgerr "Cant install/remove package simultaneously." msgerr "Cant install/remove package simultaneously."
msgerr "remove '$LOCK_FILE' if no install/remove package process running." msgerr "remove '$ROOT_DIR/$LOCK_FILE' if no install/remove package process running."
exit 1 exit 1
} }
touch "$LOCK_FILE" 2>/dev/null || { touch "$ROOT_DIR/$LOCK_FILE" 2>/dev/null || {
msgerr "Cant create lock file in '$LOCK_FILE'" msgerr "Cant create lock file in '$ROOT_DIR/$LOCK_FILE'"
exit 1 exit 1
} }
@@ -147,32 +149,36 @@ if ! isinstalled "$RMNAME"; then
ret 1 ret 1
fi fi
name=$(grep ^name $INDEX_DIR/$RMNAME/.pkginfo | cut -d " " -f3-) name=$(grep ^name $ROOT_DIR/$INDEX_DIR/$RMNAME/.pkginfo | cut -d " " -f3-)
version=$(grep ^version $INDEX_DIR/$RMNAME/.pkginfo | cut -d " " -f3-) version=$(grep ^version $ROOT_DIR/$INDEX_DIR/$RMNAME/.pkginfo | cut -d " " -f3-)
release=$(grep ^release $INDEX_DIR/$RMNAME/.pkginfo | cut -d " " -f3-) release=$(grep ^release $ROOT_DIR/$INDEX_DIR/$RMNAME/.pkginfo | cut -d " " -f3-)
if [ -z $name ] && [ -z $version ] && [ -z $release ]; then if [ -z "$name" ] && [ -z "$version" ] && [ -z "$release" ]; then
msgerr "Package '$RMNAME' not installed but exist in database." msgerr "Package '$RMNAME' not installed but exist in database."
ret 1 ret 1
fi fi
# create list for reserve and remove (dirs and files) # create list for reserve and remove (dirs and files)
reserve="/tmp/.pkgdel_reserve.$$" reserve="$ROOT_DIR/$SCRATCHPKG_DIR/.pkgdel_reserve"
remove="/tmp/.pkgdel_remove.$$" remove="$ROOT_DIR/$SCRATCHPKG_DIR/.pkgdel_remove"
dirs="/tmp/.pkgdel_dirs.$$" dirs="$ROOT_DIR/$SCRATCHPKG_DIR/.pkgdel_dirs"
files="/tmp/.pkgdel_files.$$" files="$ROOT_DIR/$SCRATCHPKG_DIR/.pkgdel_files"
grep '/$' $INDEX_DIR/*/.files | grep -v "$INDEX_DIR/$name" | awk -F : '{print $2}' | sort | uniq > "$reserve" grep '/$' $ROOT_DIR/$INDEX_DIR/*/.files \
grep '/$' "$INDEX_DIR/$name/.files" > "$remove" | grep -v "$ROOT_DIR/$INDEX_DIR/$name" \
| awk -F : '{print $2}' \
| sort \
| uniq > "$reserve"
grep '/$' "$ROOT_DIR/$INDEX_DIR/$name/.files" > "$remove"
grep -Fxv -f "$reserve" "$remove" | tac > "$dirs" grep -Fxv -f "$reserve" "$remove" | tac > "$dirs"
grep -v '/$' "$INDEX_DIR/$name/.files" | tac >> "$files" grep -v '/$' "$ROOT_DIR/$INDEX_DIR/$name/.files" | tac >> "$files"
echo "remove: $name-$version-$release..." echo "remove: $name-$version-$release..."
# pre-remove script # pre-remove script
if [ ! "$NO_PREREMOVE" ] && [ -f "$INDEX_DIR/$name/.pkginstall" ]; then if [ ! "$NO_PREREMOVE" ] && [ -f "$ROOT_DIR/$INDEX_DIR/$name/.pkginstall" ]; then
(cd "$ROOT_DIR"/ (cd "$ROOT_DIR"/
sh "$INDEX_DIR/$name/.pkginstall" pre-remove "$version" run_scripts "$INDEX_DIR/$name/.pkginstall" pre-remove "$version"
) )
fi fi
@@ -184,15 +190,15 @@ fi
rm -f "$reserve" "$dirs" "$remove" "$files" rm -f "$reserve" "$dirs" "$remove" "$files"
# post-remove script # post-remove script
if [ ! "$NO_POSTREMOVE" ] && [ -f "$INDEX_DIR/$name/.pkginstall" ]; then if [ ! "$NO_POSTREMOVE" ] && [ -f "$ROOT_DIR/$INDEX_DIR/$name/.pkginstall" ]; then
(cd "$ROOT_DIR"/ (cd "$ROOT_DIR"/
sh "$INDEX_DIR/$name/.pkginstall" post-remove "$version" run_scripts "$INDEX_DIR/$name/.pkginstall" post-remove "$version"
) )
fi fi
# remove from database # remove from database
rm -rf "$INDEX_DIR/$name" rm -rf "$ROOT_DIR/$INDEX_DIR/$name"
# running ldconfig # running ldconfig
if [ -x "$ROOT_DIR"/sbin/ldconfig ]; then if [ -x "$ROOT_DIR"/sbin/ldconfig ]; then

View File

@@ -67,13 +67,27 @@ installed_pkg_info() {
fi fi
} }
deps_alias() {
[ -f $ALIAS_FILE ] || {
echo $@
return
}
while [ "$1" ]; do
getalias=$(grep -w ^$1 $ALIAS_FILE | awk '{print $2}')
echo ${getalias:-$1}
shift
done
unset getalias
}
getdepends() { getdepends() {
ppath=$(getportpath $1) || return 0 ppath=$(getportpath $1) || return 0
grep "^# depends[[:blank:]]*:" $ppath/$BUILD_SCRIPT \ deps=$(grep "^# depends[[:blank:]]*:" $ppath/$BUILD_SCRIPT \
| sed 's/^# depends[[:blank:]]*:[[:blank:]]*//' \ | sed 's/^# depends[[:blank:]]*:[[:blank:]]*//' \
| tr ' ' '\n' \ | tr ' ' '\n' \
| awk '!a[$0]++' \ | awk '!a[$0]++' \
| sed 's/,//' | sed 's/,//')
deps_alias $deps
} }
getportpath() { getportpath() {
@@ -320,6 +334,7 @@ print_runhelp_msg() {
BUILD_SCRIPT="spkgbuild" BUILD_SCRIPT="spkgbuild"
INDEX_DIR="/var/lib/scratchpkg/index" INDEX_DIR="/var/lib/scratchpkg/index"
REPO_FILE="/etc/scratchpkg.repo" REPO_FILE="/etc/scratchpkg.repo"
ALIAS_FILE="/etc/scratchpkg.alias"
if [ -f "$REPO_FILE" ]; then if [ -f "$REPO_FILE" ]; then
for repodir in $(grep -Ev '^(#|$)' "$REPO_FILE" | awk '{print $1}'); do for repodir in $(grep -Ev '^(#|$)' "$REPO_FILE" | awk '{print $1}'); do
@@ -335,7 +350,7 @@ fi
shift shift
if [ $(type -t pkg_$opts) ]; then if [ $(command -v pkg_$opts) ]; then
pkg_$opts "$@" pkg_$opts "$@"
else else
print_runhelp_msg print_runhelp_msg

197
scratch
View File

@@ -99,13 +99,27 @@ allinstalled() {
grep ^name "$INDEX_DIR"/*/.pkginfo | awk '{print $3}' grep ^name "$INDEX_DIR"/*/.pkginfo | awk '{print $3}'
} }
deps_alias() {
[ -f $ALIAS_FILE ] || {
echo $@
return
}
while [ "$1" ]; do
getalias=$(grep -w ^$1 $ALIAS_FILE | awk '{print $2}')
echo ${getalias:-$1}
shift
done
unset getalias
}
get_depends() { get_depends() {
ppath=$(getportpath $1) || return 0 ppath=$(getportpath $1) || return 0
grep "^# depends[[:blank:]]*:" $ppath/$BUILD_SCRIPT \ deps=$(grep "^# depends[[:blank:]]*:" $ppath/$BUILD_SCRIPT \
| sed 's/^# depends[[:blank:]]*:[[:blank:]]*//' \ | sed 's/^# depends[[:blank:]]*:[[:blank:]]*//' \
| tr ' ' '\n' \ | tr ' ' '\n' \
| awk '!a[$0]++' \ | awk '!a[$0]++' \
| sed 's/,//' | sed 's/,//')
deps_alias $deps
} }
confirm() { confirm() {
@@ -119,7 +133,7 @@ confirm() {
} }
checktool() { checktool() {
if ! type -p $1 >/dev/null; then if ! command -v $1 >/dev/null; then
msgerr "'$1' not exist in your system!" msgerr "'$1' not exist in your system!"
exit 1 exit 1
fi fi
@@ -272,37 +286,37 @@ post_triggers() {
done done
fi fi
if [ "$trig_11" = 1 ] && [ $(type -p fc-cache) ]; then if [ "$trig_11" = 1 ] && [ $(command -v fc-cache) ]; then
echo "trigger: Updating fontconfig cache..." echo "trigger: Updating fontconfig cache..."
fc-cache -s fc-cache -s
fi fi
if [ "$trig_10" = 1 ] && [ $(type -p gdk-pixbuf-query-loaders) ]; then if [ "$trig_10" = 1 ] && [ $(command -v gdk-pixbuf-query-loaders) ]; then
echo "trigger: Probing GDK-Pixbuf loader modules..." echo "trigger: Probing GDK-Pixbuf loader modules..."
gdk-pixbuf-query-loaders --update-cache gdk-pixbuf-query-loaders --update-cache
fi fi
if [ "$trig_9" = 1 ] && [ $(type -p gio-querymodules) ]; then if [ "$trig_9" = 1 ] && [ $(command -v gio-querymodules) ]; then
echo "trigger: Updating GIO module cache..." echo "trigger: Updating GIO module cache..."
gio-querymodules /usr/lib/gio/modules gio-querymodules /usr/lib/gio/modules
fi fi
if [ "$trig_8" = 1 ] && [ $(type -p glib-compile-schemas) ]; then if [ "$trig_8" = 1 ] && [ $(command -v glib-compile-schemas) ]; then
echo "trigger: Compiling GSettings XML schema files..." echo "trigger: Compiling GSettings XML schema files..."
glib-compile-schemas /usr/share/glib-2.0/schemas glib-compile-schemas /usr/share/glib-2.0/schemas
fi fi
if [ "$trig_7" = 1 ] && [ $(type -p gtk-query-immodules-2.0) ]; then if [ "$trig_7" = 1 ] && [ $(command -v gtk-query-immodules-2.0) ]; then
echo "trigger: Probing GTK2 input method modules..." echo "trigger: Probing GTK2 input method modules..."
gtk-query-immodules-2.0 --update-cache gtk-query-immodules-2.0 --update-cache
fi fi
if [ "$trig_6" = 1 ] && [ $(type -p gtk-query-immodules-3.0) ]; then if [ "$trig_6" = 1 ] && [ $(command -v gtk-query-immodules-3.0) ]; then
echo "trigger: Probing GTK3 input method modules..." echo "trigger: Probing GTK3 input method modules..."
gtk-query-immodules-3.0 --update-cache gtk-query-immodules-3.0 --update-cache
fi fi
if [ "$trig_5" = 1 ] && [ $(type -p gtk-update-icon-cache) ]; then if [ "$trig_5" = 1 ] && [ $(command -v gtk-update-icon-cache) ]; then
echo "trigger: Updating icon theme caches..." echo "trigger: Updating icon theme caches..."
for dir in /usr/share/icons/* ; do for dir in /usr/share/icons/* ; do
if [ -e $dir/index.theme ]; then if [ -e $dir/index.theme ]; then
@@ -314,12 +328,12 @@ post_triggers() {
done done
fi fi
if [ "$trig_4" = 1 ] && [ $(type -p udevadm) ]; then if [ "$trig_4" = 1 ] && [ $(command -v udevadm) ]; then
echo "trigger: Updating hardware database..." echo "trigger: Updating hardware database..."
udevadm hwdb --update udevadm hwdb --update
fi fi
if [ "$trig_3" = 1 ] && [ $(type -p mkfontdir) ] && [ $(type -p mkfontscale) ]; then if [ "$trig_3" = 1 ] && [ $(command -v mkfontdir) ] && [ $(command -v mkfontscale) ]; then
echo "trigger: Updating X fontdir indices..." echo "trigger: Updating X fontdir indices..."
for dir in $(find /usr/share/fonts -maxdepth 1 -type d \( ! -path /usr/share/fonts -a ! -name X11 \)) /usr/share/fonts/X11/*; do for dir in $(find /usr/share/fonts -maxdepth 1 -type d \( ! -path /usr/share/fonts -a ! -name X11 \)) /usr/share/fonts/X11/*; do
rm -f $dir/fonts.scale $dir/fonts.dir $dir/.uuid rm -f $dir/fonts.scale $dir/fonts.dir $dir/.uuid
@@ -330,12 +344,12 @@ post_triggers() {
done done
fi fi
if [ "$trig_2" = 1 ] && [ $(type -p update-desktop-database) ]; then if [ "$trig_2" = 1 ] && [ $(command -v update-desktop-database) ]; then
echo "trigger: Updating desktop file MIME type cache..." echo "trigger: Updating desktop file MIME type cache..."
update-desktop-database --quiet update-desktop-database --quiet
fi fi
if [ "$trig_1" = 1 ] && [ $(type -p update-mime-database) ]; then if [ "$trig_1" = 1 ] && [ $(command -v update-mime-database) ]; then
echo "trigger: Updating the MIME type database..." echo "trigger: Updating the MIME type database..."
update-mime-database /usr/share/mime update-mime-database /usr/share/mime
fi fi
@@ -467,6 +481,7 @@ scratch_build() {
while [ "$1" ]; do while [ "$1" ]; do
case $1 in case $1 in
-i|-u|-r|-g|-p) ;; -i|-u|-r|-g|-p) ;;
--log) LOGBUILD=1;;
-*) OPTS="$OPTS $1";; -*) OPTS="$OPTS $1";;
*) PKGNAME="$PKGNAME $1";; *) PKGNAME="$PKGNAME $1";;
esac esac
@@ -483,7 +498,12 @@ scratch_build() {
} }
cd $ppath cd $ppath
settermtitle "Building $pkg..." settermtitle "Building $pkg..."
pkgbuild $OPTS || { if [ "$LOGBUILD" = 1 ]; then
pkgbuild $OPTS | tee $LOG_DIR/$pkg.log
else
pkgbuild $OPTS
fi
[ "$?" = 0 ] || {
settermtitle "Building $pkg failed." settermtitle "Building $pkg failed."
return 1 return 1
} }
@@ -500,6 +520,7 @@ scratch_install() {
-r|--reinstall) REINSTALL=1;; -r|--reinstall) REINSTALL=1;;
-y|--yes) NOCONFIRM=1;; -y|--yes) NOCONFIRM=1;;
-n|--no-dep) NO_DEP=1;; -n|--no-dep) NO_DEP=1;;
--log) LOGBUILD=1;;
--exclude=*) EXOPT=$1;; --exclude=*) EXOPT=$1;;
-*) OPTS="$OPTS $1";; -*) OPTS="$OPTS $1";;
*) PKGNAME="$PKGNAME $1";; *) PKGNAME="$PKGNAME $1";;
@@ -521,7 +542,12 @@ scratch_install() {
else else
cd $(getportpath $ii) cd $(getportpath $ii)
settermtitle "Reinstalling $ii..." settermtitle "Reinstalling $ii..."
pkgbuild $OPTS -r || { if [ "$LOGBUILD" = 1 ]; then
pkgbuild $OPTS -r | tee $LOG_DIR/$ii.log
else
pkgbuild $OPTS -r
fi
[ "$?" = 0 ] || {
error=1 error=1
break break
} }
@@ -545,7 +571,12 @@ scratch_install() {
else else
cd $(getportpath $ii) cd $(getportpath $ii)
settermtitle "Installing $ii..." settermtitle "Installing $ii..."
pkgbuild -i $OPTS || { if [ "$LOGBUILD" = 1 ]; then
pkgbuild $OPTS -i | tee $LOG_DIR/$ii.log
else
pkgbuild $OPTS -i
fi
[ "$?" = 0 ] || {
error=1 error=1
break break
} }
@@ -592,7 +623,12 @@ scratch_install() {
if portpathh=$(getportpath $int); then if portpathh=$(getportpath $int); then
cd $portpathh cd $portpathh
settermtitle "[ $count/$total ] installing $int..." settermtitle "[ $count/$total ] installing $int..."
pkgbuild -i $OPTS || { if [ "$LOGBUILD" = 1 ]; then
pkgbuild $OPTS -i | tee $LOG_DIR/$int.log
else
pkgbuild $OPTS -i
fi
[ "$?" = 0 ] || {
error=1 error=1
count=$(( count - 1 )) count=$(( count - 1 ))
break break
@@ -686,6 +722,7 @@ scratch_sysup() {
-i|-u|-r) ;; -i|-u|-r) ;;
-y|--yes) NOCONFIRM=1;; -y|--yes) NOCONFIRM=1;;
-n|--no-dep) NODEP=1;; -n|--no-dep) NODEP=1;;
--log) LOGBUILD=1;;
--exclude=*) EXOPT=$1;; --exclude=*) EXOPT=$1;;
-*) OPTS="$OPTS $1";; -*) OPTS="$OPTS $1";;
esac esac
@@ -742,14 +779,24 @@ scratch_sysup() {
cd $(getportpath $inst) cd $(getportpath $inst)
if ! isinstalled $inst; then if ! isinstalled $inst; then
settermtitle "[ $count/$total ] Installing $inst..." settermtitle "[ $count/$total ] Installing $inst..."
pkgbuild -i $OPTS || { if [ "$LOGBUILD" = 1 ]; then
pkgbuild $OPTS -i | tee $LOG_DIR/$inst.log
else
pkgbuild $OPTS -i
fi
[ "$?" = 0 ] || {
error=1 error=1
count=$(( count - 1 )) count=$(( count - 1 ))
break break
} }
else else
settermtitle "[ $count/$total ] Upgrading $inst..." settermtitle "[ $count/$total ] Upgrading $inst..."
pkgbuild -u $OPTS || { if [ "$LOGBUILD" = 1 ]; then
pkgbuild $OPTS -u | tee $LOG_DIR/$inst.log
else
pkgbuild $OPTS-u
fi
[ "$?" = 0 ] || {
error=1 error=1
count=$(( count - 1 )) count=$(( count - 1 ))
break break
@@ -771,6 +818,7 @@ scratch_upgrade() {
-i|-r) ;; -i|-r) ;;
-y|--yes) NOCONFIRM=1;; -y|--yes) NOCONFIRM=1;;
-d|--no-dep) NO_DEP=1;; -d|--no-dep) NO_DEP=1;;
--log) LOGBUILD=1;;
--exclude=*) EXOPT=$1;; --exclude=*) EXOPT=$1;;
-*) OPTS="$OPTS $1";; -*) OPTS="$OPTS $1";;
*) PKGNAME="$PKGNAME $1";; *) PKGNAME="$PKGNAME $1";;
@@ -783,78 +831,89 @@ scratch_upgrade() {
} }
for pkg in $PKGNAME; do for pkg in $PKGNAME; do
if ! isinstalled $pkg; then if ! isinstalled $pkg; then
msgerr "Package '$pkg' not installed." echo "Package '$pkg' not installed."
continue continue
elif [ ! $(getportpath $pkg) ]; then elif [ ! $(getportpath $pkg) ]; then
msgerr "Package '$pkg' not exist." echo "Package '$pkg' not exist."
continue continue
else else
. $(getportpath $pkg)/$BUILD_SCRIPT . $(getportpath $pkg)/$BUILD_SCRIPT
if [ "$(installed_pkg_info version $pkg)-$(installed_pkg_info release $pkg)" = "$version-$release" ]; then if [ "$(installed_pkg_info version $pkg)-$(installed_pkg_info release $pkg)" = "$version-$release" ]; then
msg "Package '$pkg' is up to date." echo "Package '$pkg' is up to date."
continue continue
fi fi
fi fi
upkg="$upkg $pkg" upkg="$upkg $pkg"
done done
[ "$upkg" ] || return 0 [ "$upkg" ] || return 0
[ "$NO_DEP" ] || {
UPGPKG=0
NEWPKG=0
if [ "$NODEP" != 1 ]; then
echo "Resolving dependencies..." echo "Resolving dependencies..."
DEP=$(scratch_deplist $upkg $EXOPT | awk '{print $2}') DEP=$(scratch_deplist $upkg $EXOPT | awk '{print $2}')
for dep in $DEP; do echo
if ! isinstalled $dep; then for d in $DEP; do
[ "$(getportpath $dep)" ] && newpkg="$newpkg $dep" if [ "$(echo $upkg | tr ' ' '\n' | grep -x $d)" = "$d" ]; then
printf "[${GREEN}u${CRESET}] $d "
WILLINSTALL="$WILLINSTALL $d"
UPGPKG=$(( UPGPKG + 1 ))
elif ! isinstalled $d && [ "$(getportpath "$d")" ]; then
printf "[${CYAN}n${CRESET}] $d "
WILLINSTALL="$WILLINSTALL $d"
NEWPKG=$(( NEWPKG + 1 ))
fi fi
done done
} else
echo echo
tnew=0 for dd in $upkg; do
tup=0 printf "[${GREEN}u${CRESET}] $dd "
for i in $newpkg; do WILLINSTALL="$WILLINSTALL $dd"
tnew=$(( tnew + 1 )) UPGPKG=$(( UPGPKG + 1 ))
printf "[${CYAN}n${CRESET}] $i " done
done fi
for i in $upkg; do
tup=$(( tup + 1 ))
printf "[${GREEN}u${CRESET}] $i "
done
echo; echo echo; echo
echo "( $tup upgrade, $tnew new install )" echo "( $UPGPKG upgrade, $NEWPKG new install )"
echo echo
[ "$NOCONFIRM" ] || { [ "$NOCONFIRM" ] || {
confirm "Continue upgrade/install these package(s)?" "Package upgrade cancelled." || exit $? confirm "Continue upgrade/install these package(s)?" "Package upgrade cancelled." || exit $?
echo echo
} }
total=$(( tup + tnew ))
count=0
error=0 error=0
if [ "$newpkg" ]; then count=0
for pkg in $newpkg; do total=$(echo $WILLINSTALL | wc -w)
count=$(( count + 1 )) for inst in $WILLINSTALL; do # install all required dependencies and target packages itself
cd $(getportpath $pkg)
settermtitle "[ $count/$total ] Installing $pkg..."
pkgbuild -i $OPTS || {
error=1
count=$(( count - 1 ))
break
}
done_pkg="$done_pkg $pkg"
cd - >/dev/null
done
fi
for pkg in $upkg; do # upgrade all target packages
count=$(( count + 1 )) count=$(( count + 1 ))
cd $(getportpath $pkg) cd $(getportpath $inst)
settermtitle "[ $count/$total ] Upgrading $pkg..." if ! isinstalled $inst; then
pkgbuild -u $OPTS || { settermtitle "[ $count/$total ] Installing $inst..."
if [ "$LOGBUILD" = 1 ]; then
pkgbuild $OPTS -i | tee $LOG_DIR/$inst.log
else
pkgbuild $OPTS -i
fi
[ "$?" = 0 ] || {
error=1 error=1
count=$(( count - 1 )) count=$(( count - 1 ))
break break
} }
done_pkg="$done_pkg $pkg" else
settermtitle "[ $count/$total ] Upgrading $inst..."
if [ "$LOGBUILD" = 1 ]; then
pkgbuild $OPTS -u | tee $LOG_DIR/$inst.log
else
pkgbuild $OPTS -u
fi
[ "$?" = 0 ] || {
error=1
count=$(( count - 1 ))
break
}
fi
cd - >/dev/null cd - >/dev/null
done_pkg="$done_pkg $inst"
done done
settermtitle "triggering upgrade hook..." settermtitle "Triggering install hook."
[ "$done_pkg" ] && scratch_trigger $done_pkg [ "$done_pkg" ] && scratch_trigger $done_pkg
settermtitle "$count/$total package(s) upgraded." settermtitle "$count/$total package(s) upgraded."
return "$error" return "$error"
@@ -1126,11 +1185,13 @@ Options:
-r|--reinstall reinstall -r|--reinstall reinstall
-n|--no-dep skip dependencies -n|--no-dep skip dependencies
-y|--yes skip ask user permission -y|--yes skip ask user permission
--log log build process
--exclude=* exclude dependencies, comma separated --exclude=* exclude dependencies, comma separated
upgrade <ports> <arg> upgrade ports (use pkgbuild arg, except '-i' & '-r') upgrade <ports> <arg> upgrade ports (use pkgbuild arg, except '-i' & '-r')
-n|--no-dep skip dependencies -n|--no-dep skip dependencies
-y|--yes skip ask user permission -y|--yes skip ask user permission
--log log build process
--exclude=* exclude dependencies, comma separated --exclude=* exclude dependencies, comma separated
remove <ports> <arg> remove installed ports (use pkgdel arg) remove <ports> <arg> remove installed ports (use pkgdel arg)
@@ -1139,6 +1200,7 @@ Options:
sysup <arg> full system upgrade (use pkgbuild arg, except '-i', '-r' & '-u') sysup <arg> full system upgrade (use pkgbuild arg, except '-i', '-r' & '-u')
-n|--no-dep skip dependencies -n|--no-dep skip dependencies
-y|--yes skip ask user permission -y|--yes skip ask user permission
--log log build process
--exclude=* exclude dependencies, comma separated --exclude=* exclude dependencies, comma separated
deplist <ports> print all dependencies for ports deplist <ports> print all dependencies for ports
@@ -1146,6 +1208,7 @@ Options:
--exclude=* exclude dependencies, comma separated --exclude=* exclude dependencies, comma separated
build <ports> <arg> build ports (use pkgbuild arg, except '-i', '-u', '-r', '-g', & '-p') build <ports> <arg> build ports (use pkgbuild arg, except '-i', '-u', '-r', '-g', & '-p')
--log log build process
lock <ports> locking ports prevent upgrade lock <ports> locking ports prevent upgrade
unlock <ports> unlock locked ports unlock <ports> unlock locked ports
@@ -1172,17 +1235,19 @@ print_runhelp_msg() {
BUILD_SCRIPT="spkgbuild" BUILD_SCRIPT="spkgbuild"
INDEX_DIR="/var/lib/scratchpkg/index" INDEX_DIR="/var/lib/scratchpkg/index"
REPO_FILE="/etc/scratchpkg.repo" REPO_FILE="/etc/scratchpkg.repo"
ALIAS_FILE="/etc/scratchpkg.alias"
# default value from pkgbuild # default value from pkgbuild
SOURCE_DIR="/var/cache/scratchpkg/sources" SOURCE_DIR="/var/cache/scratchpkg/sources"
PACKAGE_DIR="/var/cache/scratchpkg/packages" PACKAGE_DIR="/var/cache/scratchpkg/packages"
LOG_DIR="/var/cache/scratchpkg/log"
COMPRESSION_MODE="xz" COMPRESSION_MODE="xz"
mode=$1 mode=$1
if [ -z "$mode" ]; then [ "$mode" ] || {
print_runhelp_msg print_runhelp_msg
fi }
shift shift
@@ -1194,7 +1259,7 @@ for opt in $@; do
-*) char=${#opt}; count=1 -*) char=${#opt}; count=1
while [ "$count" != "$char" ]; do while [ "$count" != "$char" ]; do
count=$((count+1)) count=$((count+1))
MAINOPTS="$MAINOPTS -$(echo $opt | cut -c $count)" MAINOPTS="$MAINOPTS -$(printf '%s' $opt | cut -c $count)"
done;; done;;
*) MAINOPTS="$MAINOPTS $opt";; *) MAINOPTS="$MAINOPTS $opt";;
esac esac
@@ -1207,7 +1272,7 @@ if [ -f "$REPO_FILE" ]; then
done done
fi fi
if [ "$(type -t scratch_$mode)" = "function" ]; then if [ "$(command -v scratch_$mode)" ]; then
scratch_$mode $MAINOPTS scratch_$mode $MAINOPTS
else else
print_runhelp_msg print_runhelp_msg

9
scratchpkg.alias Normal file
View File

@@ -0,0 +1,9 @@
#
# /etc/scratchpkg.alias : scratchpkg alias file
#
# format:
# <real package> <aliased package>
#
# example:
# openssl libressl
#

View File

@@ -9,7 +9,7 @@ MAKEFLAGS="-j$(nproc)"
# SOURCE_DIR="/var/cache/scratchpkg/sources" # SOURCE_DIR="/var/cache/scratchpkg/sources"
# PACKAGE_DIR="/var/cache/scratchpkg/packages" # PACKAGE_DIR="/var/cache/scratchpkg/packages"
# WORK_DIR="/var/cache/scratchpkg/work" # WORK_DIR="/var/cache/scratchpkg/work"
# DOWNLOAD_PROG="wget" # DOWNLOAD_PROG="auto"
# WGET_OPTS="" # WGET_OPTS=""
# CURL_OPTS="" # CURL_OPTS=""
# COMPRESSION_MODE="xz" # COMPRESSION_MODE="xz"
@@ -24,8 +24,10 @@ MAKEFLAGS="-j$(nproc)"
# -- buildflags: Enable buildflags (CFLAGS and CXXFLAGS) # -- buildflags: Enable buildflags (CFLAGS and CXXFLAGS)
# -- makeflags: Enable makeflags (MAKEFLAGS) # -- makeflags: Enable makeflags (MAKEFLAGS)
# -- checksum: Enable checking checksum # -- checksum: Enable checking checksum
# -- docs: Keep docs
# -- locales: Keep locales
# #
# -- These are default values for the options="" settings # -- These are default values for the options="" settings
# -- add '!' in front of this option to disable it # -- add '!' in front of this option to disable it
# #
# OPTIONS="!libtool emptydirs strip zipman buildflags makeflags checksum" # OPTIONS="!libtool emptydirs strip zipman buildflags makeflags checksum !docs !locales"

View File

@@ -20,8 +20,8 @@
EDITOR=${EDITOR:-vi} EDITOR=${EDITOR:-vi}
type -p $EDITOR >/dev/null || { command -v $EDITOR >/dev/null || {
echo "Editor '$EDITOR' not exist..." echo "Editor '$EDITOR' not exist. Append 'EDITOR=<your editor>' to ${0##*/}."
exit 2 exit 2
} }

90
xchroot Executable file
View File

@@ -0,0 +1,90 @@
#!/bin/sh
printhelp() {
cat << EOF
Usage:
$(basename $0) <chroot-dir> [command]
If 'command' is unspecified, ${0##*/} will launch /bin/sh.
EOF
}
msgerr() {
echo "ERROR: $*"
}
[ "$(id -u)" = "0" ] || {
msgerr "$(basename $0) need root access!"
printhelp
exit 1
}
TARGET=$1
[ "$1" ] || {
msgerr "Please set directory for chroot!"
printhelp
exit 1
}
[ -d "$TARGET" ] || {
msgerr "Directory '$TARGET' not exist!"
printhelp
exit 1
}
shift
if [ ! "$1" ]; then
CMD="/bin/sh"
else
CMD=$*
fi
if [ -e /sys/firmware/efi/systab ]; then
EFI_SYSTEM=1
fi
mount --bind /dev $TARGET/dev
mount -t devpts devpts $TARGET/dev/pts -o gid=5,mode=620
mount -t proc proc $TARGET/proc
mount -t sysfs sysfs $TARGET/sys
if [ -n "$EFI_SYSTEM" ]; then
mount --bind /sys/firmware/efi/efivars $TARGET/sys/firmware/efi/efivars
fi
mount -t tmpfs tmpfs $TARGET/run
if [ -h $TARGET/dev/shm ]; then
mkdir -p $TARGET/$(readlink $TARGET/dev/shm)
fi
[ -f $TARGET/etc/resolv.conf ] && {
backupresolvconf=1
mv $TARGET/etc/resolv.conf $TARGET/etc/resolv.conf.tmp
}
cp -L /etc/resolv.conf $TARGET/etc
chroot "$TARGET" /usr/bin/env -i \
HOME=/root \
TERM="$TERM" \
PS1='\u:\w\$ ' \
PATH=/bin:/usr/bin:/sbin:/usr/sbin $CMD
retval=$?
[ "$backupresolvconf" = 1 ] && {
mv $TARGET/etc/resolv.conf.tmp $TARGET/etc/resolv.conf
}
umount -l $TARGET/dev/pts
umount -l $TARGET/dev
umount -l $TARGET/run
umount -l $TARGET/proc
if [ -n "$EFI_SYSTEM" ]; then
umount -l $TARGET/sys/firmware/efi/efivars
fi
umount -l $TARGET/sys
exit $retval