Nameless23
Linux-Anfänger
Folgendes steht in den beiden Dateien:
MfG
Nameless
Code:
#!/bin/sh -e
CONFFILE=/etc/default/mldonkey-server
case "$1" in
install|upgrade)
if dpkg --compare-versions "$2" lt "2.5.1-5" && [ -e /etc/mldonkey.conf ]; then
echo "Moving /etc/mldonkey.conf to /etc/default/mldonkey-server"
mv -f /etc/mldonkey.conf $CONFFILE
fi
;;
esac
Code:
#!/bin/sh -e
# Source debconf library
. /usr/share/debconf/confmodule
DEBUG=false
db_get mldonkey-server/launch_at_startup
launch_at_startup="$RET"
case "$1" in
configure)
CONF=/etc/default/mldonkey-server
if [ "$launch_at_startup" = "true" ]; then
###########################
# Handling debconf values #
###########################
db_get mldonkey-server/mldonkey_umask
mldonkey_umask="$RET"
umask $mldonkey_umask
db_get mldonkey-server/run_as_user
run_as_user=$RET
db_get mldonkey-server/mldonkey_group
mldonkey_group=$RET
db_get mldonkey-server/mldonkey_dir
new_mldonkey_dir="$RET"
db_get mldonkey-server/mldonkey_niceness
mldonkey_niceness="$RET"
db_get mldonkey-server/client_name
client_name="$RET"
db_get mldonkey-server/plugin
enable_directconnect=false
enable_opennap=false
enable_overnet=false
enable_soulseek=false
enable_bittorrent=false
enable_gnutella=false
enable_fasttrack=false
OLD_IFS=$IFS
IFS=", "
for i in $RET; do
case $i in
Directconnect*)
enable_directconnect=true
;;
Opennap*)
enable_opennap=true
;;
Overnet*)
enable_overnet=true
;;
Soulseek*)
enable_soulseek=true
;;
Bittorrent*)
enable_bittorrent=true
;;
Gnutella*)
enable_gnutella=true
;;
Fasttrack*)
enable_fasttrack=true
;;
esac
done
IFS=$OLD_IFS
db_get mldonkey-server/max_hard_upload_rate
max_hard_upload_rate="$RET"
db_get mldonkey-server/max_hard_download_rate
max_hard_download_rate="$RET"
db_get mldonkey-server/password
password="$RET"
db_get mldonkey-server/max_alive
max_alive="$RET"
###################
# User management #
###################
# Creating MLDonkey group if he isn't already there
if ! getent group $mldonkey_group > /dev/null ; then
$DEBUG && echo -n "Creating mldonkey group: "
addgroup --quiet $mldonkey_group
$DEBUG && echo "done."
fi
# Creating MLDonkey user if he isn't already there
if ! getent passwd $run_as_user > /dev/null ; then
$DEBUG && echo -n "Creating mldonkey user: "
adduser --quiet --system --ingroup $mldonkey_group \
--home "$new_mldonkey_dir" --no-create-home $run_as_user
$DEBUG && echo "done."
fi
run_as_useruid=`/usr/bin/id -u $run_as_user`
if [ ! -d $new_mldonkey_dir ]; then
$DEBUG && echo -n "Creating mldonkey home directory: "
mkdir "$new_mldonkey_dir"
$DEBUG && echo "done."
fi
#########################
# Relocation management #
#########################
if [ -e "$CONF" ]; then
. "$CONF"
if [ -n "$MLDONKEY_DIR" ] && [ -f "$MLDONKEY_DIR/downloads.ini" ]; then
db_get mldonkey-server/reown_file
if [ "$RET" = "true" ] && ! dpkg-statoverride --list "$MLDONKEY_DIR" >/dev/null; then
$DEBUG && echo -n "Reowning file of $MLDONKEY_DIR: "
# BUG: should not use chown, should use dpkg-statoverride itself, but the owner is not always
# the same. If i use the method suggested in the Debian Policy 10.9.1, i need to dynamically
# create a user, but this user should never be changed. The DP method will inject a new rules
# in dpkg-statoverride which will made the above test always false for any further
# upgrade/configure. With my method, only the user can set dpkg-statoverride rules to stop the
# reowning of a file... However i am not sure this is the best method to do so.
/bin/chown -R $run_as_user:$mldonkey_group "$MLDONKEY_DIR"
$DEBUG && echo "done."
fi
db_get mldonkey-server/mldonkey_move
if [ "$RET" = "true" ] && [ "$new_mldonkey_dir" != "$MLDONKEY_DIR" ]; then
$DEBUG && echo -n "Moving file of $MLDONKEY_DIR to $new_mldonkey_dir: "
/bin/mv "--target-directory=$new_mldonkey_dir" "$MLDONKEY_DIR/*"
$DEBUG && echo "done."
fi
fi
fi
#################
# Downloads.ini #
#################
if [ -e "$new_mldonkey_dir/downloads.ini" ]; then
$DEBUG && echo -n "Creating backup of $new_mldonkey_dir/downloads.ini: "
/bin/cp -p -f "$new_mldonkey_dir/downloads.ini" "$new_mldonkey_dir/downloads.ini.dpkg"
$DEBUG && echo "done."
else
$DEBUG && echo -n "Creating empty $new_mldonkey_dir/downloads.ini: "
/bin/touch "$new_mldonkey_dir/downloads.ini"
$DEBUG && echo "done."
fi
$DEBUG && echo -n "Writing new values to $new_mldonkey_dir/downloads.ini: "
/usr/bin/mldonkey_options -f "$new_mldonkey_dir/downloads.ini" <<EOF
run_as_useruid=$run_as_useruid
run_as_user="$run_as_user"
client_name="$client_name"
enable_directconnect=$enable_directconnect
enable_opennap=$enable_opennap
enable_overnet=$enable_overnet
enable_soulseek=$enable_soulseek
enable_bittorrent=$enable_bittorrent
enable_gnutella=$enable_gnutella
enable_fasttrack=$enable_fasttrack
max_hard_upload_rate=$max_hard_upload_rate
max_hard_download_rate=$max_hard_download_rate
EOF
$DEBUG && echo "done."
#############
# Files.ini #
#############
# Handling fasttrack file split here, better than in the mldonkey-server.init
if [ -e "$new_mldonkey_dir/files.ini" ] \
&& [ ! -e "$new_mldonkey_dir/files.ini.fasttrack" ] \
&& /usr/bin/mldonkey_files --test Fasttrack -q -f0 "$new_mldonkey_dir/files.ini"; then
echo "Correction of the Fasttrack problem (see /usr/share/doc/mldonkey-server/README.Debian)"
echo -n "Splitting $new_mldonkey_dir/files.ini (backup in $new_mldonkey_dir/files.ini.fasttrack): "
/usr/bin/mldonkey_files --split Fasttrack -f0 "$new_mldonkey_dir/files.ini" \
-f1 "$new_mldonkey_dir/files.ini.fasttrack" \
-f2 "$new_mldonkey_dir/files.ini"
echo "done."
fi
#############
# Users.ini #
#############
if [ -e "$new_mldonkey_dir/downloads.ini" ] && \
/usr/bin/mldonkey_users --test-users-section -q -f "$new_mldonkey_dir/downloads.ini"; then
if [ -e "$new_mldonkey_dir/users.ini" ]; then
echo "File $new_mldonkey_dir/users.ini exists and $new_mldonkey_dir/downloads.ini contains a \"users\" section, this is inconstitent."
echo "Please user mldonkey_users(1) to strip the \"users\" section of $new_mldonkey_dir/downloads.ini."
else
# OK we have downloads.ini containing a "users" section, this is pre 2.5.28.1
# configuration, lets split it...
$DEBUG && echo -n "Transferring \"users\" section from file $new_mldonkey_dir/downloads.ini to $new_mldonkey_dir/users.ini: "
/usr/bin/mldonkey_users --dump-users-section -q -f "$new_mldonkey_dir/downloads.ini" > "$new_mldonkey_dir/users.ini"
/usr/bin/mldonkey_users --strip-users-section -q -f "$new_mldonkey_dir/downloads.ini" > "$new_mldonkey_dir/downloads.ini.tmp"
mv -f "$new_mldonkey_dir/downloads.ini.tmp" "$new_mldonkey_dir/downloads.ini"
$DEBUG && echo "done."
fi
fi
if [ -n "$password" ]; then
if [ -e "$new_mldonkey_dir/users.ini" ]; then
$DEBUG && echo -n "Creating backup of $new_mldonkey_dir/users.ini: "
/bin/cp -p -f "$new_mldonkey_dir/users.ini" "$new_mldonkey_dir/users.ini.dpkg"
$DEBUG && echo "done."
else
$DEBUG && echo -n "Creating empty $new_mldonkey_dir/users.ini: "
/bin/touch "$new_mldonkey_dir/users.ini"
$DEBUG && echo "done."
fi
$DEBUG && echo -n "Registering admin password in $new_mldonkey_dir/users.ini: "
/usr/bin/mldonkey_users --add admin -q -f "$new_mldonkey_dir/users.ini" -p $password
$DEBUG && echo "done."
fi
####################
# Files permission #
####################
for file in \
"$new_mldonkey_dir" \
"/var/run" \
"/var/log/mldonkey" \
"$new_mldonkey_dir/downloads.ini" \
"$new_mldonkey_dir/downloads.ini.dpkg" \
"$new_mldonkey_dir/downloads.ini.old" \
"$new_mldonkey_dir/downloads.ini.tmp" \
"$new_mldonkey_dir/files.ini" \
"$new_mldonkey_dir/files.ini.fasttrack"; do
$DEBUG && echo -n "Changing owner and file permission of $file: "
if ! dpkg-statoverride --list "$file" >/dev/null; then
# BUG: cf dpkg-statoverride above
if [ -e "$file" ]; then
/bin/chown $run_as_user:$mldonkey_group $file
$DEBUG && echo "done."
else
$DEBUG && echo "$file doesn't exist."
fi
else
$DEBUG && echo "$file is listed in dpkg-statoverride."
fi
done
for file in \
"$new_mldonkey_dir/users.ini" \
"$new_mldonkey_dir/users.ini.dpkg" \
"$new_mldonkey_dir/users.ini.old" \
"$new_mldonkey_dir/users.ini.tmp"; do
$DEBUG && echo -n "Changing owner and file permission of $file: "
if ! dpkg-statoverride --list "$file" >/dev/null; then
# BUG: cf dpkg-statoverride above
if [ -e "$file" ]; then
/bin/chown $run_as_user:$mldonkey_group "$file"
/bin/chmod 0600 "$file"
$DEBUG && echo "done."
else
$DEBUG && echo "$file doesn't exist."
fi
else
$DEBUG && echo "$file is listed in dpkg-statoverride."
fi
done
fi
################################
# /etc/default/mldonkey-server #
################################
CONF_NEW=`/bin/tempfile`
$DEBUG && echo -n "Writing new values to $CONF_NEW: "
cat > "$CONF_NEW" <<EOF
# MLDonkey configuration
# This file is loaded by /etc/init.d/mldonkey-server
# This file is managed using ucf(1)
MLDONKEY_DIR=$new_mldonkey_dir
MLDONKEY_GROUP=$mldonkey_group
MLDONKEY_UMASK=$mldonkey_umask
MAX_ALIVE=$max_alive
LAUNCH_AT_STARTUP=$launch_at_startup
MLDONKEY_NICENESS=$mldonkey_niceness
EOF
ucf "$CONF_NEW" "$CONF"
$DEBUG && echo "done."
;;
abort-upgrade|abort-remove|abort-deconfigure)
;;
*)
echo "postinst called with unknown argument \`$1'" >&2
exit 1
;;
esac
db_stop
# For the rest
# Automatically added by dh_installmenu
if [ "$1" = "configure" ] && [ -x "`which update-menus 2>/dev/null`" ]; then
update-menus
fi
# End automatically added section
# Automatically added by dh_installinit
if [ -x "/etc/init.d/mldonkey-server" ]; then
update-rc.d mldonkey-server start 98 2 3 4 5 . stop 20 0 1 6 . >/dev/null
if [ -x "`which invoke-rc.d 2>/dev/null`" ]; then
invoke-rc.d mldonkey-server start || exit $?
else
/etc/init.d/mldonkey-server start || exit $?
fi
fi
# End automatically added section
MfG
Nameless
Zuletzt bearbeitet von einem Moderator: