99 lines
1.6 KiB
Bash
99 lines
1.6 KiB
Bash
#!/bin/bash
|
|
set -e
|
|
shopt -s nullglob
|
|
|
|
# Shows the usage of this command to the user
|
|
|
|
showUsage()
|
|
{
|
|
me="$(basename "$0")"
|
|
|
|
cat <<EOF
|
|
Usage: $me [OPTION] ACTIVITY [PATH]
|
|
|
|
This command runs a deployment activity on all BSD rc scripts in a Nix profile.
|
|
The scripts are traversed in the right dependency order.
|
|
|
|
Options:
|
|
-p, --profile=NAME Name of the Nix profile that stores the sysvinit scripts
|
|
(defaults to: processes)
|
|
-r, --reverse Traverse the sysvinit scripts in the reverse order
|
|
-h, --help Shows the usage of this command
|
|
|
|
Environment:
|
|
NIX_STATE_DIR Overrides the location of the Nix state directory
|
|
EOF
|
|
}
|
|
|
|
# Parse valid argument options
|
|
|
|
PARAMS=`@getopt@ -n $0 -o p:rh -l profile:,reverse,help -- "$@"`
|
|
|
|
if [ $? != 0 ]
|
|
then
|
|
showUsage
|
|
exit 1
|
|
fi
|
|
|
|
# Evaluate valid options
|
|
|
|
eval set -- "$PARAMS"
|
|
|
|
while [ "$1" != "--" ]
|
|
do
|
|
case "$1" in
|
|
-p|--profile)
|
|
profile="$2"
|
|
;;
|
|
-r|--reverse)
|
|
reverse=1
|
|
;;
|
|
-h|--help)
|
|
showUsage
|
|
exit 0
|
|
;;
|
|
esac
|
|
|
|
shift
|
|
done
|
|
|
|
shift
|
|
|
|
activity="$1"
|
|
|
|
# Validate the given options
|
|
|
|
if [ "$activity" = "" ]
|
|
then
|
|
echo "No activity specified!" >&2
|
|
exit 1
|
|
fi
|
|
|
|
source @commonchecks@
|
|
|
|
checkNixStateDir
|
|
checkProfile
|
|
composeOldProfilePath
|
|
|
|
# Execute the activities
|
|
|
|
if [ "$2" = "" ]
|
|
then
|
|
rcpath="$oldProfilePath/etc/rc.d"
|
|
else
|
|
rcpath="$2/etc/rc.d"
|
|
fi
|
|
|
|
if [ "$reverse" = "1" ]
|
|
then
|
|
for i in $(rcorder $rcpath/* | tail -r)
|
|
do
|
|
$i $activity
|
|
done
|
|
else
|
|
for i in $(rcorder $rcpath/*)
|
|
do
|
|
$i $activity
|
|
done
|
|
fi
|