This commit is contained in:
emmett1
2018-06-05 16:55:42 +08:00
parent 133078cff7
commit b287a29632
12 changed files with 127 additions and 121 deletions

View File

@@ -9,7 +9,7 @@ INDEX_DIR=/var/lib/scratchpkg
PORT_DIR=/usr/ports
mkdir -pv ${DESTDIR}{${BINDIR},${FUNCDIR},${CONFDIR},${HOOK_DIR},${PORT_DIR}}
install -m755 buildpkg installpkg removepkg scratch ${DESTDIR}${BINDIR}
install -m755 revdep buildpkg installpkg removepkg scratch ${DESTDIR}${BINDIR}
install -m644 functions/* ${DESTDIR}${FUNCDIR}
install -m644 scratchpkg.conf scratchpkg.repo ${DESTDIR}${CONFDIR}
install -m755 extra/* ${DESTDIR}${BINDIR}

View File

@@ -7,6 +7,13 @@ if [ ! "$1" ]; then
exit 1
fi
while read repodir repourl junk; do
case $repodir in
""|"#"*) continue ;;
esac
PORT_REPO+=($repodir)
done < /etc/scratchpkg.repo
checkdep() {
if getportpath "$1" >/dev/null; then

View File

@@ -43,9 +43,13 @@ for file in $spkgnew; do
echo "Replace '$currentfile' with '$file'."
mv "$file" "$currentfile"
else
echo "Do nothing."
echo "Doing nothing."
fi
sleep 1
done
clear
echo "Done updating package's configuration files."
exit 0

View File

@@ -1,64 +0,0 @@
#!/bin/bash -e
source "/usr/share/scratchpkg/color"
source "/usr/share/scratchpkg/message"
faileduppkg=()
successuppkg=()
case "$1" in
-up|--update-ports)
msg "Updating ports..."
if [ $UID != 0 ]; then
if [ $(type -p sudo) ]; then
sudo scratch portup
else
msgerr "Updating package need root access!"
exit 1
fi
else
scratch portup
fi ;;
esac
if [[ ! $(scratch -cu | grep "up to date") ]]; then
outdatepkg=($(scratch query --outdate | awk '{print $2}'))
totalopkgs=$(echo ${#outdatepkg[@]})
count=1
for i in ${outdatepkg[@]}; do
if [ $UID != 0 ]; then
if [ $(type -p sudo) ]; then
echo -e "[ $count/$totalopkgs ] Updating $i..."
sudo scratch -u -p $i && successuppkg+=($i) || faileduppkg+=($i)
else
msgerr "Updating package need root access!"
exit 1
fi
else
echo -e "[ $count/$totalopkgs ] Updating $i..."
scratch upgrade $i && successuppkg+=($i) || faileduppkg+=($i)
fi
echo
((count++))
done
else
msg "All packages is up to date."
exit 0
fi
if [ "${#successuppkg[@]}" -gt 0 ]; then
echo "Successfully update this package(s):"
for ok in ${successuppkg[@]}; do
echo -e "${GREEN}>>>${CRESET} $ok"
done
fi
if [ "${#faileduppkg[@]}" -gt 0 ]; then
[ "${#successuppkg[@]}" -gt 0 ] && echo # make space between success and failed
echo "Failed update this package(s):"
for ko in ${faileduppkg[@]}; do
echo -e "${RED}>>>${CRESET} $ko"
done
fi
exit 0

View File

@@ -32,10 +32,18 @@ msginst() {
echo -e "[${GREEN}*${CRESET}] $@"
}
msgnew() {
echo -e "[${GREEN}N${CRESET}] $@"
}
msgupg() {
echo -e "[${GREEN}U${CRESET}] $@"
}
msgnoinst() {
echo -e "[ ] $@"
}
msgmiss() {
echo -e "[${RED}m${CRESET}] $@"
echo -e "[${RED}M${CRESET}] $@"
}

View File

@@ -151,40 +151,6 @@ checkdeps() {
fi
}
checkneworphan() {
for dpd in ${idepends[@]}; do
saferemove $dpd
done
for mdpd in ${imakedepends[@]}; do
saferemove $mdpd
done
if [ "${#neworphan[@]}" -gt 0 ]; then
msg "New orphaned package:"
for list in ${neworphan[@]}; do
msg2 $list
done
fi
}
saferemove() {
ORPHAN="yes"
for all_installed in $(ls $INDEX_DIR); do
depend=$(cat $INDEX_DIR/$all_installed/.pkginfo | grep ^depends | cut -d " " -f3-)
for dep in ${depend[@]}; do
if [ $dep = $1 ]; then
ORPHAN="no"
fi
done
done
[ "$ORPHAN" = "yes" ] && [ -d $INDEX_DIR/$1 ] && neworphan+=($1)
}
runremovehooks() {
if [ "${#runthishook[@]}" -gt 0 ]; then
@@ -267,7 +233,6 @@ parse_opts() {
--no-preremove) NO_PREREMOVE=yes ;;
--no-postremove) NO_POSTREMOVE=yes ;;
--no-color) NOCOLOR=yes ;;
--no-orphan-check) NO_ORPHAN_CHECK=yes ;;
-*) msg "Invalid option: ($1)"; exit 1 ;;
*) RMNAME+=($1) ;;
esac
@@ -316,10 +281,7 @@ main() {
for pkg in ${RMNAME[@]}; do
getoldname $pkg ### GET NAME, VERSION, RELEASE FROM INSTALLED PACKAGE DATABASE ###
removepkg $pkg ### REMOVE PACKAGE ###
#if [ ! "$NO_ORPHAN_CHECK" ]; then # check for orphan package
#checkneworphan
#fi
removepkg $pkg ### REMOVE PACKAGE ###
done
# running ldconfig

119
scratch
View File

@@ -142,11 +142,10 @@ missingdep() {
showportpath() {
if getportpath "$1" >/dev/null; then
echo -e "$(getportpath $1)"
exit 0
if PPATH=$(getportpath "$1"); then
echo "$PPATH"
else
msgerr "Port '$1' not exist"
msgerr "Port '$1' not exist."
exit 1
fi
@@ -239,11 +238,24 @@ showdependent2() {
catport() {
if getportpath "$1" >/dev/null; then
cat "$(getportpath $1)/$BUILD_SCRIPT"
exit 0
if PPATH=$(getportpath "$1"); then
cat "$PPATH/$BUILD_SCRIPT"
else
msgerr "Port '$1' not exist"
msgerr "Port '$1' not exist."
exit 1
fi
}
printreadme() {
if PPATH=$(getportpath "$1"); then
if [ -f "$PPATH/readme" ]; then
cat "$PPATH/readme"
else
msgerr "Port '$1' does not have readme."
fi
else
msgerr "Port '$1' not exist."
exit 1
fi
}
@@ -365,6 +377,60 @@ pkgcache() {
}
sysup() {
needroot "Upgrading package"
PKGOUTDATE=$(outdatepkg)
if [ ! "$PKGOUTDATE" ]; then
msg "All package is up to date."
exit 0
fi
for i in ${PKGOUTDATE[@]}; do
echo -ne "Calculating '$i' dependencies...\033[0K\r"
deplist $i
done
echo -ne "\033[0K"
for d in ${DEP[@]}; do
if [ "$(echo ${PKGOUTDATE[@]} | tr ' ' '\n' | grep -x $d)" = "$d" ]; then
msgupg "$d"
WILLINSTALL+=($d)
elif [ ! -e "$INDEX_DIR/$d/.pkginfo" ] && getportpath $d >/dev/null; then
msgnew "$d"
WILLINSTALL+=($d)
fi
done
echo
echo "These package(s) will be upgrade and installed..."
echo
confirm "Continue upgrade and install these package(s)?" "Package upgrade cancelled."
echo
for inst in ${WILLINSTALL[@]}; do # install all required dependencies and target packages itself
if [ ! -e "$INDEX_DIR/$inst/.pkginfo" ]; then
portinstall $inst -i || exit 1
else
portinstall $inst -u || exit 1
fi
done
}
outdatepkg() {
for pkg in $(allinstalled); do
if [ ! -e "$INDEX_DIR/$pkg/.lock" ] && getportpath $pkg >/dev/null; then
. $(getportpath $pkg)/$BUILD_SCRIPT
iversion=$(installed_pkg_info version $pkg)
irelease=$(installed_pkg_info release $pkg)
if [ "$release" != "$irelease" ] || [ "$version" != "$iversion" ]; then
echo $name
fi
fi
done
}
checkupdate() {
for pkg in $(allinstalled); do
@@ -552,6 +618,10 @@ deplist() {
fi
fi
#if [[ $(echo ${DEP[@]} | tr " " "\n" | grep -x $i) = "$i" ]]; then
#return 0
#fi
# add package to currently process
CHECK+=($1)
@@ -563,7 +633,9 @@ deplist() {
done
# add dependency to list checked dep
DEP+=($1)
if [[ $(echo ${DEP[@]} | tr " " "\n" | grep -x $1) = "" ]]; then
DEP+=($1)
fi
# delete process package array
for i in "${!CHECK[@]}"; do
@@ -631,7 +703,9 @@ mode:
pkgtree <package> show list files of installed package
path <package> show package's buildscripts path
sync update port's repo
sysup full system update
dup print duplicate ports in repo
readme print readme file if exist
listinst list installed package in system
listorphan list orphan package
integrity check integrity of package's files
@@ -713,12 +787,14 @@ done
checkdirexist "$INDEX_DIR"
while read repodir repourl junk; do
case $repodir in
""|"#"*) continue ;;
esac
PORT_REPO+=($repodir)
done < /etc/scratchpkg.repo
if [ -f /etc/scratchpkg.repo ]; then
while read repodir repourl junk; do
case $repodir in
""|"#"*) continue ;;
esac
PORT_REPO+=($repodir)
done < /etc/scratchpkg.repo
fi
# build mode
if [ "$mode" = "build" ]; then
@@ -1045,6 +1121,19 @@ if [ "$mode" = "search" ]; then
exit 0
fi
# print readme for ports
if [ "$mode" = "readme" ]; then
needarg "$ARG" || exit 1
printreadme $ARG
exit 0
fi
# update all ports
if [ "$mode" = "sysup" ]; then
sysup
exit 0
fi
echo "Run '$(basename $0) help' to see available mode and options"
exit 0