Dselect support
[ntk/apt.git] / dselect / install
CommitLineData
7a1b1f8b
AL
1#!/bin/sh
2
3# Get the configuration from /etc/apt/apt.conf
4CLEAN="auto"
5OPTS="-f"
6APTGET="/usr/bin/apt-get"
7DPKG="/usr/bin/dpkg"
8sh -e
9RES=`apt-config shell CLEAN DSelect::Clean OPTS DSelect::Options \
10 DPKG Dir::Bin::dpkg APTGET Dir::Bin::apt-get`
11eval $RES
12sh +e
13
14# Yes/No Prompter
15function yesno() {
16# $1 = prompt
17# $2 = default(y)
18 local ans def defp
19 if [ "$2" ];then
20 case $2 in
21 Y|y) defp="(Y/n)" def=y;;
22 N|n) defp="(y/N)" def=n;;
23 *) echo "Bad default setting!" 1>&2; exit 1;;
24 esac
25 else
26 defp="(y/N)" def=n
27 fi
28 while :;do
29 echo -n "$1$defp" 1>&3
30 read ans
31 case $ans in
32 Y|y|N|n) break;;
33 "") ans=$def;break;;
34 esac
35 echo
36 done
37 echo $ans | tr YN yn
38}
39
40#$APTGET $OPTS dselect-upgrade
41RES=$?
42
43# 1 means the user choose no at the prompt
44if [ $RES -eq 1 ]; then
45 exit 0
46fi
47
48# Finished OK
49if [ $RES -eq 0 ]; then
50 # Check the cleaning mode
51 case `echo $CLEAN | tr '[:upper:]' '[:lower:]'` in
52 always|auto)
53 $APTGET clean && echo "Press enter to continue." && read RES && exit 0;
54 ;;
55 prompt)
56 exec 3>&1
57 if [ `yesno "Do you want to erase the downloaded files " y` = y ]; then
58 $APTGET clean && echo "Press enter to continue." && read RES && exit 0;
59 fi
60 ;;
61 *)
62 ;;
63 esac
64else
65 echo "Some errors occurred while unpacking. I'm going to configure the"
66 echo "packages that were installed. This may result in duplicate errors"
67 echo "or errors caused by missing dependencies. This is OK, only the errors"
68 echo "above this message are important. Please fix them and run [I]nstall again"
69 echo "Press enter to continue."
70 read RES && $DPKG --configure -a
71 exit 100
72fi
73
74exit $?