Last active
August 13, 2016 07:06
-
-
Save danmaq/8825128e199c787b46ca61e4786447a8 to your computer and use it in GitHub Desktop.
/etc/rcX.d/AllScripts launcher for "Ubuntu on Windows". Usage: sudo rund4wsl.sh -l <runlevel> -o <start|stop>
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
failed() | |
{ | |
echo $1 1>&2 | |
exit 1 | |
} | |
usage() | |
{ | |
failed "Usage: sudo $0 -l <runlevel> -o <start|stop>" | |
} | |
[ $# = 0 ] && usage | |
OPTION=`getopt -n $0 -o l:o:h -- "$@"` | |
[ $? != 0 ] && usage | |
eval set -- "$OPTION" | |
while true | |
do | |
case "$1" in | |
-l) ENABLED_RUN_LEVEL=true | |
RUN_LEVEL=$2 | |
shift 2 | |
;; | |
-o) ENABLED_DAEMON_OPTION=true | |
DAEMON_OPTION=$2 | |
shift 2 | |
;; | |
-h) | |
usage | |
;; | |
--) | |
shift | |
break | |
;; | |
esac | |
done | |
[ ! $ENABLED_RUN_LEVEL ] && usage | |
[ ! $ENABLED_DAEMON_OPTION ] && usage | |
TARGET="/etc/rc${RUN_LEVEL}.d" | |
[ ! -e $TARGET ] && failed "Invalid run level: $RUN_LEVEL" | |
for FILE in `find $TARGET -maxdepth 1 -perm -u=x \! -type d` | |
do | |
echo "$FILE $DAEMON_OPTION" | |
echo `$FILE $DAEMON_OPTION` | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
start_rund4wsl.cmd - Windows 側からログオン時に呼び出してください。
term_rund4wsl.cmd - Windows 側からログオフ時に呼び出してください。
予め visudo でパスワード省くようにしないとうまく動かないかも。それと chmod。