Almost done
This commit is contained in:
parent
be3a6f49aa
commit
91665b4f0d
159
dpkg-frontend.sh
159
dpkg-frontend.sh
@ -26,6 +26,7 @@ Author="Jack-Benny Persson (jack-benny@cyberinfo.se)"
|
|||||||
|
|
||||||
# Binaries
|
# Binaries
|
||||||
Which="/usr/bin/which"
|
Which="/usr/bin/which"
|
||||||
|
Aptget="/usr/bin/apt-get"
|
||||||
# Binaries entered in the list will be avalible to the script as variables with
|
# Binaries entered in the list will be avalible to the script as variables with
|
||||||
# the first letter uppercase
|
# the first letter uppercase
|
||||||
Binaries=(dpkg sed awk egrep printf cat grep mktemp rm tail zenity)
|
Binaries=(dpkg sed awk egrep printf cat grep mktemp rm tail zenity)
|
||||||
@ -47,66 +48,104 @@ print_help()
|
|||||||
print_version
|
print_version
|
||||||
$Printf "$Author\n"
|
$Printf "$Author\n"
|
||||||
$Printf "dpkg-frontend\n"
|
$Printf "dpkg-frontend\n"
|
||||||
/bin/cat <<-EOT
|
/bin/cat <<-EOT
|
||||||
|
|
||||||
Options:
|
Options:
|
||||||
-h
|
-h
|
||||||
Print detailed help screen
|
Print detailed help screen
|
||||||
-V
|
-V
|
||||||
Print version information
|
Print version information
|
||||||
-v
|
-v
|
||||||
Verbose output
|
Verbose output
|
||||||
EOT
|
EOT
|
||||||
}
|
}
|
||||||
|
|
||||||
# Dialog for package searching
|
# Dialog for package searching
|
||||||
search_pkg()
|
search_pkg()
|
||||||
{
|
{
|
||||||
Search=`$Zenity --title "dpkg-frontend" --entry \
|
Search=`$Zenity --title "dpkg-frontend" --entry \
|
||||||
--text="Search for package"`
|
--text="Search for package"`
|
||||||
if [ $? -eq 1 ]; then
|
if [ $? -eq 1 ]; then
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
$Dpkg --list | $Awk '{ print $2 }' | $Egrep -x $Search &> /dev/null
|
$Dpkg --list | $Awk '{ print $2 }' | $Egrep -x $Search &> /dev/null
|
||||||
if [ $? -eq 0 ]; then
|
if [ $? -eq 0 ]; then
|
||||||
return 0
|
return 0
|
||||||
else
|
else
|
||||||
return 5
|
return 5
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
uninstall_pkg()
|
uninstall_pkg()
|
||||||
{
|
{
|
||||||
$Zenity --title "dpkg-frontend" \
|
$Zenity --title "dpkg-frontend" \
|
||||||
--question \
|
--question \
|
||||||
--text="Package $Search is installed.\nUninstall ${Search}?"
|
--text="Package <b>$Search</b> is installed.\nUninstall <b>${Search}</b>?"
|
||||||
if [ $? -eq 0 ]; then # CHANGE NEXT LINE
|
if [ $? -eq 0 ]; then # CHANGE NEXT LINE
|
||||||
sleep 3 | $Zenity --title "dpkg-frontend" \
|
$Dpkg -r $Search | $Zenity --title "dpkg-frontend" \
|
||||||
--progress --pulsate --text "Uninstalling ${Search}..."
|
--progress --pulsate --text "Uninstalling <b>${Search}</b>..."
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
install_pkg()
|
install_pkg()
|
||||||
{
|
{
|
||||||
echo "Install pkg?"
|
$Aptget install $Search -y | \
|
||||||
|
$Zenity --title "dpkg-fronend" --progress --pulsate \
|
||||||
|
--text "Installing package <b>$Search</b>"
|
||||||
|
if [ $? -eq 0 ]; then
|
||||||
|
$Zenity --title "dpkg-frontend" --info \
|
||||||
|
--text="Succesfully installed <b>$Search</b>"
|
||||||
|
exit 0
|
||||||
|
else
|
||||||
|
$Zenity --title "dpkg-frontend" --error \
|
||||||
|
--text="Something went wrong with the installation of <b>$Search</b>"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
show_selections()
|
show_selections()
|
||||||
{
|
{
|
||||||
Selections=`dpkg --get-selections $Search | awk '{ print $2 }'`
|
Selections=`dpkg --get-selections $Search | awk '{ print $2 }'`
|
||||||
$Zenity --title "dpkg-frontend" \
|
$Zenity --title "dpkg-frontend" \
|
||||||
--info --text "Selections for $Search is: <b>${Selections}</b>"
|
--info --text "Selections for <b>$Search</b> is: <b>${Selections}</b>"
|
||||||
|
}
|
||||||
|
|
||||||
|
set_selections()
|
||||||
|
{
|
||||||
|
SetSelections=`$Zenity --title "dpkg-frontend" --entry \
|
||||||
|
--text="Type selections for package <b>$Search</b>"`
|
||||||
|
echo "$Search $SetSelections" | $Dpkg --set-selections
|
||||||
|
if [ $? -eq 0 ]; then
|
||||||
|
$Zentiy --title "dpkg-frontend" --info \
|
||||||
|
--text "<b>${SetSelections}</b> is set for <b>${Search}</b>"
|
||||||
|
else
|
||||||
|
$Zenity --title "dpkg-frontend" --error \
|
||||||
|
--text "Couldn't set selections for <b>$Search</b>"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
show_info()
|
||||||
|
{
|
||||||
|
Info=`$Dpkg --status $Search`
|
||||||
|
$Zenity --no-markup --title "dpkg-frontend" --info \
|
||||||
|
--text "$Info"
|
||||||
}
|
}
|
||||||
|
|
||||||
choice_dialog()
|
choice_dialog()
|
||||||
{
|
{
|
||||||
Choice=`$Zenity --list --column=Action --column=Description \
|
Choice=`$Zenity --list --column=Action --column=Description \
|
||||||
--radiolist uninstall "Uninstall" show "Show selections"`
|
--radiolist uninstall "Uninstall" set "Set selections" \
|
||||||
if [ "$Choice" == "Uninstall" ]; then
|
show "Show selections" \
|
||||||
return 11
|
info "Show information"`
|
||||||
elif [ "$Choice" == "Show selections" ]; then
|
if [ "$Choice" == "Uninstall" ]; then
|
||||||
return 12
|
return 11
|
||||||
fi
|
elif [ "$Choice" == "Show selections" ]; then
|
||||||
|
return 12
|
||||||
|
elif [ "$Choice" == "Show information" ]; then
|
||||||
|
return 13
|
||||||
|
elif [ "$Choice" == "Set selections" ]; then
|
||||||
|
return 14
|
||||||
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
# Create variables with absolute path to binaries and check
|
# Create variables with absolute path to binaries and check
|
||||||
@ -114,7 +153,7 @@ choice_dialog()
|
|||||||
# variables with first character uppercase, such as Grep)
|
# variables with first character uppercase, such as Grep)
|
||||||
Count=0
|
Count=0
|
||||||
for i in ${Binaries[@]}; do
|
for i in ${Binaries[@]}; do
|
||||||
$Which $i &> /dev/null
|
$Which $i &> /dev/null
|
||||||
if [ $? -eq 0 ]; then
|
if [ $? -eq 0 ]; then
|
||||||
declare $(echo ${Binaries[$Count]^}=`${Which} $i`)
|
declare $(echo ${Binaries[$Count]^}=`${Which} $i`)
|
||||||
((Count++))
|
((Count++))
|
||||||
@ -124,6 +163,13 @@ for i in ${Binaries[@]}; do
|
|||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
|
# Check if we are root
|
||||||
|
if [ $EUID -ne 0 ]; then
|
||||||
|
$Zenity --title "dpkg-frontend" --error \
|
||||||
|
--text "You need to run <b>dpkg-frontend</b> as root"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
# Parse command line options and arguments
|
# Parse command line options and arguments
|
||||||
while getopts Vvho: Opt; do
|
while getopts Vvho: Opt; do
|
||||||
case "$Opt" in
|
case "$Opt" in
|
||||||
@ -142,22 +188,31 @@ while getopts Vvho: Opt; do
|
|||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
|
|
||||||
|
|
||||||
### Main ###
|
### Main ###
|
||||||
search_pkg
|
search_pkg
|
||||||
if [ $? -eq 1 ]; then
|
case $? in
|
||||||
exit 0
|
1) exit 0
|
||||||
elif [ $? -eq 5 ]; then
|
;;
|
||||||
$Zenity --title "dpkg-frontend" --info \
|
5) $Zenity --title "dpkg-frontend" --question \
|
||||||
--text="Package $Search is not installed"
|
--text="Package <b>$Search</b> is not installed. Install it?"
|
||||||
exit 1
|
if [ $? -eq 0 ]; then
|
||||||
fi
|
install_pkg
|
||||||
|
else
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
choice_dialog
|
choice_dialog
|
||||||
if [ $? -eq 11 ]; then
|
case $? in
|
||||||
uninstall_pkg
|
11) uninstall_pkg
|
||||||
elif [ $? -eq 12 ]; then
|
;;
|
||||||
show_selections
|
12) show_selections
|
||||||
fi
|
;;
|
||||||
|
13) show_info
|
||||||
|
;;
|
||||||
|
14) set_selections
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
exit 0
|
exit 0
|
||||||
|
Loading…
x
Reference in New Issue
Block a user