├── .editorconfig ├── .gitignore ├── AUTHORS ├── src ├── usr │ ├── sbin │ │ ├── check-shell-syntax │ │ ├── Makefile.am │ │ └── slide-switch.sh-cut │ └── share │ │ └── slide-switch │ │ ├── check-shell-syntax │ │ ├── check-json-syntax │ │ ├── Makefile.am │ │ ├── switch-data.json-cut │ │ └── functions.sh-cut └── etc │ ├── hotplug.d │ └── button │ │ ├── check-shell-syntax │ │ ├── Makefile.am │ │ └── 50-slide-switch.sh-cut │ └── init.d │ ├── check-shell-syntax │ ├── Makefile.am │ ├── zzz-slide-switch-update.sh-cut │ └── slide-switch.sh-cut ├── Makefile.am ├── bootstrap ├── configure.ac ├── rules.mk ├── NEWS.md ├── README.md ├── INSTALL └── COPYING /.editorconfig: -------------------------------------------------------------------------------- 1 | # http://editorconfig.org/ 2 | 3 | root = true 4 | 5 | [*] 6 | charset = utf-8 7 | end_of_line = lf 8 | indent_style = tab 9 | insert_final_newline = true 10 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | Makefile.in 2 | 3 | /autom4te.cache 4 | /aclocal.m4 5 | /config.log 6 | /config.status 7 | /configure 8 | /install-sh 9 | /missing 10 | /test-driver 11 | 12 | /build/* 13 | !/build/.gitignore 14 | -------------------------------------------------------------------------------- /AUTHORS: -------------------------------------------------------------------------------- 1 | Jeffery To (jefferyto) 2 | Luke Ross (lukeross) 3 | Jens Steinhauser (JenSte) 4 | Alexey Solovyev (alex-solovyev) 5 | Chuckame 6 | Ryan Patterson (CGamesPlay) 7 | chris (chr-chr) 8 | nexus166 9 | -------------------------------------------------------------------------------- /src/usr/sbin/check-shell-syntax: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # src/usr/sbin/check-shell-syntax 4 | # This file is part of slide-switch. 5 | # 6 | # Copyright (C) 2016-2019, 2022 The slide-switch authors 7 | # https://github.com/jefferyto/openwrt-slide-switch 8 | # 9 | # slide-switch is free software; you can redistribute it and/or 10 | # modify it under the terms of the GNU General Public License 11 | # version 2 as published by the Free Software Foundation. 12 | # 13 | # slide-switch is distributed in the hope that it will be useful, 14 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | # GNU General Public License for more details. 17 | # 18 | # You should have received a copy of the GNU General Public License 19 | # along with slide-switch. If not, see . 20 | # 21 | 22 | sh -n slide-switch 23 | -------------------------------------------------------------------------------- /src/etc/hotplug.d/button/check-shell-syntax: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # src/etc/hotplug.d/button/check-shell-syntax 4 | # This file is part of slide-switch. 5 | # 6 | # Copyright (C) 2016-2019, 2022 The slide-switch authors 7 | # https://github.com/jefferyto/openwrt-slide-switch 8 | # 9 | # slide-switch is free software; you can redistribute it and/or 10 | # modify it under the terms of the GNU General Public License 11 | # version 2 as published by the Free Software Foundation. 12 | # 13 | # slide-switch is distributed in the hope that it will be useful, 14 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | # GNU General Public License for more details. 17 | # 18 | # You should have received a copy of the GNU General Public License 19 | # along with slide-switch. If not, see . 20 | # 21 | 22 | sh -n 50-slide-switch 23 | -------------------------------------------------------------------------------- /src/usr/share/slide-switch/check-shell-syntax: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # src/usr/share/slide-switch/check-shell-syntax 4 | # This file is part of slide-switch. 5 | # 6 | # Copyright (C) 2016-2019, 2022 The slide-switch authors 7 | # https://github.com/jefferyto/openwrt-slide-switch 8 | # 9 | # slide-switch is free software; you can redistribute it and/or 10 | # modify it under the terms of the GNU General Public License 11 | # version 2 as published by the Free Software Foundation. 12 | # 13 | # slide-switch is distributed in the hope that it will be useful, 14 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | # GNU General Public License for more details. 17 | # 18 | # You should have received a copy of the GNU General Public License 19 | # along with slide-switch. If not, see . 20 | # 21 | 22 | sh -n functions.sh 23 | -------------------------------------------------------------------------------- /src/etc/init.d/check-shell-syntax: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # src/etc/init.d/check-shell-syntax 4 | # This file is part of slide-switch. 5 | # 6 | # Copyright (C) 2016-2019, 2022 The slide-switch authors 7 | # https://github.com/jefferyto/openwrt-slide-switch 8 | # 9 | # slide-switch is free software; you can redistribute it and/or 10 | # modify it under the terms of the GNU General Public License 11 | # version 2 as published by the Free Software Foundation. 12 | # 13 | # slide-switch is distributed in the hope that it will be useful, 14 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | # GNU General Public License for more details. 17 | # 18 | # You should have received a copy of the GNU General Public License 19 | # along with slide-switch. If not, see . 20 | # 21 | 22 | sh -n slide-switch && sh -n zzz-slide-switch-update 23 | -------------------------------------------------------------------------------- /Makefile.am: -------------------------------------------------------------------------------- 1 | # 2 | # Makefile.am 3 | # This file is part of slide-switch. 4 | # 5 | # Copyright (C) 2016-2019, 2022 The slide-switch authors 6 | # https://github.com/jefferyto/openwrt-slide-switch 7 | # 8 | # slide-switch is free software; you can redistribute it and/or 9 | # modify it under the terms of the GNU General Public License 10 | # version 2 as published by the Free Software Foundation. 11 | # 12 | # slide-switch is distributed in the hope that it will be useful, 13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | # GNU General Public License for more details. 16 | # 17 | # You should have received a copy of the GNU General Public License 18 | # along with slide-switch. If not, see . 19 | # 20 | 21 | SUBDIRS = \ 22 | src/etc/hotplug.d/button \ 23 | src/etc/init.d \ 24 | src/usr/sbin \ 25 | src/usr/share/slide-switch 26 | -------------------------------------------------------------------------------- /src/usr/share/slide-switch/check-json-syntax: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # src/usr/share/slide-switch/check-json-syntax 4 | # This file is part of slide-switch. 5 | # 6 | # Copyright (C) 2016-2019, 2022 The slide-switch authors 7 | # https://github.com/jefferyto/openwrt-slide-switch 8 | # 9 | # slide-switch is free software; you can redistribute it and/or 10 | # modify it under the terms of the GNU General Public License 11 | # version 2 as published by the Free Software Foundation. 12 | # 13 | # slide-switch is distributed in the hope that it will be useful, 14 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | # GNU General Public License for more details. 17 | # 18 | # You should have received a copy of the GNU General Public License 19 | # along with slide-switch. If not, see . 20 | # 21 | 22 | python3 -m json.tool switch-data.json 23 | -------------------------------------------------------------------------------- /src/usr/sbin/Makefile.am: -------------------------------------------------------------------------------- 1 | # 2 | # src/usr/sbin/Makefile.am 3 | # This file is part of slide-switch. 4 | # 5 | # Copyright (C) 2016-2019, 2022 The slide-switch authors 6 | # https://github.com/jefferyto/openwrt-slide-switch 7 | # 8 | # slide-switch is free software; you can redistribute it and/or 9 | # modify it under the terms of the GNU General Public License 10 | # version 2 as published by the Free Software Foundation. 11 | # 12 | # slide-switch is distributed in the hope that it will be useful, 13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | # GNU General Public License for more details. 16 | # 17 | # You should have received a copy of the GNU General Public License 18 | # along with slide-switch. If not, see . 19 | # 20 | 21 | sbin_SCRIPTS = slide-switch 22 | dist_check_SCRIPTS = check-shell-syntax 23 | 24 | CLEANFILES = $(sbin_SCRIPTS) 25 | EXTRA_DIST = $(sbin_SCRIPTS:=.sh-cut) 26 | 27 | include $(top_srcdir)/rules.mk 28 | -------------------------------------------------------------------------------- /src/usr/share/slide-switch/Makefile.am: -------------------------------------------------------------------------------- 1 | # 2 | # src/usr/share/slide-switch/Makefile.am 3 | # This file is part of slide-switch. 4 | # 5 | # Copyright (C) 2016-2019, 2022 The slide-switch authors 6 | # https://github.com/jefferyto/openwrt-slide-switch 7 | # 8 | # slide-switch is free software; you can redistribute it and/or 9 | # modify it under the terms of the GNU General Public License 10 | # version 2 as published by the Free Software Foundation. 11 | # 12 | # slide-switch is distributed in the hope that it will be useful, 13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | # GNU General Public License for more details. 16 | # 17 | # You should have received a copy of the GNU General Public License 18 | # along with slide-switch. If not, see . 19 | # 20 | 21 | pkgdata_DATA = functions.sh switch-data.json 22 | dist_check_SCRIPTS = check-json-syntax check-shell-syntax 23 | 24 | CLEANFILES = $(pkgdata_DATA) 25 | EXTRA_DIST = $(pkgdata_DATA:=-cut) 26 | 27 | include $(top_srcdir)/rules.mk 28 | -------------------------------------------------------------------------------- /src/etc/init.d/Makefile.am: -------------------------------------------------------------------------------- 1 | # 2 | # src/etc/init.d/Makefile.am 3 | # This file is part of slide-switch. 4 | # 5 | # Copyright (C) 2016-2019, 2022 The slide-switch authors 6 | # https://github.com/jefferyto/openwrt-slide-switch 7 | # 8 | # slide-switch is free software; you can redistribute it and/or 9 | # modify it under the terms of the GNU General Public License 10 | # version 2 as published by the Free Software Foundation. 11 | # 12 | # slide-switch is distributed in the hope that it will be useful, 13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | # GNU General Public License for more details. 16 | # 17 | # You should have received a copy of the GNU General Public License 18 | # along with slide-switch. If not, see . 19 | # 20 | 21 | initddir = $(sysconfdir)/init.d 22 | initd_SCRIPTS = slide-switch zzz-slide-switch-update 23 | dist_check_SCRIPTS = check-shell-syntax 24 | 25 | CLEANFILES = $(initd_SCRIPTS) 26 | EXTRA_DIST = $(initd_SCRIPTS:=.sh-cut) 27 | 28 | include $(top_srcdir)/rules.mk 29 | -------------------------------------------------------------------------------- /src/etc/hotplug.d/button/Makefile.am: -------------------------------------------------------------------------------- 1 | # 2 | # src/etc/hotplug.d/button/Makefile.am 3 | # This file is part of slide-switch. 4 | # 5 | # Copyright (C) 2016-2019, 2022 The slide-switch authors 6 | # https://github.com/jefferyto/openwrt-slide-switch 7 | # 8 | # slide-switch is free software; you can redistribute it and/or 9 | # modify it under the terms of the GNU General Public License 10 | # version 2 as published by the Free Software Foundation. 11 | # 12 | # slide-switch is distributed in the hope that it will be useful, 13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | # GNU General Public License for more details. 16 | # 17 | # You should have received a copy of the GNU General Public License 18 | # along with slide-switch. If not, see . 19 | # 20 | 21 | buttondir = $(sysconfdir)/hotplug.d/button 22 | button_DATA = 50-slide-switch 23 | dist_check_SCRIPTS = check-shell-syntax 24 | 25 | CLEANFILES = $(button_DATA) 26 | EXTRA_DIST = $(button_DATA:=.sh-cut) 27 | 28 | include $(top_srcdir)/rules.mk 29 | -------------------------------------------------------------------------------- /src/etc/hotplug.d/button/50-slide-switch.sh-cut: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # src/etc/hotplug.d/button/50-slide-switch.sh-cut.in 4 | # This file is part of slide-switch. 5 | # 6 | # Copyright (C) 2016-2019, 2022 The slide-switch authors 7 | # https://github.com/jefferyto/openwrt-slide-switch 8 | # 9 | # slide-switch is free software; you can redistribute it and/or 10 | # modify it under the terms of the GNU General Public License 11 | # version 2 as published by the Free Software Foundation. 12 | # 13 | # slide-switch is distributed in the hope that it will be useful, 14 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | # GNU General Public License for more details. 17 | # 18 | # You should have received a copy of the GNU General Public License 19 | # along with slide-switch. If not, see . 20 | # 21 | # --8<---- CUT HERE 22 | #!/bin/sh 23 | # 24 | # Copyright (C) 2016-2019, 2022 The slide-switch authors 25 | # https://github.com/jefferyto/openwrt-slide-switch 26 | # 27 | # slide-switch is free software, licensed under the GNU General Public License v2. 28 | # 29 | 30 | "@sbindir@/slide-switch" --log=syslog update "$BUTTON" & 31 | 32 | return 0 33 | -------------------------------------------------------------------------------- /src/etc/init.d/zzz-slide-switch-update.sh-cut: -------------------------------------------------------------------------------- 1 | #!/bin/sh /etc/rc.common 2 | # 3 | # src/etc/init.d/zzz-slide-switch-update.sh-cut.in 4 | # This file is part of slide-switch. 5 | # 6 | # Copyright (C) 2016-2019, 2022 The slide-switch authors 7 | # https://github.com/jefferyto/openwrt-slide-switch 8 | # 9 | # slide-switch is free software; you can redistribute it and/or 10 | # modify it under the terms of the GNU General Public License 11 | # version 2 as published by the Free Software Foundation. 12 | # 13 | # slide-switch is distributed in the hope that it will be useful, 14 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | # GNU General Public License for more details. 17 | # 18 | # You should have received a copy of the GNU General Public License 19 | # along with slide-switch. If not, see . 20 | # 21 | # --8<---- CUT HERE 22 | #!/bin/sh /etc/rc.common 23 | # 24 | # Copyright (C) 2016-2019, 2022 The slide-switch authors 25 | # https://github.com/jefferyto/openwrt-slide-switch 26 | # 27 | # slide-switch is free software, licensed under the GNU General Public License v2. 28 | # 29 | 30 | START=99 31 | 32 | boot() { 33 | "@sbindir@/slide-switch" --log=syslog update --force 34 | } 35 | -------------------------------------------------------------------------------- /bootstrap: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # bootstrap 4 | # This file is part of slide-switch. 5 | # 6 | # Copyright (C) 2016-2019, 2022 The slide-switch authors 7 | # https://github.com/jefferyto/openwrt-slide-switch 8 | # 9 | # slide-switch is free software; you can redistribute it and/or 10 | # modify it under the terms of the GNU General Public License 11 | # version 2 as published by the Free Software Foundation. 12 | # 13 | # slide-switch is distributed in the hope that it will be useful, 14 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | # GNU General Public License for more details. 17 | # 18 | # You should have received a copy of the GNU General Public License 19 | # along with slide-switch. If not, see . 20 | # 21 | 22 | set -o errexit 23 | 24 | me=$(basename "$0") 25 | 26 | if autoreconf --version >/dev/null 2>&1; then 27 | autoreconf --install --verbose "$@" 28 | else 29 | echo "$me: running: aclocal $@" 30 | aclocal "$@" 31 | 32 | echo "$me: running: autoconf $@" 33 | autoconf "$@" 34 | 35 | echo "$me: running: automake --add-missing --copy $@" 36 | automake --add-missing --copy "$@" 37 | fi 38 | 39 | echo 40 | echo "Ready for \`cd build && ../configure && make && make install'" 41 | -------------------------------------------------------------------------------- /src/etc/init.d/slide-switch.sh-cut: -------------------------------------------------------------------------------- 1 | #!/bin/sh /etc/rc.common 2 | # 3 | # src/etc/init.d/slide-switch.sh-cut.in 4 | # This file is part of slide-switch. 5 | # 6 | # Copyright (C) 2016-2019, 2022 The slide-switch authors 7 | # https://github.com/jefferyto/openwrt-slide-switch 8 | # 9 | # slide-switch is free software; you can redistribute it and/or 10 | # modify it under the terms of the GNU General Public License 11 | # version 2 as published by the Free Software Foundation. 12 | # 13 | # slide-switch is distributed in the hope that it will be useful, 14 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | # GNU General Public License for more details. 17 | # 18 | # You should have received a copy of the GNU General Public License 19 | # along with slide-switch. If not, see . 20 | # 21 | # --8<---- CUT HERE 22 | #!/bin/sh /etc/rc.common 23 | # 24 | # Copyright (C) 2016-2019, 2022 The slide-switch authors 25 | # https://github.com/jefferyto/openwrt-slide-switch 26 | # 27 | # slide-switch is free software, licensed under the GNU General Public License v2. 28 | # 29 | 30 | START=94 31 | STOP=10 32 | 33 | start() { 34 | "@sbindir@/slide-switch" --log=syslog init 35 | } 36 | 37 | stop() { 38 | "@sbindir@/slide-switch" --log=syslog clean 39 | } 40 | -------------------------------------------------------------------------------- /configure.ac: -------------------------------------------------------------------------------- 1 | # 2 | # configure.ac 3 | # This file is part of slide-switch. 4 | # 5 | # Copyright (C) 2016-2019, 2022 The slide-switch authors 6 | # https://github.com/jefferyto/openwrt-slide-switch 7 | # 8 | # slide-switch is free software; you can redistribute it and/or 9 | # modify it under the terms of the GNU General Public License 10 | # version 2 as published by the Free Software Foundation. 11 | # 12 | # slide-switch is distributed in the hope that it will be useful, 13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | # GNU General Public License for more details. 16 | # 17 | # You should have received a copy of the GNU General Public License 18 | # along with slide-switch. If not, see . 19 | # 20 | 21 | # Process this file with autoconf to produce a configure script. 22 | 23 | AC_PREREQ([2.69]) 24 | AC_INIT([slide-switch], [1.0.1-dev], [https://github.com/jefferyto/openwrt-slide-switch]) 25 | AM_INIT_AUTOMAKE([foreign]) 26 | 27 | AC_COPYRIGHT([Copyright (C) 2016-2019, 2022 The slide-switch authors]) 28 | 29 | # Checks for programs. 30 | AC_PROG_AWK 31 | if test -z "$AWK"; then 32 | AC_MSG_ERROR([awk is required]) 33 | fi 34 | 35 | # Checks for libraries. 36 | 37 | # Checks for header files. 38 | 39 | # Checks for typedefs, structures, and compiler characteristics. 40 | 41 | # Checks for library functions. 42 | 43 | AC_CONFIG_FILES([ 44 | Makefile 45 | src/etc/hotplug.d/button/Makefile 46 | src/etc/init.d/Makefile 47 | src/usr/sbin/Makefile 48 | src/usr/share/slide-switch/Makefile 49 | ]) 50 | 51 | AC_OUTPUT 52 | -------------------------------------------------------------------------------- /rules.mk: -------------------------------------------------------------------------------- 1 | # 2 | # rules.mk 3 | # This file is part of slide-switch. 4 | # 5 | # Copyright (C) 2016-2019, 2022 The slide-switch authors 6 | # https://github.com/jefferyto/openwrt-slide-switch 7 | # 8 | # slide-switch is free software; you can redistribute it and/or 9 | # modify it under the terms of the GNU General Public License 10 | # version 2 as published by the Free Software Foundation. 11 | # 12 | # slide-switch is distributed in the hope that it will be useful, 13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | # GNU General Public License for more details. 16 | # 17 | # You should have received a copy of the GNU General Public License 18 | # along with slide-switch. If not, see . 19 | # 20 | 21 | SUFFIXES = -cut -in 22 | 23 | -cut-in: 24 | $(AWK) 'p; /--8<----/ {p=1}' $< > $@ 25 | 26 | .json-in.json: 27 | tr -d '[:space:]' < $< > $@ 28 | 29 | # https://www.gnu.org/software/make/manual/html_node/Directory-Variables.html 30 | # https://www.gnu.org/software/automake/manual/html_node/Uniform.html#index-pkgdatadir 31 | # https://www.gnu.org/software/automake/manual/html_node/Basics-of-Distribution.html#index-PACKAGE 32 | .sh-in.sh: 33 | sed \ 34 | -e 's,[@]prefix[@],$(prefix),g' \ 35 | -e 's,[@]exec_prefix[@],$(exec_prefix),g' \ 36 | -e 's,[@]bindir[@],$(bindir),g' \ 37 | -e 's,[@]sbindir[@],$(sbindir),g' \ 38 | -e 's,[@]libexecdir[@],$(libexecdir),g' \ 39 | -e 's,[@]datarootdir[@],$(datarootdir),g' \ 40 | -e 's,[@]datadir[@],$(datadir),g' \ 41 | -e 's,[@]sysconfdir[@],$(sysconfdir),g' \ 42 | -e 's,[@]sharedstatedir[@],$(sharedstatedir),g' \ 43 | -e 's,[@]localstatedir[@],$(localstatedir),g' \ 44 | -e 's,[@]pkgdatadir[@],$(pkgdatadir),g' \ 45 | -e 's,[@]PACKAGE[@],$(PACKAGE),g' \ 46 | -e 's,[@]VERSION[@],$(VERSION),g' \ 47 | $< > $@ 48 | 49 | .sh: 50 | cp $< $@ 51 | 52 | TESTS = $(dist_check_SCRIPTS) 53 | -------------------------------------------------------------------------------- /src/usr/sbin/slide-switch.sh-cut: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # src/usr/sbin/slide-switch.sh-cut.in 4 | # This file is part of slide-switch. 5 | # 6 | # Copyright (C) 2016-2019, 2022 The slide-switch authors 7 | # https://github.com/jefferyto/openwrt-slide-switch 8 | # 9 | # slide-switch is free software; you can redistribute it and/or 10 | # modify it under the terms of the GNU General Public License 11 | # version 2 as published by the Free Software Foundation. 12 | # 13 | # slide-switch is distributed in the hope that it will be useful, 14 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | # GNU General Public License for more details. 17 | # 18 | # You should have received a copy of the GNU General Public License 19 | # along with slide-switch. If not, see . 20 | # 21 | # --8<---- CUT HERE 22 | #!/bin/sh 23 | # 24 | # Copyright (C) 2016-2019, 2022 The slide-switch authors 25 | # https://github.com/jefferyto/openwrt-slide-switch 26 | # 27 | # slide-switch is free software, licensed under the GNU General Public License v2. 28 | # 29 | 30 | . "@pkgdatadir@/functions.sh" 31 | 32 | optarg= 33 | 34 | 35 | set_log "${SLIDE_SWITCH_LOG:-stderr}" 36 | set_verbosity "${SLIDE_SWITCH_VERBOSITY:-notice}" 37 | 38 | while true; do 39 | case $1 in 40 | --log=*) 41 | optarg=${1#--log=} 42 | shift 43 | 44 | [ -n "$optarg" ] || { 45 | error "missing --log argument" 46 | show_usage 47 | exit $ex_usage 48 | } 49 | 50 | set_log "$optarg" || exit 51 | ;; 52 | 53 | --verbosity=*) 54 | optarg=${1#--verbosity=} 55 | shift 56 | 57 | [ -n "$optarg" ] || { 58 | error "missing --verbosity argument" 59 | show_usage 60 | exit $ex_usage 61 | } 62 | 63 | set_verbosity "$optarg" || exit 64 | ;; 65 | 66 | *) 67 | break 68 | ;; 69 | esac 70 | done 71 | 72 | info "$me $version" 73 | 74 | case $1 in 75 | init) do_init ;; 76 | update) shift; do_update "$@" ;; 77 | switch) do_switch ;; 78 | position) do_position "$2" ;; 79 | clean) do_clean ;; 80 | boot) do_boot "$2" ;; 81 | --version) do_version ;; 82 | --help) show_usage ;; 83 | 84 | *) error "invalid command \"$1\""; show_usage; exit $ex_usage ;; 85 | esac 86 | -------------------------------------------------------------------------------- /src/usr/share/slide-switch/switch-data.json-cut: -------------------------------------------------------------------------------- 1 | /* 2 | * src/usr/lib/slide-switch/switch-data.json-cut 3 | * This file is part of slide-switch. 4 | * 5 | * Copyright (C) 2016-2019, 2022 The slide-switch authors 6 | * https://github.com/jefferyto/openwrt-slide-switch 7 | * 8 | * slide-switch is free software; you can redistribute it and/or 9 | * modify it under the terms of the GNU General Public License 10 | * version 2 as published by the Free Software Foundation. 11 | * 12 | * slide-switch is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with slide-switch. If not, see . 19 | * 20 | * --8<---- CUT HERE */ 21 | { 22 | "buffalo,wzr-600dhp": { 23 | "movie-engine": { 24 | "keys": [ "movie_engine" ], 25 | "positions": { 26 | "lo": "on", 27 | "hi": "off" 28 | } 29 | }, 30 | "router": { 31 | "keys": [ "router_auto", "router_off" ], 32 | "positions": { 33 | "hi_hi": "on", 34 | "hi_lo": "off", 35 | "lo_hi": "auto" 36 | } 37 | } 38 | }, 39 | "buffalo,wzr-hp-ag300h": "buffalo,wzr-600dhp", 40 | "buffalo,wzr-hp-g300nh-rb": { 41 | "movie-engine": { 42 | "keys": [ "movie_off", "movie_on" ], 43 | "positions": { 44 | "lo_hi": "on", 45 | "hi_lo": "off" 46 | } 47 | }, 48 | "router": { 49 | "keys": [ "router_on", "router_auto" ], 50 | "positions": { 51 | "lo_lo": "on", 52 | "hi_lo": "off", 53 | "lo_hi": "auto" 54 | } 55 | } 56 | }, 57 | "buffalo,wzr-hp-g300nh-s": "buffalo,wzr-hp-g300nh-rb", 58 | "glinet,gl-ar150": { 59 | "mode": { 60 | "keys": [ "manual", "auto" ], 61 | "positions": { 62 | "lo_hi": "left", 63 | "lo_lo": "center", 64 | "hi_lo": "right" 65 | } 66 | } 67 | }, 68 | "glinet,gl-ar300m-lite": { 69 | "mode": { 70 | "keys": [ "right", "left" ], 71 | "positions": { 72 | "lo_hi": "left", 73 | "lo_lo": "center", 74 | "hi_lo": "right" 75 | } 76 | } 77 | }, 78 | "glinet,gl-ar300m-nand": "glinet,gl-ar300m-lite", 79 | "glinet,gl-ar300m-nor": "glinet,gl-ar300m-lite", 80 | "glinet,gl-ar300m16": "glinet,gl-ar300m-lite", 81 | "glinet,gl-ar750": { 82 | "mode": { 83 | "keys": [ "mode" ], 84 | "positions": { 85 | "lo": "clear", 86 | "hi": "dot" 87 | } 88 | } 89 | }, 90 | "glinet,gl-ar750s-nor": "glinet,gl-ar750", 91 | "glinet,gl-ar750s-nor-nand": "glinet,gl-ar750", 92 | "glinet,gl-e750": { 93 | "mode": { 94 | "keys": [ "switch" ], 95 | "positions": { 96 | "lo": "dot", 97 | "hi": "clear" 98 | } 99 | } 100 | }, 101 | "glinet,gl-mt1300": { 102 | "mode": { 103 | "keys": [ "switch" ], 104 | "positions": { 105 | "lo": "clear", 106 | "hi": "dot" 107 | } 108 | } 109 | }, 110 | "glinet,gl-mt3000": { 111 | "mode": { 112 | "keys": [ "mode" ], 113 | "positions": { 114 | "lo": "dot", 115 | "hi": "clear" 116 | } 117 | } 118 | }, 119 | "glinet,gl-mt300a": { 120 | "mode": { 121 | "keys": [ "0x100", "0x101" ], 122 | "positions": { 123 | "lo_hi": "left", 124 | "lo_lo": "center", 125 | "hi_lo": "right" 126 | } 127 | } 128 | }, 129 | "glinet,gl-mt300n": { 130 | "mode": { 131 | "keys": [ "0x100", "0x101" ], 132 | "positions": { 133 | "hi_lo": "left", 134 | "lo_lo": "center", 135 | "lo_hi": "right" 136 | } 137 | } 138 | }, 139 | "glinet,gl-mt300n-v2": "glinet,gl-mt300n", 140 | "glinet,gl-mv1000": "glinet,gl-mt1300", 141 | "hootoo,ht-tm02": { 142 | "mode": { 143 | "keys": [ "modeswitch" ], 144 | "positions": { 145 | "lo": "wired", 146 | "hi": "wireless" 147 | } 148 | } 149 | }, 150 | "tplink,tl-mr3020-v1": { 151 | "mode": { 152 | "keys": [ "sw1", "sw2" ], 153 | "positions": { 154 | "hi_lo": "3g", 155 | "lo_hi": "wisp", 156 | "hi_hi": "ap" 157 | } 158 | } 159 | }, 160 | "tplink,tl-mr3020-v3": { 161 | "mode": { 162 | "keys": [ "modec1", "modec2" ], 163 | "positions": { 164 | "lo_hi": "3g", 165 | "hi_lo": "wisp", 166 | "hi_hi": "ap" 167 | } 168 | } 169 | }, 170 | "tplink,tl-mr3040-v2": { 171 | "mode": { 172 | "keys": [ "sw1", "sw2" ], 173 | "positions": { 174 | "lo_hi": "3g", 175 | "hi_lo": "wisp", 176 | "hi_hi": "ap" 177 | } 178 | } 179 | }, 180 | "tplink,tl-wr810n-v1": { 181 | "mode": { 182 | "keys": [ "switch_b0", "switch_b1" ], 183 | "positions": { 184 | "hi_lo": "router-ap", 185 | "lo_hi": "repeater", 186 | "hi_hi": "client" 187 | } 188 | } 189 | }, 190 | "tplink,tl-wr810n-v2": "tplink,tl-wr810n-v1", 191 | "tplink,tl-wr902ac-v1": { 192 | "mode": { 193 | "keys": [ "sw1", "sw2" ], 194 | "positions": { 195 | "hi_lo": "share-eth", 196 | "lo_hi": "share-hotspot", 197 | "hi_hi": "ap" 198 | } 199 | } 200 | }, 201 | "tplink,tl-wr902ac-v3": { 202 | "mode": { 203 | "keys": [ "sw1", "sw2" ], 204 | "positions": { 205 | "lo_hi": "share-eth", 206 | "hi_lo": "share-hotspot", 207 | "hi_hi": "ap" 208 | } 209 | } 210 | } 211 | } 212 | -------------------------------------------------------------------------------- /NEWS.md: -------------------------------------------------------------------------------- 1 | # News 2 | 3 | ## [1.0.1-dev][Unreleased] - Unreleased 4 | * Added support for GL.iNet GL-MT3000 ([#26][GH-26]) 5 | 6 | ## [1.0.0] - 2022-03-17 7 | * **BACKWARD-INCOMPATIBLE:** Changed switch name from *switch* to 8 | *mode*: 9 | * GL.iNet GL-AR150 10 | * GL.iNet GL-AR300M 11 | * GL.iNet GL-AR750 12 | * GL.iNet GL-AR750S 13 | * GL.iNet GL-MT300A 14 | * GL.iNet GL-MT300N v1 15 | * GL.iNet GL-MT300N v2 16 | * **BACKWARD-INCOMPATIBLE:** Changed position names from "left" and 17 | "right" to "clear" and "dot", respectively: 18 | * GL.iNet GL-AR750 19 | * GL.iNet GL-AR750S 20 | * Added support for loading switch data from 21 | /etc/slide-switch/switch-data.json; if this file exists, it will be 22 | checked for switch data before the default data file 23 | * Added support for `keys` array in switch data, in place of `labels` 24 | and `codes` arrays; if present, GPIO labels and key codes will be read 25 | from device tree information in /proc/device-tree (each element in the 26 | `keys` array should be a node-name under the `keys` node) 27 | * Require user to be root for commands/actions that trigger button 28 | events or have other side effects 29 | * Added logging to standard error 30 | * Added command-line option to select logging to standard error 31 | (default), syslog, all (both standard error and syslog) or none 32 | * Added command-line option to select logging verbosity 33 | * Added command-line help message 34 | * Removed compatibility with older (model-only) board names 35 | * `init` command: 36 | * Initialize switch states only, without triggering button pressed 37 | events 38 | * `update` command: 39 | * Require `init` command to be called beforehand 40 | * Accept multiple switch name and/or button arguments 41 | * Added command-line option to perform a forced update (trigger button 42 | pressed events for all switches) 43 | * `switch` command: 44 | * Separate switch names with newlines instead of spaces, i.e. print 45 | one switch name per line 46 | * `position` command: 47 | * Require exactly one switch name argument 48 | * `clean` command: 49 | * Avoid removing files or directories placed in slide-switch's working 50 | directories by other processes 51 | * Restored support for Buffalo WZR-HP-AG300H (requires upcoming OpenWrt 52 | 22.0X release) 53 | * Added support for Buffalo WZR-600DHP (requires upcoming OpenWrt 22.0X 54 | release) 55 | 56 | ## [0.9.7] - 2022-02-18 57 | * Fixed support for models with spaces in their GPIO labels: 58 | * GL.iNet GL-AR300M 59 | * GL.iNet GL-AR300M-Lite 60 | * GL.iNet GL-AR300M16 61 | * TP-Link TL-WR902AC v1 62 | 63 | ## [0.9.6] - 2022-02-04 64 | * Requires OpenWrt 21.02 or newer 65 | * Check button values using GPIO labels instead of GPIO numbers 66 | * Fixed support for ([#18][GH-18]): 67 | * GL.iNet GL-MT300N v2 68 | * TP-Link TL-MR3020 v3 69 | * TP-Link TL-WR902AC v3 70 | * Added support for: 71 | * GL.iNet GL-AR300M-Lite 72 | * GL.iNet GL-AR300M16 73 | * GL.iNet GL-E750 ([#20][GH-20]) 74 | * GL.iNet GL-MT1300 75 | * GL.iNet GL-MV1000 76 | * Removed support for Buffalo WZR-HP-AG300H, as its buttons currently do 77 | not have GPIO labels 78 | * Removed support for devices no longer supported by OpenWrt 21.02: 79 | * TP-Link TL-MR12U 80 | * TP-Link TL-MR13U 81 | * TP-Link TL-WR720N 82 | 83 | ## [0.9.5] - 2019-08-02 84 | * Fixed state files stored in /slide-switch instead of 85 | /var/run/slide-switch ([#14][GH-14]) 86 | * Fixed compatibility with board names in the form "vendor,model" 87 | ([#14][GH-14]) 88 | 89 | ## [0.9.4] - 2019-04-23 90 | * Merged platform data to make the package architecture-independent 91 | * Minify switch data file during installation 92 | * Added support for TP-Link TL-MR3020 v3 93 | 94 | ## [0.9.3] - 2018-12-10 95 | * Added support for routers with two-way switches: 96 | * GLI (GL.iNet) GL-AR750 97 | * GLI (GL.iNet) GL-AR750S 98 | * HooToo HT-TM02 99 | * Added support for two-way switches in: 100 | * Buffalo WZR-HP-AG300H 101 | * Buffalo WZR-HP-G300NH 102 | 103 | ## [0.9.2] - 2018-07-18 104 | * Added support for TP-Link TL-WR902AC v3 105 | 106 | ## [0.9.1] - 2018-01-05 107 | * Added support for: 108 | * GLI (GL.iNet) GL-MT300N v2 109 | * TP-Link TL-WR810N v2 (unverified) 110 | * TP-Link TL-WR902AC v1 111 | * Fixed ar71xx_board_name / ramips_board_name not found error 112 | * Fixed "object" included in first-run output 113 | 114 | ## 0.9.0 - 2016-09-04 115 | * Initial beta release 116 | 117 | [Unreleased]: https://github.com/jefferyto/openwrt-slide-switch/compare/1.0.0...main 118 | [1.0.0]: https://github.com/jefferyto/openwrt-slide-switch/compare/0.9.7...1.0.0 119 | [0.9.7]: https://github.com/jefferyto/openwrt-slide-switch/compare/0.9.6...0.9.7 120 | [0.9.6]: https://github.com/jefferyto/openwrt-slide-switch/compare/0.9.5...0.9.6 121 | [0.9.5]: https://github.com/jefferyto/openwrt-slide-switch/compare/0.9.4...0.9.5 122 | [0.9.4]: https://github.com/jefferyto/openwrt-slide-switch/compare/0.9.3...0.9.4 123 | [0.9.3]: https://github.com/jefferyto/openwrt-slide-switch/compare/0.9.2...0.9.3 124 | [0.9.2]: https://github.com/jefferyto/openwrt-slide-switch/compare/0.9.1...0.9.2 125 | [0.9.1]: https://github.com/jefferyto/openwrt-slide-switch/compare/0.9.0...0.9.1 126 | 127 | [GH-14]: https://github.com/jefferyto/openwrt-slide-switch/issues/14 128 | [GH-18]: https://github.com/jefferyto/openwrt-slide-switch/issues/18 129 | [GH-20]: https://github.com/jefferyto/openwrt-slide-switch/pull/20 130 | [GH-26]: https://github.com/jefferyto/openwrt-slide-switch/pull/26 131 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # slide-switch 2 | 3 | slide-switch translates slide switch position changes into normal button 4 | presses and releases for OpenWrt devices. 5 | 6 | ## Usage 7 | 8 | After installing slide-switch, follow the instructions in the [OpenWrt 9 | User Guide][] to add scripts for each switch position. Both procd 10 | scripts (in `/etc/rc.button`) and hotplug scripts (in 11 | `/etc/hotplug.d/button`) are supported. 12 | 13 | Each switch position has a corresponding button name in the form 14 | `-`. For example, the TP-Link TL-MR3020 15 | has a switch named *mode* with positions "3g", "wisp" and "ap"; button 16 | names for the positions would be `mode-3g`, `mode-wisp` and `mode-ap`. 17 | See [Supported Devices][] for a list of switch names 18 | and positions. 19 | 20 | slide-switch will trigger both button presses and releases. For example, 21 | if the *mode* switch is moved from "3g" to "wisp", a release action will 22 | be triggered for "3g" (`BUTTON=mode-3g ACTION=released`), and a press 23 | action will be triggered for "wisp" (`BUTTON=mode-wisp ACTION=pressed`). 24 | Note that the timeout action is not supported at this time. 25 | 26 | On boot, slide-switch will also trigger a button press for the active 27 | position of each switch. To disable or re-enable this behaviour, run 28 | `slide-switch boot disable` or `slide-switch boot enable`, respectively. 29 | 30 | [OpenWrt User Guide]: https://openwrt.org/docs/guide-user/hardware/hardware.button 31 | [Supported Devices]: #supported-devices 32 | 33 | ## Supported Devices 34 | 35 | | Device | Switch Name | Switch Positions | Verified | Notes | 36 | | ------------------------------ | :----------: | :----------------------------: | :----------------: | ----- | 37 | | [Buffalo WZR-600DHP][] | movie-engine | on / off | | | 38 | | [Buffalo WZR-600DHP][] | router | on / off / auto | | | 39 | | [Buffalo WZR-HP-AG300H][] | movie-engine | on / off | | | 40 | | [Buffalo WZR-HP-AG300H][] | router | on / off / auto | | | 41 | | [Buffalo WZR-HP-G300NH][] | movie-engine | on / off | :heavy_check_mark: | | 42 | | [Buffalo WZR-HP-G300NH][] | router | on / off / auto | :heavy_check_mark: | | 43 | | [GL.iNet GL-AR150][] | mode | left / center / right | | | 44 | | [GL.iNet GL-AR300M][] | mode | left / center / right | :heavy_check_mark: | | 45 | | [GL.iNet GL-AR300M-Lite][] | mode | left / center / right | | | 46 | | [GL.iNet GL-AR300M16][] | mode | left / center / right | :heavy_check_mark: | | 47 | | [GL.iNet GL-AR750][] | mode | dot / clear | :heavy_check_mark: | | 48 | | [GL.iNet GL-AR750S][] | mode | dot / clear | :heavy_check_mark: | | 49 | | [GL.iNet GL-E750][] | mode | dot / clear | :heavy_check_mark: | | 50 | | [GL.iNet GL-MT1300][] | mode | dot / clear | :heavy_check_mark: | | 51 | | [GL.iNet GL-MT3000][] | mode | dot / clear | :heavy_check_mark: | | 52 | | [GL.iNet GL-MT300A][] | mode | left / center / right | :heavy_check_mark: | | 53 | | [GL.iNet GL-MT300N v1][] | mode | left / center / right | | | 54 | | [GL.iNet GL-MT300N v2][] | mode | left / center / right | :heavy_check_mark: | | 55 | | [GL.iNet GL-MV1000][] | mode | dot / clear | | | 56 | | [HooToo HT-TM02][] | mode | wired / wireless | :heavy_check_mark: | | 57 | | [TP-Link TL-MR3020 v1][] | mode | 3g / wisp / ap | :heavy_check_mark: | | 58 | | [TP-Link TL-MR3020 v3][] | mode | 3g / wisp / ap | :heavy_check_mark: | | 59 | | [TP-Link TL-MR3040 v2][] | mode | 3g / wisp / ap | :heavy_check_mark: | | 60 | | [TP-Link TL-WR810N(EU) v1.1][] | mode | router-ap / repeater / client | :heavy_check_mark: | | 61 | | [TP-Link TL-WR810N(EU) v2][] | mode | router-ap / repeater / client | | | 62 | | [TP-Link TL-WR902AC v1][] | mode | share-eth / share-hotspot / ap | :heavy_check_mark: | | 63 | | [TP-Link TL-WR902AC v3][] | mode | share-eth / share-hotspot / ap | :heavy_check_mark: | | 64 | 65 | For most devices, switch data is initially collected from the OpenWrt 66 | wiki and from OpenWrt's source code. The Verified column indicates cases 67 | where the switch data has been tested and verified correct by users. 68 | 69 | [Buffalo WZR-600DHP]: https://openwrt.org/toh/buffalo/wzr-600dhp 70 | [Buffalo WZR-HP-AG300H]: https://openwrt.org/toh/buffalo/wzr-hp-ag300h 71 | [Buffalo WZR-HP-G300NH]: https://openwrt.org/toh/buffalo/wzr-hp-g300h 72 | [GL.iNet GL-AR150]: https://openwrt.org/toh/gl.inet/gl-ar150 73 | [GL.iNet GL-AR300M]: https://openwrt.org/toh/gl.inet/gl-ar300m 74 | [GL.iNet GL-AR300M-Lite]: https://openwrt.org/toh/gl.inet/gl-ar300m_lite 75 | [GL.iNet GL-AR300M16]: https://openwrt.org/toh/gl.inet/gl-ar300m 76 | [GL.iNet GL-AR750]: https://openwrt.org/toh/gl.inet/gl-ar750 77 | [GL.iNet GL-AR750S]: https://openwrt.org/toh/gl.inet/gl-ar750s 78 | [GL.iNet GL-E750]: https://openwrt.org/toh/gl.inet/gl-e750 79 | [GL.iNet GL-MT1300]: https://openwrt.org/toh/gl.inet/gl-mt1300_v1 80 | [GL.iNet GL-MT3000]: https://openwrt.org/toh/gl.inet/gl-mt3000 81 | [GL.iNet GL-MT300A]: https://openwrt.org/toh/gl.inet/gl-mt300a 82 | [GL.iNet GL-MT300N v1]: https://openwrt.org/toh/gl.inet/gl-mt300n_v1 83 | [GL.iNet GL-MT300N v2]: https://openwrt.org/toh/gl.inet/gl-mt300n_v2 84 | [GL.iNet GL-MV1000]: https://openwrt.org/toh/gl.inet/gl-mv1000 85 | [HooToo HT-TM02]: https://openwrt.org/toh/hootoo/tripmate-nano 86 | [TP-Link TL-MR3020 v1]: https://openwrt.org/toh/tp-link/tl-mr3020 87 | [TP-Link TL-MR3020 v3]: https://openwrt.org/toh/tp-link/tl-mr3020_v3 88 | [TP-Link TL-MR3040 v2]: https://openwrt.org/toh/tp-link/tl-mr3040 89 | [TP-Link TL-WR810N(EU) v1.1]: https://openwrt.org/toh/tp-link/tl-wr810n 90 | [TP-Link TL-WR810N(EU) v2]: https://openwrt.org/toh/tp-link/tl-wr810n 91 | [TP-Link TL-WR902AC v1]: https://openwrt.org/toh/tp-link/tl-wr902ac_v1 92 | [TP-Link TL-WR902AC v3]: https://openwrt.org/toh/tp-link/tl-wr902ac_v3 93 | 94 | ## Changelog 95 | 96 | See [NEWS][]. 97 | 98 | ### Backward-Incompatible Changes 99 | 100 | #### 1.0.0 101 | 102 | * GL.iNet GL-AR150, 103 | GL.iNet GL-AR300M, 104 | GL.iNet GL-MT300A, 105 | GL.iNet GL-MT300N v1, 106 | GL.iNet GL-MT300N v2: 107 | * Changed switch name from *switch* to *mode* 108 | * GL.iNet GL-AR750, 109 | GL.iNet GL-AR750S: 110 | * Changed switch name from *switch* to *mode* 111 | * Changed position names from "left" and "right" to "clear" and "dot", 112 | respectively 113 | 114 | [NEWS]: NEWS.md 115 | 116 | ## Contributing 117 | 118 | Beyond code for bug fixes or new features, any help to verify switch 119 | data or add data for new devices would be greatly appreciated. 120 | 121 | ## License 122 | 123 | Copyright (C) 2016-2019, 2022 The slide-switch authors 124 | 125 | 126 | slide-switch is free software; you can redistribute it and/or 127 | modify it under the terms of the GNU General Public License 128 | version 2 as published by the Free Software Foundation. 129 | 130 | slide-switch is distributed in the hope that it will be useful, 131 | but WITHOUT ANY WARRANTY; without even the implied warranty of 132 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 133 | GNU General Public License for more details. 134 | 135 | You should have received a copy of the GNU General Public License 136 | along with slide-switch. If not, see . 137 | -------------------------------------------------------------------------------- /INSTALL: -------------------------------------------------------------------------------- 1 | Installation Instructions 2 | ************************* 3 | 4 | Copyright (C) 1994-1996, 1999-2002, 2004-2016 Free Software 5 | Foundation, Inc. 6 | 7 | Copying and distribution of this file, with or without modification, 8 | are permitted in any medium without royalty provided the copyright 9 | notice and this notice are preserved. This file is offered as-is, 10 | without warranty of any kind. 11 | 12 | Basic Installation 13 | ================== 14 | 15 | Briefly, the shell command './configure && make && make install' 16 | should configure, build, and install this package. The following 17 | more-detailed instructions are generic; see the 'README' file for 18 | instructions specific to this package. Some packages provide this 19 | 'INSTALL' file but do not implement all of the features documented 20 | below. The lack of an optional feature in a given package is not 21 | necessarily a bug. More recommendations for GNU packages can be found 22 | in *note Makefile Conventions: (standards)Makefile Conventions. 23 | 24 | The 'configure' shell script attempts to guess correct values for 25 | various system-dependent variables used during compilation. It uses 26 | those values to create a 'Makefile' in each directory of the package. 27 | It may also create one or more '.h' files containing system-dependent 28 | definitions. Finally, it creates a shell script 'config.status' that 29 | you can run in the future to recreate the current configuration, and a 30 | file 'config.log' containing compiler output (useful mainly for 31 | debugging 'configure'). 32 | 33 | It can also use an optional file (typically called 'config.cache' and 34 | enabled with '--cache-file=config.cache' or simply '-C') that saves the 35 | results of its tests to speed up reconfiguring. Caching is disabled by 36 | default to prevent problems with accidental use of stale cache files. 37 | 38 | If you need to do unusual things to compile the package, please try 39 | to figure out how 'configure' could check whether to do them, and mail 40 | diffs or instructions to the address given in the 'README' so they can 41 | be considered for the next release. If you are using the cache, and at 42 | some point 'config.cache' contains results you don't want to keep, you 43 | may remove or edit it. 44 | 45 | The file 'configure.ac' (or 'configure.in') is used to create 46 | 'configure' by a program called 'autoconf'. You need 'configure.ac' if 47 | you want to change it or regenerate 'configure' using a newer version of 48 | 'autoconf'. 49 | 50 | The simplest way to compile this package is: 51 | 52 | 1. 'cd' to the directory containing the package's source code and type 53 | './configure' to configure the package for your system. 54 | 55 | Running 'configure' might take a while. While running, it prints 56 | some messages telling which features it is checking for. 57 | 58 | 2. Type 'make' to compile the package. 59 | 60 | 3. Optionally, type 'make check' to run any self-tests that come with 61 | the package, generally using the just-built uninstalled binaries. 62 | 63 | 4. Type 'make install' to install the programs and any data files and 64 | documentation. When installing into a prefix owned by root, it is 65 | recommended that the package be configured and built as a regular 66 | user, and only the 'make install' phase executed with root 67 | privileges. 68 | 69 | 5. Optionally, type 'make installcheck' to repeat any self-tests, but 70 | this time using the binaries in their final installed location. 71 | This target does not install anything. Running this target as a 72 | regular user, particularly if the prior 'make install' required 73 | root privileges, verifies that the installation completed 74 | correctly. 75 | 76 | 6. You can remove the program binaries and object files from the 77 | source code directory by typing 'make clean'. To also remove the 78 | files that 'configure' created (so you can compile the package for 79 | a different kind of computer), type 'make distclean'. There is 80 | also a 'make maintainer-clean' target, but that is intended mainly 81 | for the package's developers. If you use it, you may have to get 82 | all sorts of other programs in order to regenerate files that came 83 | with the distribution. 84 | 85 | 7. Often, you can also type 'make uninstall' to remove the installed 86 | files again. In practice, not all packages have tested that 87 | uninstallation works correctly, even though it is required by the 88 | GNU Coding Standards. 89 | 90 | 8. Some packages, particularly those that use Automake, provide 'make 91 | distcheck', which can by used by developers to test that all other 92 | targets like 'make install' and 'make uninstall' work correctly. 93 | This target is generally not run by end users. 94 | 95 | Compilers and Options 96 | ===================== 97 | 98 | Some systems require unusual options for compilation or linking that 99 | the 'configure' script does not know about. Run './configure --help' 100 | for details on some of the pertinent environment variables. 101 | 102 | You can give 'configure' initial values for configuration parameters 103 | by setting variables in the command line or in the environment. Here is 104 | an example: 105 | 106 | ./configure CC=c99 CFLAGS=-g LIBS=-lposix 107 | 108 | *Note Defining Variables::, for more details. 109 | 110 | Compiling For Multiple Architectures 111 | ==================================== 112 | 113 | You can compile the package for more than one kind of computer at the 114 | same time, by placing the object files for each architecture in their 115 | own directory. To do this, you can use GNU 'make'. 'cd' to the 116 | directory where you want the object files and executables to go and run 117 | the 'configure' script. 'configure' automatically checks for the source 118 | code in the directory that 'configure' is in and in '..'. This is known 119 | as a "VPATH" build. 120 | 121 | With a non-GNU 'make', it is safer to compile the package for one 122 | architecture at a time in the source code directory. After you have 123 | installed the package for one architecture, use 'make distclean' before 124 | reconfiguring for another architecture. 125 | 126 | On MacOS X 10.5 and later systems, you can create libraries and 127 | executables that work on multiple system types--known as "fat" or 128 | "universal" binaries--by specifying multiple '-arch' options to the 129 | compiler but only a single '-arch' option to the preprocessor. Like 130 | this: 131 | 132 | ./configure CC="gcc -arch i386 -arch x86_64 -arch ppc -arch ppc64" \ 133 | CXX="g++ -arch i386 -arch x86_64 -arch ppc -arch ppc64" \ 134 | CPP="gcc -E" CXXCPP="g++ -E" 135 | 136 | This is not guaranteed to produce working output in all cases, you 137 | may have to build one architecture at a time and combine the results 138 | using the 'lipo' tool if you have problems. 139 | 140 | Installation Names 141 | ================== 142 | 143 | By default, 'make install' installs the package's commands under 144 | '/usr/local/bin', include files under '/usr/local/include', etc. You 145 | can specify an installation prefix other than '/usr/local' by giving 146 | 'configure' the option '--prefix=PREFIX', where PREFIX must be an 147 | absolute file name. 148 | 149 | You can specify separate installation prefixes for 150 | architecture-specific files and architecture-independent files. If you 151 | pass the option '--exec-prefix=PREFIX' to 'configure', the package uses 152 | PREFIX as the prefix for installing programs and libraries. 153 | Documentation and other data files still use the regular prefix. 154 | 155 | In addition, if you use an unusual directory layout you can give 156 | options like '--bindir=DIR' to specify different values for particular 157 | kinds of files. Run 'configure --help' for a list of the directories 158 | you can set and what kinds of files go in them. In general, the default 159 | for these options is expressed in terms of '${prefix}', so that 160 | specifying just '--prefix' will affect all of the other directory 161 | specifications that were not explicitly provided. 162 | 163 | The most portable way to affect installation locations is to pass the 164 | correct locations to 'configure'; however, many packages provide one or 165 | both of the following shortcuts of passing variable assignments to the 166 | 'make install' command line to change installation locations without 167 | having to reconfigure or recompile. 168 | 169 | The first method involves providing an override variable for each 170 | affected directory. For example, 'make install 171 | prefix=/alternate/directory' will choose an alternate location for all 172 | directory configuration variables that were expressed in terms of 173 | '${prefix}'. Any directories that were specified during 'configure', 174 | but not in terms of '${prefix}', must each be overridden at install time 175 | for the entire installation to be relocated. The approach of makefile 176 | variable overrides for each directory variable is required by the GNU 177 | Coding Standards, and ideally causes no recompilation. However, some 178 | platforms have known limitations with the semantics of shared libraries 179 | that end up requiring recompilation when using this method, particularly 180 | noticeable in packages that use GNU Libtool. 181 | 182 | The second method involves providing the 'DESTDIR' variable. For 183 | example, 'make install DESTDIR=/alternate/directory' will prepend 184 | '/alternate/directory' before all installation names. The approach of 185 | 'DESTDIR' overrides is not required by the GNU Coding Standards, and 186 | does not work on platforms that have drive letters. On the other hand, 187 | it does better at avoiding recompilation issues, and works well even 188 | when some directory options were not specified in terms of '${prefix}' 189 | at 'configure' time. 190 | 191 | Optional Features 192 | ================= 193 | 194 | If the package supports it, you can cause programs to be installed 195 | with an extra prefix or suffix on their names by giving 'configure' the 196 | option '--program-prefix=PREFIX' or '--program-suffix=SUFFIX'. 197 | 198 | Some packages pay attention to '--enable-FEATURE' options to 199 | 'configure', where FEATURE indicates an optional part of the package. 200 | They may also pay attention to '--with-PACKAGE' options, where PACKAGE 201 | is something like 'gnu-as' or 'x' (for the X Window System). The 202 | 'README' should mention any '--enable-' and '--with-' options that the 203 | package recognizes. 204 | 205 | For packages that use the X Window System, 'configure' can usually 206 | find the X include and library files automatically, but if it doesn't, 207 | you can use the 'configure' options '--x-includes=DIR' and 208 | '--x-libraries=DIR' to specify their locations. 209 | 210 | Some packages offer the ability to configure how verbose the 211 | execution of 'make' will be. For these packages, running './configure 212 | --enable-silent-rules' sets the default to minimal output, which can be 213 | overridden with 'make V=1'; while running './configure 214 | --disable-silent-rules' sets the default to verbose, which can be 215 | overridden with 'make V=0'. 216 | 217 | Particular systems 218 | ================== 219 | 220 | On HP-UX, the default C compiler is not ANSI C compatible. If GNU CC 221 | is not installed, it is recommended to use the following options in 222 | order to use an ANSI C compiler: 223 | 224 | ./configure CC="cc -Ae -D_XOPEN_SOURCE=500" 225 | 226 | and if that doesn't work, install pre-built binaries of GCC for HP-UX. 227 | 228 | HP-UX 'make' updates targets which have the same time stamps as their 229 | prerequisites, which makes it generally unusable when shipped generated 230 | files such as 'configure' are involved. Use GNU 'make' instead. 231 | 232 | On OSF/1 a.k.a. Tru64, some versions of the default C compiler cannot 233 | parse its '' header file. The option '-nodtk' can be used as a 234 | workaround. If GNU CC is not installed, it is therefore recommended to 235 | try 236 | 237 | ./configure CC="cc" 238 | 239 | and if that doesn't work, try 240 | 241 | ./configure CC="cc -nodtk" 242 | 243 | On Solaris, don't put '/usr/ucb' early in your 'PATH'. This 244 | directory contains several dysfunctional programs; working variants of 245 | these programs are available in '/usr/bin'. So, if you need '/usr/ucb' 246 | in your 'PATH', put it _after_ '/usr/bin'. 247 | 248 | On Haiku, software installed for all users goes in '/boot/common', 249 | not '/usr/local'. It is recommended to use the following options: 250 | 251 | ./configure --prefix=/boot/common 252 | 253 | Specifying the System Type 254 | ========================== 255 | 256 | There may be some features 'configure' cannot figure out 257 | automatically, but needs to determine by the type of machine the package 258 | will run on. Usually, assuming the package is built to be run on the 259 | _same_ architectures, 'configure' can figure that out, but if it prints 260 | a message saying it cannot guess the machine type, give it the 261 | '--build=TYPE' option. TYPE can either be a short name for the system 262 | type, such as 'sun4', or a canonical name which has the form: 263 | 264 | CPU-COMPANY-SYSTEM 265 | 266 | where SYSTEM can have one of these forms: 267 | 268 | OS 269 | KERNEL-OS 270 | 271 | See the file 'config.sub' for the possible values of each field. If 272 | 'config.sub' isn't included in this package, then this package doesn't 273 | need to know the machine type. 274 | 275 | If you are _building_ compiler tools for cross-compiling, you should 276 | use the option '--target=TYPE' to select the type of system they will 277 | produce code for. 278 | 279 | If you want to _use_ a cross compiler, that generates code for a 280 | platform different from the build platform, you should specify the 281 | "host" platform (i.e., that on which the generated programs will 282 | eventually be run) with '--host=TYPE'. 283 | 284 | Sharing Defaults 285 | ================ 286 | 287 | If you want to set default values for 'configure' scripts to share, 288 | you can create a site shell script called 'config.site' that gives 289 | default values for variables like 'CC', 'cache_file', and 'prefix'. 290 | 'configure' looks for 'PREFIX/share/config.site' if it exists, then 291 | 'PREFIX/etc/config.site' if it exists. Or, you can set the 292 | 'CONFIG_SITE' environment variable to the location of the site script. 293 | A warning: not all 'configure' scripts look for a site script. 294 | 295 | Defining Variables 296 | ================== 297 | 298 | Variables not defined in a site shell script can be set in the 299 | environment passed to 'configure'. However, some packages may run 300 | configure again during the build, and the customized values of these 301 | variables may be lost. In order to avoid this problem, you should set 302 | them in the 'configure' command line, using 'VAR=value'. For example: 303 | 304 | ./configure CC=/usr/local2/bin/gcc 305 | 306 | causes the specified 'gcc' to be used as the C compiler (unless it is 307 | overridden in the site shell script). 308 | 309 | Unfortunately, this technique does not work for 'CONFIG_SHELL' due to an 310 | Autoconf limitation. Until the limitation is lifted, you can use this 311 | workaround: 312 | 313 | CONFIG_SHELL=/bin/bash ./configure CONFIG_SHELL=/bin/bash 314 | 315 | 'configure' Invocation 316 | ====================== 317 | 318 | 'configure' recognizes the following options to control how it 319 | operates. 320 | 321 | '--help' 322 | '-h' 323 | Print a summary of all of the options to 'configure', and exit. 324 | 325 | '--help=short' 326 | '--help=recursive' 327 | Print a summary of the options unique to this package's 328 | 'configure', and exit. The 'short' variant lists options used only 329 | in the top level, while the 'recursive' variant lists options also 330 | present in any nested packages. 331 | 332 | '--version' 333 | '-V' 334 | Print the version of Autoconf used to generate the 'configure' 335 | script, and exit. 336 | 337 | '--cache-file=FILE' 338 | Enable the cache: use and save the results of the tests in FILE, 339 | traditionally 'config.cache'. FILE defaults to '/dev/null' to 340 | disable caching. 341 | 342 | '--config-cache' 343 | '-C' 344 | Alias for '--cache-file=config.cache'. 345 | 346 | '--quiet' 347 | '--silent' 348 | '-q' 349 | Do not print messages saying which checks are being made. To 350 | suppress all normal output, redirect it to '/dev/null' (any error 351 | messages will still be shown). 352 | 353 | '--srcdir=DIR' 354 | Look for the package's source code in directory DIR. Usually 355 | 'configure' can determine that directory automatically. 356 | 357 | '--prefix=DIR' 358 | Use DIR as the installation prefix. *note Installation Names:: for 359 | more details, including other options available for fine-tuning the 360 | installation locations. 361 | 362 | '--no-create' 363 | '-n' 364 | Run the configure checks, but stop before creating any output 365 | files. 366 | 367 | 'configure' also accepts some other, not widely useful, options. Run 368 | 'configure --help' for more details. 369 | -------------------------------------------------------------------------------- /COPYING: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 2, June 1991 3 | 4 | Copyright (C) 1989, 1991 Free Software Foundation, Inc., 5 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 6 | Everyone is permitted to copy and distribute verbatim copies 7 | of this license document, but changing it is not allowed. 8 | 9 | Preamble 10 | 11 | The licenses for most software are designed to take away your 12 | freedom to share and change it. By contrast, the GNU General Public 13 | License is intended to guarantee your freedom to share and change free 14 | software--to make sure the software is free for all its users. This 15 | General Public License applies to most of the Free Software 16 | Foundation's software and to any other program whose authors commit to 17 | using it. (Some other Free Software Foundation software is covered by 18 | the GNU Lesser General Public License instead.) You can apply it to 19 | your programs, too. 20 | 21 | When we speak of free software, we are referring to freedom, not 22 | price. Our General Public Licenses are designed to make sure that you 23 | have the freedom to distribute copies of free software (and charge for 24 | this service if you wish), that you receive source code or can get it 25 | if you want it, that you can change the software or use pieces of it 26 | in new free programs; and that you know you can do these things. 27 | 28 | To protect your rights, we need to make restrictions that forbid 29 | anyone to deny you these rights or to ask you to surrender the rights. 30 | These restrictions translate to certain responsibilities for you if you 31 | distribute copies of the software, or if you modify it. 32 | 33 | For example, if you distribute copies of such a program, whether 34 | gratis or for a fee, you must give the recipients all the rights that 35 | you have. You must make sure that they, too, receive or can get the 36 | source code. And you must show them these terms so they know their 37 | rights. 38 | 39 | We protect your rights with two steps: (1) copyright the software, and 40 | (2) offer you this license which gives you legal permission to copy, 41 | distribute and/or modify the software. 42 | 43 | Also, for each author's protection and ours, we want to make certain 44 | that everyone understands that there is no warranty for this free 45 | software. If the software is modified by someone else and passed on, we 46 | want its recipients to know that what they have is not the original, so 47 | that any problems introduced by others will not reflect on the original 48 | authors' reputations. 49 | 50 | Finally, any free program is threatened constantly by software 51 | patents. We wish to avoid the danger that redistributors of a free 52 | program will individually obtain patent licenses, in effect making the 53 | program proprietary. To prevent this, we have made it clear that any 54 | patent must be licensed for everyone's free use or not licensed at all. 55 | 56 | The precise terms and conditions for copying, distribution and 57 | modification follow. 58 | 59 | GNU GENERAL PUBLIC LICENSE 60 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 61 | 62 | 0. This License applies to any program or other work which contains 63 | a notice placed by the copyright holder saying it may be distributed 64 | under the terms of this General Public License. The "Program", below, 65 | refers to any such program or work, and a "work based on the Program" 66 | means either the Program or any derivative work under copyright law: 67 | that is to say, a work containing the Program or a portion of it, 68 | either verbatim or with modifications and/or translated into another 69 | language. (Hereinafter, translation is included without limitation in 70 | the term "modification".) Each licensee is addressed as "you". 71 | 72 | Activities other than copying, distribution and modification are not 73 | covered by this License; they are outside its scope. The act of 74 | running the Program is not restricted, and the output from the Program 75 | is covered only if its contents constitute a work based on the 76 | Program (independent of having been made by running the Program). 77 | Whether that is true depends on what the Program does. 78 | 79 | 1. You may copy and distribute verbatim copies of the Program's 80 | source code as you receive it, in any medium, provided that you 81 | conspicuously and appropriately publish on each copy an appropriate 82 | copyright notice and disclaimer of warranty; keep intact all the 83 | notices that refer to this License and to the absence of any warranty; 84 | and give any other recipients of the Program a copy of this License 85 | along with the Program. 86 | 87 | You may charge a fee for the physical act of transferring a copy, and 88 | you may at your option offer warranty protection in exchange for a fee. 89 | 90 | 2. You may modify your copy or copies of the Program or any portion 91 | of it, thus forming a work based on the Program, and copy and 92 | distribute such modifications or work under the terms of Section 1 93 | above, provided that you also meet all of these conditions: 94 | 95 | a) You must cause the modified files to carry prominent notices 96 | stating that you changed the files and the date of any change. 97 | 98 | b) You must cause any work that you distribute or publish, that in 99 | whole or in part contains or is derived from the Program or any 100 | part thereof, to be licensed as a whole at no charge to all third 101 | parties under the terms of this License. 102 | 103 | c) If the modified program normally reads commands interactively 104 | when run, you must cause it, when started running for such 105 | interactive use in the most ordinary way, to print or display an 106 | announcement including an appropriate copyright notice and a 107 | notice that there is no warranty (or else, saying that you provide 108 | a warranty) and that users may redistribute the program under 109 | these conditions, and telling the user how to view a copy of this 110 | License. (Exception: if the Program itself is interactive but 111 | does not normally print such an announcement, your work based on 112 | the Program is not required to print an announcement.) 113 | 114 | These requirements apply to the modified work as a whole. If 115 | identifiable sections of that work are not derived from the Program, 116 | and can be reasonably considered independent and separate works in 117 | themselves, then this License, and its terms, do not apply to those 118 | sections when you distribute them as separate works. But when you 119 | distribute the same sections as part of a whole which is a work based 120 | on the Program, the distribution of the whole must be on the terms of 121 | this License, whose permissions for other licensees extend to the 122 | entire whole, and thus to each and every part regardless of who wrote it. 123 | 124 | Thus, it is not the intent of this section to claim rights or contest 125 | your rights to work written entirely by you; rather, the intent is to 126 | exercise the right to control the distribution of derivative or 127 | collective works based on the Program. 128 | 129 | In addition, mere aggregation of another work not based on the Program 130 | with the Program (or with a work based on the Program) on a volume of 131 | a storage or distribution medium does not bring the other work under 132 | the scope of this License. 133 | 134 | 3. You may copy and distribute the Program (or a work based on it, 135 | under Section 2) in object code or executable form under the terms of 136 | Sections 1 and 2 above provided that you also do one of the following: 137 | 138 | a) Accompany it with the complete corresponding machine-readable 139 | source code, which must be distributed under the terms of Sections 140 | 1 and 2 above on a medium customarily used for software interchange; or, 141 | 142 | b) Accompany it with a written offer, valid for at least three 143 | years, to give any third party, for a charge no more than your 144 | cost of physically performing source distribution, a complete 145 | machine-readable copy of the corresponding source code, to be 146 | distributed under the terms of Sections 1 and 2 above on a medium 147 | customarily used for software interchange; or, 148 | 149 | c) Accompany it with the information you received as to the offer 150 | to distribute corresponding source code. (This alternative is 151 | allowed only for noncommercial distribution and only if you 152 | received the program in object code or executable form with such 153 | an offer, in accord with Subsection b above.) 154 | 155 | The source code for a work means the preferred form of the work for 156 | making modifications to it. For an executable work, complete source 157 | code means all the source code for all modules it contains, plus any 158 | associated interface definition files, plus the scripts used to 159 | control compilation and installation of the executable. However, as a 160 | special exception, the source code distributed need not include 161 | anything that is normally distributed (in either source or binary 162 | form) with the major components (compiler, kernel, and so on) of the 163 | operating system on which the executable runs, unless that component 164 | itself accompanies the executable. 165 | 166 | If distribution of executable or object code is made by offering 167 | access to copy from a designated place, then offering equivalent 168 | access to copy the source code from the same place counts as 169 | distribution of the source code, even though third parties are not 170 | compelled to copy the source along with the object code. 171 | 172 | 4. You may not copy, modify, sublicense, or distribute the Program 173 | except as expressly provided under this License. Any attempt 174 | otherwise to copy, modify, sublicense or distribute the Program is 175 | void, and will automatically terminate your rights under this License. 176 | However, parties who have received copies, or rights, from you under 177 | this License will not have their licenses terminated so long as such 178 | parties remain in full compliance. 179 | 180 | 5. You are not required to accept this License, since you have not 181 | signed it. However, nothing else grants you permission to modify or 182 | distribute the Program or its derivative works. These actions are 183 | prohibited by law if you do not accept this License. Therefore, by 184 | modifying or distributing the Program (or any work based on the 185 | Program), you indicate your acceptance of this License to do so, and 186 | all its terms and conditions for copying, distributing or modifying 187 | the Program or works based on it. 188 | 189 | 6. Each time you redistribute the Program (or any work based on the 190 | Program), the recipient automatically receives a license from the 191 | original licensor to copy, distribute or modify the Program subject to 192 | these terms and conditions. You may not impose any further 193 | restrictions on the recipients' exercise of the rights granted herein. 194 | You are not responsible for enforcing compliance by third parties to 195 | this License. 196 | 197 | 7. If, as a consequence of a court judgment or allegation of patent 198 | infringement or for any other reason (not limited to patent issues), 199 | conditions are imposed on you (whether by court order, agreement or 200 | otherwise) that contradict the conditions of this License, they do not 201 | excuse you from the conditions of this License. If you cannot 202 | distribute so as to satisfy simultaneously your obligations under this 203 | License and any other pertinent obligations, then as a consequence you 204 | may not distribute the Program at all. For example, if a patent 205 | license would not permit royalty-free redistribution of the Program by 206 | all those who receive copies directly or indirectly through you, then 207 | the only way you could satisfy both it and this License would be to 208 | refrain entirely from distribution of the Program. 209 | 210 | If any portion of this section is held invalid or unenforceable under 211 | any particular circumstance, the balance of the section is intended to 212 | apply and the section as a whole is intended to apply in other 213 | circumstances. 214 | 215 | It is not the purpose of this section to induce you to infringe any 216 | patents or other property right claims or to contest validity of any 217 | such claims; this section has the sole purpose of protecting the 218 | integrity of the free software distribution system, which is 219 | implemented by public license practices. Many people have made 220 | generous contributions to the wide range of software distributed 221 | through that system in reliance on consistent application of that 222 | system; it is up to the author/donor to decide if he or she is willing 223 | to distribute software through any other system and a licensee cannot 224 | impose that choice. 225 | 226 | This section is intended to make thoroughly clear what is believed to 227 | be a consequence of the rest of this License. 228 | 229 | 8. If the distribution and/or use of the Program is restricted in 230 | certain countries either by patents or by copyrighted interfaces, the 231 | original copyright holder who places the Program under this License 232 | may add an explicit geographical distribution limitation excluding 233 | those countries, so that distribution is permitted only in or among 234 | countries not thus excluded. In such case, this License incorporates 235 | the limitation as if written in the body of this License. 236 | 237 | 9. The Free Software Foundation may publish revised and/or new versions 238 | of the General Public License from time to time. Such new versions will 239 | be similar in spirit to the present version, but may differ in detail to 240 | address new problems or concerns. 241 | 242 | Each version is given a distinguishing version number. If the Program 243 | specifies a version number of this License which applies to it and "any 244 | later version", you have the option of following the terms and conditions 245 | either of that version or of any later version published by the Free 246 | Software Foundation. If the Program does not specify a version number of 247 | this License, you may choose any version ever published by the Free Software 248 | Foundation. 249 | 250 | 10. If you wish to incorporate parts of the Program into other free 251 | programs whose distribution conditions are different, write to the author 252 | to ask for permission. For software which is copyrighted by the Free 253 | Software Foundation, write to the Free Software Foundation; we sometimes 254 | make exceptions for this. Our decision will be guided by the two goals 255 | of preserving the free status of all derivatives of our free software and 256 | of promoting the sharing and reuse of software generally. 257 | 258 | NO WARRANTY 259 | 260 | 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY 261 | FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN 262 | OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES 263 | PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED 264 | OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 265 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS 266 | TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE 267 | PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, 268 | REPAIR OR CORRECTION. 269 | 270 | 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 271 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR 272 | REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, 273 | INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING 274 | OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED 275 | TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY 276 | YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER 277 | PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE 278 | POSSIBILITY OF SUCH DAMAGES. 279 | 280 | END OF TERMS AND CONDITIONS 281 | 282 | How to Apply These Terms to Your New Programs 283 | 284 | If you develop a new program, and you want it to be of the greatest 285 | possible use to the public, the best way to achieve this is to make it 286 | free software which everyone can redistribute and change under these terms. 287 | 288 | To do so, attach the following notices to the program. It is safest 289 | to attach them to the start of each source file to most effectively 290 | convey the exclusion of warranty; and each file should have at least 291 | the "copyright" line and a pointer to where the full notice is found. 292 | 293 | 294 | Copyright (C) 295 | 296 | This program is free software; you can redistribute it and/or modify 297 | it under the terms of the GNU General Public License as published by 298 | the Free Software Foundation; either version 2 of the License, or 299 | (at your option) any later version. 300 | 301 | This program is distributed in the hope that it will be useful, 302 | but WITHOUT ANY WARRANTY; without even the implied warranty of 303 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 304 | GNU General Public License for more details. 305 | 306 | You should have received a copy of the GNU General Public License along 307 | with this program; if not, write to the Free Software Foundation, Inc., 308 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 309 | 310 | Also add information on how to contact you by electronic and paper mail. 311 | 312 | If the program is interactive, make it output a short notice like this 313 | when it starts in an interactive mode: 314 | 315 | Gnomovision version 69, Copyright (C) year name of author 316 | Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 317 | This is free software, and you are welcome to redistribute it 318 | under certain conditions; type `show c' for details. 319 | 320 | The hypothetical commands `show w' and `show c' should show the appropriate 321 | parts of the General Public License. Of course, the commands you use may 322 | be called something other than `show w' and `show c'; they could even be 323 | mouse-clicks or menu items--whatever suits your program. 324 | 325 | You should also get your employer (if you work as a programmer) or your 326 | school, if any, to sign a "copyright disclaimer" for the program, if 327 | necessary. Here is a sample; alter the names: 328 | 329 | Yoyodyne, Inc., hereby disclaims all copyright interest in the program 330 | `Gnomovision' (which makes passes at compilers) written by James Hacker. 331 | 332 | , 1 April 1989 333 | Ty Coon, President of Vice 334 | 335 | This General Public License does not permit incorporating your program into 336 | proprietary programs. If your program is a subroutine library, you may 337 | consider it more useful to permit linking proprietary applications with the 338 | library. If this is what you want to do, use the GNU Lesser General 339 | Public License instead of this License. 340 | -------------------------------------------------------------------------------- /src/usr/share/slide-switch/functions.sh-cut: -------------------------------------------------------------------------------- 1 | # 2 | # src/usr/share/slide-switch/functions.sh-cut.in 3 | # This file is part of slide-switch. 4 | # 5 | # Copyright (C) 2016-2019, 2022 The slide-switch authors 6 | # https://github.com/jefferyto/openwrt-slide-switch 7 | # 8 | # slide-switch is free software; you can redistribute it and/or 9 | # modify it under the terms of the GNU General Public License 10 | # version 2 as published by the Free Software Foundation. 11 | # 12 | # slide-switch is distributed in the hope that it will be useful, 13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | # GNU General Public License for more details. 16 | # 17 | # You should have received a copy of the GNU General Public License 18 | # along with slide-switch. If not, see . 19 | # 20 | # --8<---- CUT HERE 21 | # 22 | # Copyright (C) 2016-2019, 2022 The slide-switch authors 23 | # https://github.com/jefferyto/openwrt-slide-switch 24 | # 25 | # slide-switch is free software, licensed under the GNU General Public License v2. 26 | # 27 | 28 | package=@PACKAGE@ 29 | version=@VERSION@ 30 | 31 | data_dir=@pkgdatadir@ 32 | run_dir=@localstatedir@/run/@PACKAGE@ 33 | lock_dir=@localstatedir@/lock/@PACKAGE@ 34 | conf_dir=@sysconfdir@/@PACKAGE@ 35 | initd_dir=@sysconfdir@/init.d 36 | 37 | board_name=/tmp/sysinfo/board_name 38 | gpio_table=/sys/kernel/debug/gpio 39 | device_tree_keys=/proc/device-tree/keys 40 | device_tree_gpio_keys=/proc/device-tree/gpio-keys 41 | hotplug_call=/sbin/hotplug-call 42 | rc_button=/etc/rc.button 43 | 44 | custom_switch_data_file=$conf_dir/switch-data.json 45 | switch_data_file=$data_dir/switch-data.json 46 | switches_cache=$run_dir/switches 47 | state_dir=$run_dir/state 48 | update_initd_script=$initd_dir/zzz-slide-switch-update 49 | 50 | . /usr/share/libubox/jshn.sh 51 | 52 | me=${0##*/} 53 | 54 | ex_usage=64 55 | ex_dataerr=65 56 | ex_noinput=66 57 | ex_unavailable=69 58 | ex_oserr=71 59 | ex_osfile=72 60 | ex_noperm=77 61 | 62 | log_stderr= 63 | log_syslog= 64 | verbosity= 65 | is_root_result= 66 | locks= 67 | 68 | 69 | log_level_to_num() { 70 | local _var="$1" 71 | local _level="$2" 72 | local _num 73 | 74 | case $_level in 75 | emerg|panic) _num=0 ;; 76 | alert) _num=1 ;; 77 | crit) _num=2 ;; 78 | err|error) _num=3 ;; 79 | warning|warn) _num=4 ;; 80 | notice) _num=5 ;; 81 | info) _num=6 ;; 82 | debug) _num=7 ;; 83 | 84 | *[!0-9]*) return 1 ;; 85 | 86 | *) _num=$_level ;; 87 | esac 88 | 89 | _set_var "$_var" "$_num" 90 | } 91 | 92 | log() { 93 | local level="$1" 94 | local message="$2" 95 | local level_num 96 | 97 | log_level_to_num level_num "$level" && 98 | [ "$level_num" -le "$verbosity" ] || return 0 99 | 100 | [ -n "$log_stderr" ] && echo "[$level] $message" >&2 101 | 102 | [ -n "$log_syslog" ] && logger -t "${me}[$$]" -p "user.$level" "$message" 103 | 104 | return 0 105 | } 106 | 107 | error() { 108 | log err "$@" 109 | } 110 | 111 | warning() { 112 | log warning "$@" 113 | } 114 | 115 | notice() { 116 | log notice "$@" 117 | } 118 | 119 | info() { 120 | log info "$@" 121 | } 122 | 123 | debug() { 124 | log debug "$@" 125 | } 126 | 127 | 128 | is_root() { 129 | local uid 130 | 131 | [ -n "$is_root_result" ] || { 132 | uid=$(id -u) && [ "$uid" -eq 0 ] 133 | is_root_result=$? 134 | } 135 | 136 | return $is_root_result 137 | } 138 | 139 | require_root() { 140 | is_root || { 141 | error "require_root: user must be root" 142 | return $ex_noperm 143 | } 144 | } 145 | 146 | get_board() { 147 | local _var="$1" 148 | local _board 149 | 150 | _board=$(cat "$board_name") && _set_var "$_var" "$_board" 151 | } 152 | 153 | get_epoch() { 154 | local _var="$1" 155 | local _epoch 156 | 157 | _epoch=$(date +%s) || { 158 | error "get_epoch: failed to get date" 159 | return $ex_oserr 160 | } 161 | 162 | _set_var "$_var" "$_epoch" 163 | } 164 | 165 | list_contains() { 166 | local list=" $1 " 167 | local item=" $2 " 168 | 169 | [ -z "${list##*$item*}" ] 170 | } 171 | 172 | is_safe_string() { 173 | local str="$1" 174 | 175 | [ -n "${str##*[!0-9A-Za-z_-]*}" ] 176 | } 177 | 178 | 179 | check_prerequisites() { 180 | local file 181 | 182 | for file in "$board_name" "$gpio_table"; do 183 | [ -f "$file" ] && [ -r "$file" ] || { 184 | error "check_prerequisites: cannot read $file" 185 | return $ex_osfile 186 | } 187 | done 188 | 189 | [ -f "$switch_data_file" ] && [ -r "$switch_data_file" ] || { 190 | error "check_prerequisites: cannot read $switch_data_file" 191 | return $ex_noinput 192 | } 193 | } 194 | 195 | 196 | get_gpio_value() { 197 | local __var="$1" 198 | local __label="$2" 199 | local __allow_no_matches="$3" 200 | local __pattern 201 | local __match 202 | local __result 203 | 204 | __pattern=$(printf '|%-20.20s) in \(hi\|lo\)' "$__label") || { 205 | error "get_gpio_value: failed to get search pattern for label \"$__label\"" 206 | return $ex_oserr 207 | } 208 | 209 | __match="$(grep -m 1 -o -e "$__pattern" "$gpio_table" 2>/dev/null)" 210 | __result=$? 211 | 212 | [ "$__result" -eq 0 ] || { 213 | [ "$__result" -eq 1 ] && { 214 | [ -z "$__allow_no_matches" ] && error "get_gpio_value: cannot find label \"$__label\" in $gpio_table" 215 | return $ex_dataerr 216 | } 217 | 218 | error "get_gpio_value: failed to search $gpio_table for label \"$__label\"" 219 | return $ex_oserr 220 | } 221 | 222 | _set_var "$__var" "${__match##*) in }" 223 | } 224 | 225 | get_position_code() { 226 | local _var="$1" 227 | local _switch="$2" 228 | local _position_name="$3" 229 | 230 | _set_var "$_var" "${_switch}-$_position_name" 231 | } 232 | 233 | 234 | is_keys_available() { 235 | [ -d "$device_tree_keys" ] || [ -d "$device_tree_gpio_keys" ] 236 | } 237 | 238 | is_key() { 239 | local key="$1" 240 | 241 | [ -d "$device_tree_keys/$key" ] || [ -d "$device_tree_gpio_keys/$key" ] 242 | } 243 | 244 | get_key_label_path() { 245 | local __var="$1" 246 | local __key="$2" 247 | local __key_path="$device_tree_keys/$__key" 248 | 249 | [ -d "$__key_path" ] || __key_path="$device_tree_gpio_keys/$__key" 250 | 251 | _set_var "$__var" "$__key_path/label" 252 | } 253 | 254 | get_key_code_path() { 255 | local __var="$1" 256 | local __key="$2" 257 | local __key_path="$device_tree_keys/$__key" 258 | 259 | [ -d "$__key_path" ] || __key_path="$device_tree_gpio_keys/$__key" 260 | 261 | _set_var "$__var" "$__key_path/linux,code" 262 | } 263 | 264 | has_key_info() { 265 | local key="$1" 266 | local label_path 267 | local code_path 268 | 269 | get_key_label_path label_path "$key" 270 | get_key_code_path code_path "$key" 271 | 272 | [ -f "$label_path" ] && [ -r "$label_path" ] && 273 | [ -f "$code_path" ] && [ -r "$code_path" ] 274 | } 275 | 276 | get_key_label() { 277 | local _var="$1" 278 | local _key="$2" 279 | local _label_path 280 | local _label 281 | 282 | get_key_label_path _label_path "$_key" 283 | 284 | _label=$(cat "$_label_path") || { 285 | error "get_key_label: failed to read $_label_path" 286 | return $ex_oserr 287 | } 288 | 289 | _set_var "$_var" "$_label" 290 | } 291 | 292 | get_key_code() { 293 | local _var="$1" 294 | local _key="$2" 295 | local _code_path 296 | local _hex 297 | local _code 298 | 299 | get_key_code_path _code_path "$_key" 300 | 301 | _hex=$(hexdump -n 4 -v -e '4/1 "%02x"' "$_code_path") || { 302 | error "get_key_code: failed to read $_code_path" 303 | return $ex_oserr 304 | } 305 | 306 | case $_hex in 307 | 00000100) _code=BTN_0 ;; 308 | 00000101) _code=BTN_1 ;; 309 | 00000102) _code=BTN_2 ;; 310 | 00000103) _code=BTN_3 ;; 311 | 00000104) _code=BTN_4 ;; 312 | 00000105) _code=BTN_5 ;; 313 | 00000106) _code=BTN_6 ;; 314 | 00000107) _code=BTN_7 ;; 315 | 00000108) _code=BTN_8 ;; 316 | 00000109) _code=BTN_9 ;; 317 | esac 318 | 319 | [ -n "$_code" ] || { 320 | error "get_key_code: unknown value \"$_hex\" in $_code_path" 321 | return $ex_osfile 322 | } 323 | 324 | _set_var "$_var" "$_code" 325 | } 326 | 327 | 328 | is_valid_switch_data_file() { 329 | local data_file="$1" 330 | 331 | jsonfilter -q -i "$data_file" -t "@" > /dev/null 332 | 333 | [ "$?" -ne 126 ] 334 | } 335 | 336 | get_switch_data_file_board_value() { 337 | local __option="$1" 338 | local __var="$2" 339 | local __data_file="$3" 340 | local __board="$4" 341 | local __value 342 | 343 | __value=$(jsonfilter -i "$__data_file" "$__option" "@[\"$__board\"]") || __value= 344 | 345 | _set_var "$__var" "$__value" 346 | } 347 | 348 | get_switch_data_file_board_data_type() { 349 | get_switch_data_file_board_value -t "$@" 350 | } 351 | 352 | get_switch_data_file_board_data() { 353 | get_switch_data_file_board_value -e "$@" 354 | } 355 | 356 | 357 | populate_switches_details() { 358 | local switches 359 | local switch 360 | local keys 361 | local key 362 | local label 363 | local code 364 | 365 | json_set_namespace switches 366 | json_select 367 | 368 | json_get_keys switches 369 | 370 | for switch in $switches; do 371 | json_select 372 | json_select "$switch" 373 | 374 | json_is_a labels '' && json_is_a codes '' || { 375 | debug "populate_switches_details: switch \"$switch\" already has labels and/or codes properties" 376 | continue 377 | } 378 | 379 | json_is_a keys array || { 380 | debug "populate_switches_details: switch \"$switch\" does not have a keys array" 381 | continue 382 | } 383 | 384 | json_get_values keys keys 385 | 386 | [ -n "$keys" ] || { 387 | debug "populate_switches_details: no keys defined for switch \"$switch\"" 388 | continue 389 | } 390 | 391 | json_add_array labels 392 | json_close_array 393 | 394 | json_add_array codes 395 | json_close_array 396 | 397 | for key in $keys; do 398 | json_select 399 | json_select "$switch" 400 | 401 | is_key "$key" || { 402 | error "populate_switches_details: key \"$key\" of switch \"$switch\" is not a valid gpio key" 403 | return $ex_dataerr 404 | } 405 | 406 | has_key_info "$key" || { 407 | error "populate_switches_details: key \"$key\" of switch \"$switch\" is missing label and/or linux,code" 408 | return $ex_dataerr 409 | } 410 | 411 | get_key_label label "$key" && 412 | get_key_code code "$key" || return 413 | 414 | debug "populate_switches_details: found label \"$label\" and code \"$code\" for key \"$key\" of switch \"$switch\"" 415 | 416 | json_select labels 417 | 418 | json_add_string '' "$label" 419 | 420 | json_select .. 421 | json_select codes 422 | 423 | json_add_string '' "$code" 424 | done 425 | done 426 | } 427 | 428 | 429 | check_json_type() { 430 | local key="$1" 431 | local type="$2" 432 | local key_name="${3:-$key}" 433 | local article="a" 434 | 435 | case $type in 436 | [aeiou]*) article=an ;; 437 | esac 438 | 439 | json_is_a "$key" "$type" || { 440 | error "check_json_type: \"$key_name\" is not $article $type" 441 | return $ex_dataerr 442 | } 443 | } 444 | 445 | check_nonempty_string() { 446 | local str="$1" 447 | local str_name="$2" 448 | 449 | [ -n "$str" ] || { 450 | error "check_nonempty_string: $str_name cannot be an empty string" 451 | return $ex_dataerr 452 | } 453 | } 454 | 455 | check_safe_string() { 456 | local str="$1" 457 | local str_name="$2" 458 | 459 | is_safe_string "$str" || { 460 | error "check_safe_string: $str_name \"$str\" must contain letters, digits, underscores and/or hyphens only" 461 | return $ex_dataerr 462 | } 463 | } 464 | 465 | check_input_gpio_label() { 466 | local label="$1" 467 | local value 468 | 469 | get_gpio_value value "$label" allow_no_matches && [ -n "$value" ] || { 470 | error "check_input_gpio_label: \"$label\" is not the label of a valid input gpio" 471 | return $ex_dataerr 472 | } 473 | } 474 | 475 | check_position_string() { 476 | local position="$1" 477 | local str="$position" 478 | local prev 479 | 480 | while [ "x$str" != "x$prev" ]; do 481 | prev=$str 482 | 483 | str=${str%_hi} 484 | str=${str%_lo} 485 | done 486 | 487 | [ "x$str" = xhi ] || [ "x$str" = xlo ] || { 488 | warning "check_position_string: position \"$position\" is not in the format \"(hi|lo)(_(hi|lo))*\"" 489 | return $ex_dataerr 490 | } 491 | } 492 | 493 | check_position_code() { 494 | local switch="$1" 495 | local position_name="$2" 496 | local codes="$3" 497 | local code 498 | 499 | get_position_code code "$switch" "$position_name" 500 | 501 | ! list_contains "$codes" "$code" || { 502 | error "check_position_code: switch \"$switch\" cannot have both a position name \"$position_name\" and a code \"$code\"" 503 | return $ex_dataerr 504 | } 505 | } 506 | 507 | validate_switches_initial() { 508 | local switches 509 | local switch 510 | 511 | json_set_namespace switches 512 | json_select 513 | 514 | json_get_keys switches 515 | 516 | [ -n "$switches" ] || warning "validate_switches_initial: no switches defined" 517 | 518 | for switch in $switches; do 519 | debug "validate_switches_initial: checking switch \"$switch\"" 520 | 521 | check_nonempty_string "$switch" "switch name" && 522 | check_safe_string "$switch" "switch name" && 523 | check_json_type "$switch" object || return 524 | done 525 | } 526 | 527 | validate_switches_details() { 528 | local switches 529 | local switch 530 | local labels_indices 531 | local label 532 | local codes 533 | local positions 534 | local position 535 | local position_name 536 | local i 537 | 538 | json_set_namespace switches 539 | json_select 540 | 541 | json_get_keys switches 542 | 543 | for switch in $switches; do 544 | json_select 545 | json_select "$switch" 546 | 547 | debug "validate_switches_details: checking data for switch \"$switch\"" 548 | 549 | check_json_type labels array "$switch.labels" && 550 | check_json_type codes array "$switch.codes" && 551 | check_json_type positions object "$switch.positions" || return 552 | 553 | json_get_keys labels_indices labels 554 | json_get_values codes codes 555 | json_get_keys positions positions 556 | 557 | [ -n "$labels_indices" ] || warning "validate_switches_details: no labels defined for switch \"$switch\"" 558 | [ -n "$codes" ] || warning "validate_switches_details: no codes defined for switch \"$switch\"" 559 | [ -n "$positions" ] || warning "validate_switches_details: no positions defined for switch \"$switch\"" 560 | 561 | json_select labels 562 | 563 | for i in $labels_indices; do 564 | json_get_var label "$i" 565 | check_input_gpio_label "$label" || return 566 | done 567 | 568 | json_select .. 569 | json_select positions 570 | 571 | for position in $positions; do 572 | check_position_string "$position" || continue 573 | 574 | check_json_type "$position" string "$switch.positions.$position" || return 575 | 576 | json_get_var position_name "$position" 577 | 578 | check_nonempty_string "$position_name" "position name" && 579 | check_safe_string "$position_name" "position name" && 580 | check_position_code "$switch" "$position_name" "$codes" || return 581 | done 582 | done 583 | } 584 | 585 | 586 | load_switch_data_from_cache() { 587 | [ -f "$switches_cache" ] && [ -r "$switches_cache" ] || { 588 | debug "load_switch_data_from_cache: cannot read $switches_cache" 589 | return 1 590 | } 591 | 592 | info "load_switch_data_from_cache: loading switch data from $switches_cache" 593 | 594 | json_set_namespace switches 595 | json_load_file "$switches_cache" 596 | } 597 | 598 | save_switch_data_to_cache() { 599 | is_root || { 600 | debug "save_switch_data_to_cache: user must be root" 601 | return 602 | } 603 | 604 | debug "save_switch_data_to_cache: caching switch data to $switches_cache" 605 | 606 | mkdir -p "${switches_cache%/*}" 607 | 608 | json_set_namespace switches 609 | json_select 610 | json_dump > "$switches_cache" 611 | } 612 | 613 | load_switch_data_from_file() { 614 | local _var="$1" 615 | local _data_file="$2" 616 | local _board="$3" 617 | local _no_alt_board_name="$4" 618 | local _type 619 | local _alt_board 620 | local _data 621 | 622 | debug "load_switch_data_from_file: attempting to load switch data for board \"$_board\" from $_data_file" 623 | 624 | is_valid_switch_data_file "$_data_file" || { 625 | error "load_switch_data_from_file: failed to parse $_data_file" 626 | return $ex_dataerr 627 | } 628 | 629 | get_switch_data_file_board_data_type _type "$_data_file" "$_board" 630 | 631 | [ -z "$_no_alt_board_name" ] && [ "x$_type" = xstring ] && { 632 | debug "load_switch_data_from_file: board \"$_board\" shares switch data with another model, loading alternate board name" 633 | 634 | get_switch_data_file_board_data _alt_board "$_data_file" "$_board" 635 | 636 | [ -n "$_alt_board" ] || { 637 | error "load_switch_data_from_file: missing alternate board name for board \"$_board\" in $_data_file" 638 | return $ex_dataerr 639 | } 640 | 641 | info "load_switch_data_from_file: using alternate board name \"$_alt_board\" for board \"$_board\"" 642 | 643 | _board=$_alt_board 644 | get_switch_data_file_board_data_type _type "$_data_file" "$_board" 645 | } 646 | 647 | [ -n "$_type" ] || { 648 | debug "load_switch_data_from_file: board \"$_board\" not found in $_data_file" 649 | _set_var "$_var" "$_board" 650 | return $ex_unavailable 651 | } 652 | 653 | [ "x$_type" = xobject ] || { 654 | error "load_switch_data_from_file: \"$_board\" is not an object in $_data_file" 655 | return $ex_dataerr 656 | } 657 | 658 | info "load_switch_data_from_file: loading switch data for board \"$_board\" from $_data_file" 659 | 660 | get_switch_data_file_board_data _data "$_data_file" "$_board" 661 | 662 | json_set_namespace switches 663 | json_load "$_data" 664 | } 665 | 666 | load_switch_data() { 667 | local no_load_from_cache="$1" 668 | local no_save_to_cache="$2" 669 | local board 670 | local final_board 671 | local result 672 | local no_alt_board_name 673 | 674 | [ -z "$no_load_from_cache" ] && load_switch_data_from_cache && return 675 | 676 | get_board board && [ -n "$board" ] || { 677 | error "load_switch_data: missing board name" 678 | return $ex_dataerr 679 | } 680 | 681 | [ -f "$custom_switch_data_file" ] && [ -r "$custom_switch_data_file" ] && { 682 | info "load_switch_data: attempting to load switch data for board \"$board\" from $custom_switch_data_file" 683 | 684 | load_switch_data_from_file final_board "$custom_switch_data_file" "$board" 685 | result=$? 686 | 687 | [ "$result" -ne 0 ] && { 688 | [ "$result" -ne "$ex_unavailable" ] && return $result 689 | 690 | notice "load_switch_data: board \"$final_board\" not found in $custom_switch_data_file" 691 | 692 | [ "x$final_board" != "x$board" ] && { 693 | board=$final_board 694 | no_alt_board_name=1 695 | } 696 | 697 | result= 698 | } 699 | } 700 | 701 | [ -z "$result" ] && { 702 | debug "load_switch_data: attempting to load switch data for board \"$board\" from $switch_data_file" 703 | 704 | load_switch_data_from_file final_board "$switch_data_file" "$board" "$no_alt_board_name" 705 | result=$? 706 | 707 | [ "$result" -ne 0 ] && { 708 | [ "$result" -eq "$ex_unavailable" ] && warning "load_switch_data: board \"$final_board\" not found in $switch_data_file" 709 | 710 | return $result 711 | } 712 | } 713 | 714 | validate_switches_initial || return 715 | 716 | is_keys_available && { 717 | populate_switches_details || return 718 | } 719 | 720 | validate_switches_details || return 721 | 722 | [ -z "$no_save_to_cache" ] && save_switch_data_to_cache 723 | 724 | return 0 725 | } 726 | 727 | 728 | get_switches() { 729 | local _var="$1" 730 | 731 | json_set_namespace switches 732 | json_select 733 | 734 | json_get_keys "$_var" 735 | } 736 | 737 | get_switch_for_button() { 738 | local _var="$1" 739 | local _button="$2" 740 | local _switches 741 | local _switch 742 | local _codes 743 | 744 | json_set_namespace switches 745 | json_select 746 | 747 | json_get_keys _switches 748 | 749 | for _switch in $_switches; do 750 | json_select 751 | json_select "$_switch" 752 | 753 | json_get_values _codes codes 754 | 755 | list_contains "$_codes" "$_button" && { 756 | debug "get_switch_for_button: found switch \"$_switch\" for button \"$_button\"" 757 | _set_var "$_var" "$_switch" 758 | return 759 | } 760 | done 761 | 762 | debug "get_switch_for_button: no switches found for button \"$_button\"" 763 | return 1 764 | } 765 | 766 | get_current_position() { 767 | local _var="$1" 768 | local _switch="$2" 769 | local _labels_indices 770 | local _label 771 | local _value 772 | local _position 773 | local _i 774 | 775 | json_set_namespace switches 776 | json_select 777 | json_select "$_switch" 778 | json_select labels 779 | 780 | json_get_keys _labels_indices 781 | 782 | for _i in $_labels_indices; do 783 | json_get_var _label "$_i" 784 | get_gpio_value _value "$_label" || return 785 | _position="${_position}_$_value" 786 | done 787 | 788 | _set_var "$_var" "${_position#_}" 789 | } 790 | 791 | get_position_name() { 792 | local _var="$1" 793 | local _switch="$2" 794 | local _position="$3" 795 | 796 | json_set_namespace switches 797 | json_select 798 | json_select "$_switch" 799 | json_select positions 800 | 801 | json_get_var "$_var" "$_position" 802 | } 803 | 804 | 805 | get_state_file() { 806 | local _var="$1" 807 | local _switch="$2" 808 | 809 | _set_var "$_var" "$state_dir/$_switch" 810 | } 811 | 812 | init_state() { 813 | local switch="$1" 814 | local now="$2" 815 | local positions 816 | local position 817 | 818 | debug "init_state: initializing state for switch \"$switch\"" 819 | 820 | json_set_namespace switches 821 | json_select 822 | json_select "$switch" 823 | 824 | json_get_keys positions positions 825 | 826 | get_current_position position "$switch" || return 827 | 828 | debug "init_state: setting \"$position\" as initial position for switch \"$switch\"" 829 | 830 | json_set_namespace state 831 | json_init 832 | 833 | json_add_string position "$position" 834 | 835 | json_add_object seen 836 | for position in $positions; do 837 | json_add_int "$position" "$now" 838 | done 839 | json_close_object 840 | } 841 | 842 | has_state() { 843 | local switch="$1" 844 | local state_file 845 | 846 | get_state_file state_file "$switch" 847 | 848 | [ -f "$state_file" ] && [ -r "$state_file" ] 849 | } 850 | 851 | load_state() { 852 | local switch="$1" 853 | local state_file 854 | 855 | has_state "$switch" || { 856 | debug "load_state: state for switch \"$switch\" has not been initialized" 857 | return 1 858 | } 859 | 860 | get_state_file state_file "$switch" 861 | 862 | debug "load_state: loading state for switch \"$switch\" from $state_file" 863 | 864 | json_set_namespace state 865 | json_load_file "$state_file" 866 | } 867 | 868 | save_state() { 869 | local switch="$1" 870 | local state_file 871 | 872 | get_state_file state_file "$switch" 873 | 874 | debug "save_state: saving state for switch \"$switch\" to $state_file" 875 | 876 | mkdir -p "${state_file%/*}" 877 | 878 | json_set_namespace state 879 | json_select 880 | json_dump > "$state_file" 881 | } 882 | 883 | 884 | get_state_position() { 885 | local _var="$1" 886 | 887 | json_set_namespace state 888 | json_select 889 | 890 | json_get_var "$_var" position 891 | } 892 | 893 | set_state_position() { 894 | local position="$1" 895 | 896 | json_set_namespace state 897 | json_select 898 | 899 | json_add_string position "$position" 900 | } 901 | 902 | get_state_seen() { 903 | local _var="$1" 904 | local _position="$2" 905 | 906 | json_set_namespace state 907 | json_select 908 | json_select seen 909 | 910 | json_get_var "$_var" "$_position" 911 | } 912 | 913 | set_state_seen() { 914 | local position="$1" 915 | local seen="$2" 916 | 917 | json_set_namespace state 918 | json_select 919 | json_select seen 920 | 921 | json_add_int "$position" "$seen" 922 | } 923 | 924 | 925 | get_lock_dir() { 926 | local _var="$1" 927 | local _switch="$2" 928 | 929 | _set_var "$_var" "$lock_dir/$_switch" 930 | } 931 | 932 | cleanup_locks() { 933 | local switch 934 | local switch_lock_dir 935 | 936 | for switch in $locks; do 937 | get_lock_dir switch_lock_dir "$switch" 938 | 939 | [ -d "$switch_lock_dir" ] || { 940 | warning "cleanup_locks: cannot find lock for switch \"$switch\" ($switch_lock_dir)" 941 | continue 942 | } 943 | 944 | debug "cleanup_locks: removing lock for switch \"$switch\" ($switch_lock_dir)" 945 | rmdir --ignore-fail-on-non-empty "$switch_lock_dir" 946 | done 947 | 948 | locks= 949 | } 950 | 951 | get_lock() { 952 | local switch="$1" 953 | local switch_lock_dir 954 | 955 | get_lock_dir switch_lock_dir "$switch" 956 | 957 | mkdir -p "${switch_lock_dir%/*}" 958 | 959 | mkdir "$switch_lock_dir" 2>/dev/null || { 960 | debug "get_lock: failed to get lock for switch \"$switch\" ($switch_lock_dir)" 961 | return 1 962 | } 963 | 964 | locks="$locks $switch" 965 | 966 | trap 'cleanup_locks' EXIT 967 | trap 'cleanup_locks; trap - INT; kill -INT $$' INT 968 | trap 'exit 129' HUP 969 | trap 'exit 131' QUIT 970 | trap 'exit 143' TERM 971 | 972 | debug "get_lock: got lock for $switch ($switch_lock_dir)" 973 | } 974 | 975 | release_locks() { 976 | debug "release_locks: releasing locks" 977 | 978 | cleanup_locks 979 | 980 | trap - EXIT INT HUP QUIT TERM 981 | } 982 | 983 | 984 | trigger_button_event() { 985 | local switch="$1" 986 | local position="$2" 987 | local action="$3" 988 | local now="$4" 989 | local position_name 990 | local before 991 | local button 992 | local seen 993 | 994 | get_position_name position_name "$switch" "$position" 995 | 996 | [ -n "$position_name" ] || { 997 | warning "trigger_button_event: could not get position name for switch \"$switch\" and position \"$position\"" 998 | return 1 999 | } 1000 | 1001 | get_state_seen before "$position" 1002 | set_state_seen "$position" "$now" 1003 | 1004 | get_position_code button "$switch" "$position_name" 1005 | seen=$((now - before)) 1006 | 1007 | notice "trigger_button_event: triggering button event with BUTTON=\"$button\" ACTION=\"$action\" SEEN=\"$seen\"" 1008 | 1009 | ( 1010 | export BUTTON="$button" 1011 | export ACTION="$action" 1012 | export SEEN="$seen" 1013 | 1014 | debug "trigger_button_event: attempting to call $hotplug_call" 1015 | [ -x "$hotplug_call" ] && "$hotplug_call" button 1016 | 1017 | debug "trigger_button_event: attempting to call $rc_button/$button" 1018 | [ -x "$rc_button/$button" ] && "$rc_button/$button" 1019 | ) 1020 | 1021 | return 0 1022 | } 1023 | 1024 | 1025 | show_usage() { 1026 | cat <<- EOF 1027 | Usage: $me [OPTION]... COMMAND [ARGUMENT]... 1028 | Print slide switch information, or trigger button presses and releases 1029 | 1030 | Options: 1031 | --log=WHERE output logging messages to WHERE: 1032 | 'stderr', 'syslog', 'all', 'none' 1033 | (default: 'stderr') 1034 | --verbosity=LEVEL output logging messages at LEVEL or higher; 1035 | LEVEL is a syslog level keyword or value 1036 | (default: 'notice') 1037 | --help display this help and exit 1038 | --version output version information and exit 1039 | 1040 | Commands: 1041 | init initialize slide switch state information 1042 | update [ARGUMENT]... trigger button presses and releases for the 1043 | listed switch names and/or buttons, or for 1044 | all slide switches if no names given; 1045 | include '-f' or '--force' to trigger button 1046 | presses even when no switch position changes 1047 | have occurred 1048 | switch print list of slide switches for this device 1049 | position NAME print current position of slide switch NAME 1050 | clean remove slide switch state information 1051 | boot STATUS whether to trigger button presses on boot; 1052 | STATUS is 'enable' or 'disable' 1053 | (default: 'enable') 1054 | 1055 | $package home page: 1056 | EOF 1057 | } 1058 | 1059 | 1060 | set_log() { 1061 | local value="$1" 1062 | 1063 | case $value in 1064 | none) log_stderr= ; log_syslog= ;; 1065 | stderr) log_stderr=1; log_syslog= ;; 1066 | syslog) log_stderr= ; log_syslog=1 ;; 1067 | all) log_stderr=1; log_syslog=1 ;; 1068 | 1069 | *) error "invalid log value \"$value\""; show_usage; return $ex_usage ;; 1070 | esac 1071 | } 1072 | 1073 | set_verbosity() { 1074 | local value="$1" 1075 | 1076 | log_level_to_num verbosity "$value" || { 1077 | error "invalid verbosity value \"$value\"" 1078 | show_usage 1079 | return $ex_usage 1080 | } 1081 | } 1082 | 1083 | 1084 | do_init() { 1085 | local switches 1086 | local switch 1087 | local now 1088 | 1089 | check_prerequisites && 1090 | require_root && 1091 | load_switch_data no_load_from_cache || return 1092 | 1093 | get_switches switches 1094 | get_epoch now || return 1095 | 1096 | for switch in $switches; do 1097 | get_lock "$switch" || { 1098 | warning "init: cannot get lock for switch \"$switch\"" 1099 | continue 1100 | } 1101 | 1102 | debug "init: initializing switch \"$switch\"" 1103 | 1104 | init_state "$switch" "$now" || return 1105 | save_state "$switch" 1106 | done 1107 | 1108 | release_locks 1109 | } 1110 | 1111 | do_update() { 1112 | local switches 1113 | local switch 1114 | local force 1115 | local has_requested 1116 | local requested 1117 | local locked 1118 | local now 1119 | local current 1120 | local previous 1121 | local arg 1122 | 1123 | check_prerequisites && 1124 | require_root && 1125 | load_switch_data || return 1126 | 1127 | get_switches switches 1128 | 1129 | for arg in "$@"; do 1130 | case $arg in 1131 | -f|--force) 1132 | debug "update: given --force option" 1133 | force=1 1134 | continue 1135 | ;; 1136 | esac 1137 | 1138 | is_safe_string "$arg" || { 1139 | error "update: \"$arg\" is not a valid switch name or button" 1140 | show_usage 1141 | return $ex_usage 1142 | } 1143 | 1144 | has_requested=1 1145 | switch= 1146 | 1147 | list_contains "$switches" "$arg" && { 1148 | debug "update: \"$arg\" is a switch name" 1149 | switch=$arg 1150 | } 1151 | 1152 | [ -z "$switch" ] && { 1153 | get_switch_for_button switch "$arg" && 1154 | [ -n "$switch" ] && 1155 | debug "update: \"$arg\" is a button for switch \"$switch\"" 1156 | } 1157 | 1158 | [ -n "$switch" ] || { 1159 | debug "update: \"$arg\" is not a switch name or button" 1160 | continue 1161 | } 1162 | 1163 | ! list_contains "$requested" "$switch" && requested="$requested $switch" 1164 | done 1165 | 1166 | [ -z "$has_requested" ] && { 1167 | notice "update: no switch names or buttons given, updating all switches" 1168 | requested=$switches 1169 | } 1170 | 1171 | for switch in $requested; do 1172 | has_state "$switch" || { 1173 | debug "update: state for switch \"$switch\" has not been initialized" 1174 | continue 1175 | } 1176 | 1177 | get_lock "$switch" || { 1178 | debug "update: cannot get lock for switch \"$switch\"" 1179 | continue 1180 | } 1181 | 1182 | locked="$locked $switch" 1183 | done 1184 | 1185 | [ -n "$locked" ] || { 1186 | debug "update: no switches to update" 1187 | return 1188 | } 1189 | 1190 | sleep 1 1191 | 1192 | get_epoch now || return 1193 | 1194 | for switch in $locked; do 1195 | load_state "$switch" || { 1196 | warning "update: cannot load state for switch \"$switch\"" 1197 | continue 1198 | } 1199 | 1200 | get_state_position previous 1201 | get_current_position current "$switch" || return 1202 | 1203 | debug "update: previous position for switch \"$switch\" is \"$previous\"" 1204 | debug "update: current position for switch \"$switch\" is \"$current\"" 1205 | 1206 | [ -n "$force" ] && [ "x$current" = "x$previous" ] && { 1207 | debug "update: forcing update for switch \"$switch\"" 1208 | previous= 1209 | } 1210 | 1211 | [ "x$current" != "x$previous" ] || { 1212 | debug "update: switch \"$switch\" position unchanged" 1213 | continue 1214 | } 1215 | 1216 | [ -n "$previous" ] && trigger_button_event "$switch" "$previous" released "$now" 1217 | trigger_button_event "$switch" "$current" pressed "$now" 1218 | 1219 | set_state_position "$current" 1220 | save_state "$switch" 1221 | done 1222 | 1223 | release_locks 1224 | } 1225 | 1226 | do_switch() { 1227 | local switches 1228 | local switch 1229 | 1230 | check_prerequisites && 1231 | load_switch_data '' no_save_to_cache || return 1232 | 1233 | get_switches switches 1234 | 1235 | for switch in $switches; do 1236 | echo "$switch" 1237 | done 1238 | } 1239 | 1240 | do_position() { 1241 | local switch="$1" 1242 | local switches 1243 | local position 1244 | local position_name 1245 | 1246 | check_prerequisites && 1247 | load_switch_data '' no_save_to_cache || return 1248 | 1249 | get_switches switches 1250 | 1251 | [ -n "$switch" ] || { 1252 | error "position: missing switch name" 1253 | show_usage 1254 | return $ex_usage 1255 | } 1256 | 1257 | is_safe_string "$switch" || { 1258 | error "position: \"$switch\" is not a valid switch name" 1259 | show_usage 1260 | return $ex_usage 1261 | } 1262 | 1263 | list_contains "$switches" "$switch" || { 1264 | error "position: cannot find switch \"$switch\"" 1265 | show_usage 1266 | return $ex_usage 1267 | } 1268 | 1269 | get_current_position position "$switch" || return 1270 | get_position_name position_name "$switch" "$position" 1271 | 1272 | echo "$position_name" 1273 | } 1274 | 1275 | do_clean() { 1276 | local switches 1277 | local switch 1278 | local state_file 1279 | local switch_lock_dir 1280 | 1281 | check_prerequisites && 1282 | require_root && 1283 | load_switch_data no_load_from_cache no_save_to_cache || return 1284 | 1285 | get_switches switches 1286 | 1287 | for switch in $switches; do 1288 | get_state_file state_file "$switch" 1289 | get_lock_dir switch_lock_dir "$switch" 1290 | 1291 | debug "clean: removing state for switch \"$switch\" ($state_file)" 1292 | rm -f "$state_file" 1293 | 1294 | debug "clean: removing lock for switch \"$switch\" ($switch_lock_dir)" 1295 | [ -d "$switch_lock_dir" ] && rmdir --ignore-fail-on-non-empty "$switch_lock_dir" 1296 | done 1297 | 1298 | debug "clean: removing $switches_cache" 1299 | rm -f "$switches_cache" 1300 | 1301 | debug "clean: removing $state_dir, $run_dir, $lock_dir" 1302 | rmdir --ignore-fail-on-non-empty "$state_dir" "$run_dir" "$lock_dir" 2>/dev/null 1303 | 1304 | return 0 1305 | } 1306 | 1307 | do_boot() { 1308 | local action="$1" 1309 | 1310 | require_root || return 1311 | 1312 | [ -x "$update_initd_script" ] || { 1313 | error "boot: init.d script $update_initd_script not found or not executable" 1314 | return $ex_unavailable 1315 | } 1316 | 1317 | [ "x$action" = xenable ] || [ "x$action" = xdisable ] || { 1318 | error "boot: invalid argument \"$action\"" 1319 | show_usage 1320 | return $ex_usage 1321 | } 1322 | 1323 | debug "boot: calling $update_initd_script $action" 1324 | "$update_initd_script" "$action" 1325 | } 1326 | 1327 | do_version() { 1328 | echo "$me $version" 1329 | } 1330 | --------------------------------------------------------------------------------