summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormakefu <github@syntax-fehler.de>2011-08-29 12:38:56 +0200
committermakefu <github@syntax-fehler.de>2011-08-29 12:38:56 +0200
commite805dbd13ea4afc86cbb6bf20c17a4cdf72cb835 (patch)
tree9a356cee8f787a971c4cb71e258db71941750837
parent851fb93dd3d1778da12752977cfbe4fff7d65ecb (diff)
punani: fix help/hard conflict, system function
handle_system is now the function which does the right thing for all distro specific stuff
-rwxr-xr-xpunani/bin/punani239
1 files changed, 152 insertions, 87 deletions
diff --git a/punani/bin/punani b/punani/bin/punani
index f01cedb7..f9244c53 100755
--- a/punani/bin/punani
+++ b/punani/bin/punani
@@ -9,7 +9,7 @@
set -euf
godmode() {
if test "${nosudo-false}" != true -a `id -u` != 0; then
- echo "Warning: we require god mode..." >&2
+ echo "!! we require god mode..." >&2
exec sudo "$0" "$@"
exit 23 # go to hell
fi
@@ -43,7 +43,142 @@ arch_aur_helper()
echo "!! To be Implemented"
return 1
}
+handle_system () {
+ case "$system" in
+ (*arch-like*)
+ # dryrun
+ # TODO dryrun not dry enough for aur helper
+ if [ "${dryrun-}" ];then
+ pacman () { echo "pacman $@" ; }
+ pkgfile () { echo "pkgfile $@"; }
+ yaourt () { echo "yaourt $@" ; }
+ fi
+
+ # get dependencies :
+ # we need pkgfile
+ if ! [ `which pkgfile` ] ; then
+ pacman -S --noconfirm pkgtools
+ pkgfile -u
+ fi
+ punani_Scientist_update() {
+ pacman -Sy
+ pkgtool -u
+ }
+
+ punani_Engineer_insert() {
+ # punani under archlinux first tries to load the packages with the given file name
+ # it needs pkgfile for that
+ #
+ # when trying harder it tries to load the package with the given name directly via yaourt
+ echo "** trying to find package with given file"
+ if pacman -Sy `pkgfile $1`; then
+ echo "++ finished"
+ exit 0
+ else
+ echo "!! nothing found in base repos"
+ if [ "${hard-}" ] ; then
+ echo "** trying harder"
+ echo "** trying yaourt directly with given package"
+ mgr=`arch_aur_helper`
+ if $mgr -S $1 ;then
+ echo "++ finished"
+ exit 0
+ else
+ echo "!! giving up...i am sorry"
+ exit 1
+ fi
+ echo
+ else
+ echo "?? When in doubt try $0 -h -Ei $1 "
+ fi
+ fi
+ }
+ punani_Engineer_remove() {
+ pacman -Rcs "`pacman -Ql | grep $1$ | awk '{print $1}'`"
+ if [ "${hard-}" ] ; then
+ echo "** trying harder"
+ echo "** directly delete given package name"
+ pacman -Rcs "$1"
+ fi
+ }
+ ;;
+ (*debian-like*)
+ if [ "${dryrun-}" ]; then
+ apt-file () { echo $@; }
+ apt-get () { echo $@; }
+ fi
+ [ `which apt-file` ] || apt-get install --yes apt-file && apt-file update
+ punani_Scientist_update() {
+ apt-get update
+ apt-file update
+ }
+ punani_Scientist_search() {
+ apt-file search $1 && exit 0
+ if [ "${hard-}" ] ; then
+ apt-cache search $1
+ fi
+ }
+ punani_Engineer_insert() {
+ if apt-get install `apt-file search $1`;then
+ echo "++ finished"
+ else
+ if [ "${hard-}" ] ; then
+ echo "** trying harder"
+ apt-get install $1
+ fi
+ fi
+ }
+ punani_Engineer_remove() {
+ apt-get remove --purge "`apt-file search $1`"
+ if [ "${hard-}" ] ; then
+ echo "** trying harder"
+ echo "** directly delete given package name"
+ apt-get remove --purge "$1"
+ fi
+ }
+ ;;
+ (*)
+ email='krebs@syntax-fehler.de'
+ irc_host='irc.freenode.org'
+ irc_channel='#tincspasm'
+ cat>&2<<EOF
+Error 2: Your System Will Be Supported ASAP
+1. send us a bug report
+1.1 your operating system's name and version
+1.2 this message: $0 $*
+1.3 mailto:$email
+2. join the relevant IRC channel
+2.1 /connect $irc_host
+2.2 /join $irc_channel
+EOF
+ exit 23
+ esac
+}
+help(){
+ cat <<EOF
+Usage: $0 [Options] [role][command]
+
+Options:
+ -f force
+ -h hard
+ -v verbose
+ -d dryrun
+ -? this message
+
+Role:
+ -E Engineer
+ -S Scientist
+
+Engineer:
+ i insert
+ r remove
+Scientist:
+ s search
+ y update
+EOF
+ exit 1
+}
punani (){
ns=punani
role=undefined
@@ -53,6 +188,7 @@ punani (){
(h) hard=true; continue;;
(v) verbose=true; continue;;
(d) dryrun=true; continue;;
+ (\?) help;continue ;;
esac
case ${role-Manager} in
(Engineer)
@@ -62,11 +198,19 @@ punani (){
(*)
echo 'Error 1: You are made of stupid!' >&2
exit 23;;
- esac
- ;;
+ esac;;
+ (Scientist)
+ case $OPT in
+ (s) command="${ns}_${role}_search";;
+ (y) command="${ns}_${role}_update";;
+ (*)
+ echo 'Error 1: You are made of stupid!' >&2
+ exit 23;;
+ esac ;;
(undefined)
case $OPT in
(E) role=Engineer;;
+ (S) role=Scientist;;
(*)
exit 23;;
esac
@@ -82,96 +226,17 @@ punani $@
case $role in
(Engineer) godmode $@;;
+ (Scientist)
+ case $command in
+ (*_update) godmode $@;;
+ esac;;
esac
shift `echo $OPTIND-1 | bc`
guess_system
-case "$system" in
- (*arch-like*)
- # get dependencies :
- # we need pkgfile
- if [ "${dryrun-}" ];then
- pacman () { echo "pacman $@" ; }
- pkgfile () { echo "pkgfile $@"; }
- yaourt () { echo "yaourt $@" ; }
- fi
- if ! [ `which pkgfile` ] ; then
- pacman -S --noconfirm pkgtools
- pkgfile -u
- fi
- punani_Scientist_update() {
- pacman -Sy
- pkgtool -u
- }
-
- punani_Engineer_insert() {
- # punani under archlinux first tries to load the packages with the given file name
- # it needs pkgfile for that
- #
- # when trying harder it tries to load the package with the given name directly via yaourt
- echo "** trying to find package with given file"
- if pacman -Sy `pkgfile $1`; then
- echo "++ finished"
- exit 0
- else
- echo "!! nothing found in base repos"
- if [ "${hard-}" ] ; then
- echo "** trying harder"
- echo "** trying yaourt directly with given package"
- mgr=`arch_aur_helper`
- if $mgr -S $1 ;then
- echo "++ finished"
- exit 0
- else
- echo "!! giving up...i am sorry"
- exit 1
- fi
- echo
- else
- echo "?? When in doubt try $0 -Ei --hard $1 "
- fi
- fi
- }
- punani_Engineer_remove() {
- pacman -Rcs "`pacman -Ql | grep $1$ | awk '{print $1}'`"
- if [ "${hard-}" ] ; then
- echo "trying harder"
- echo "** directly delete given package name"
- pacman -Rcs "$1"
- fi
- }
- ;;
- (*debian-like*)
- if [ "${dryrun-}" ]; then
- apt-file () { echo $@; }
- apt-get () { echo $@; }
- fi
- [ `which apt-file` ] || apt-get install --yes apt-file && apt-file update
- punani_Scientist_update() {
- apt-get update
- apt-file update
- }
-
- ;;
- (*)
- email='krebs@syntax-fehler.de'
- irc_host='irc.freenode.org'
- irc_channel='#tincspasm'
- cat>&2<<EOF
-Error 2: Your System Will Be Supported ASAP
-1. send us a bug report
-1.1 your operating system's name and version
-1.2 this message: $0 $*
-1.3 mailto:$email
-2. join the relevant IRC channel
-2.1 /connect $irc_host
-2.2 /join $irc_channel
-EOF
- exit 23
-esac
-
+handle_system
command="${ns}_Engineer_insert"
for name; do
"$command" "$name"