Người sử dụng thời đại công nghiệp 4.0 cũng thay đổi, họ thông minh hơn và không chỉ chấp nhận cách sử dụng giản đơn. Một số công ty đang tăng khả năng tùy biến tới người dùng cho sản phẩm của họ.
Lại nói năng lực điện toán. Trong các lệnh shell thông dụng thì năng lực điện toán thể hiện mạnh nhất ở việc xử lý biểu thức chính quy, trong đó là sản sinh văn bản tự động và đoán nhận ngôn ngữ.
Captprinter-setup là một chương trình kịch bản, nó xây dựng biểu thức chính quy để kiểm tra tham số nhập vào của người dùng cuối, đảm bảo nhận đúng định dạng đối với tham số có phần phức tạp như địa chỉ IP.
Tính năng của Captprinter-setup và hướng dẫn sử dụng nằm trong bài Captprinter-setup – Chương trình cài đặt driver máy in Canon CAPT.
Captprinter-setup 2.0 thay thế việc chạy các kịch bản khởi động của cupsd và ccpd (Canon CAPT Printer Daemon) trong systemV của phiên bản trước bằng chạy các dịch vụ tương ứng trong systemd.
Ngoài ra, Captprinter-setup 2.0 cải tiến để đáp ứng số lượng máy in thay đổi trong hệ thống, không còn giới hạn 1 máy như phiên bản trước.
Toàn bộ nội dung chương trình ở dưới đây. Bạn xem phần license đầu chương trình trước khi sử dụng, nó đảm bảo quyền sử dụng của người dùng và giới hạn trách nhiệm của tác giả.
Vì chương trình này được viết cho Omarine 3.0 là phiên bản chưa phát hành, bạn có thể phải sửa đổi mã cho phù hợp với hệ thống của mình.
#!/bin/sh # =========================================================================== # Captprinter-setup - A tool to install Canon CAPT Printer Driver. # Copyright (C) 2015 - 2017 Pham Thanh Tuyen <phamtyn@gmail.com> # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # You should have received a copy of the GNU General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. # =========================================================================== VERSION=2.0 PATH=/bin:/usr/bin:/sbin:/usr/sbin PRINTER_FAMILY="LBP-1120 LBP-1210 LBP2900 LBP3000 LBP3010 LBP3018 LBP3050 LBP3100 LBP3108 LBP3150 \ LBP3200 LBP3210 LBP3250 LBP3300 LBP3310 LBP3500 LBP5000 LBP5050 LBP5100 LBP5300 LBP6000 LBP6018 \ LBP6020 LBP6200 LBP6300n LBP6300dn LBP6310dn LBP7010C LBP7018C LBP7200C LBP7210Cdn LBP9100Cdn" IP_REGEXP="^([1-9][0-9]?|1[0-9]{2}|2[0-4][0-9]|25[0-5])(\.([0-9]{1,2}|1[0-9]{2}|2[0-4][0-9]|25[0-5])){3}$" HELP_MESSAGE="This progam is a tool to install Canon CAPT Printer Driver \ for Omarine system.\n\n" HELP_MESSAGE2="is one of names in the following list:\n$PRINTER_FAMILY\n\n" HELP_MESSAGE3="is ip address to use the network printer. \ Please consider to edit /etc/cups/cupsd.conf to change the CUPS security settings accordingly.\ \n\n*If you do your print job but see nothing on output, please run following command to monitor \ the print status:" echo_success() { local RES_COL=60 echo -en \\033[${RES_COL}G echo -n "[" echo -en "\\033[1;32m" echo -n $" OK " echo -en "\\033[0;39m" echo -n "]" echo -ne "\r" return 0 } echo_color() { echo -en "\\033[1;${2}m" echo -en $1 echo -en "\\033[0;39m" return 0 } usage() { echo -e "\n\ captprinter-setup - version $VERSION\n\ \nUsage:\n" echo_color \ "\t`basename $0` PRINTER_NAME [IP]\n \t`basename $0` [IP] PRINTER_NAME\n \t`basename $0` --help\n\n " 37 echo -en $HELP_MESSAGE | fold -s echo_color "PRINTER_NAME" 37 echo -n " " echo -en $HELP_MESSAGE2 | fold -s echo_color "IP" 37 echo -n " " echo -en $HELP_MESSAGE3 | fold -s echo -n " " echo_color "captstatusui -P PRINTER_NAME\n" 37 echo "" exit } check_rootuser(){ if [ "$(id -u)" != "0" ]; then echo -e "\n\ Only root can setup the printer.\n\ You can run captprinter-setup with sudo command.\n" usage fi } name2driver() { case $PRINTER_NAME in LBP9100Cdn) PRINTER_DRIVER=CNCUPSLBP9100CCAPTK.ppd ;; LBP7210Cdn) PRINTER_DRIVER=CNCUPSLBP7210CCAPTK.ppd ;; LBP7018C|LBP7010C) PRINTER_DRIVER=CNCUPSLBP7018CCAPTK.ppd ;; LBP6310dn) PRINTER_DRIVER=CNCUPSLBP6310CAPTK.ppd ;; LBP6300dn) PRINTER_DRIVER=CNCUPSLBP6300CAPTK.ppd ;; LBP6018|LBP6000) PRINTER_DRIVER=CNCUPSLBP6018CAPTK.ppd ;; LBP3150/LBP3108/LBP3100) PRINTER_DRIVER=CNCUPSLBP3150CAPTK.ppd ;; LBP3050/LBP3018/LBP3010) PRINTER_DRIVER=CNCUPSLBP3050CAPTK.ppd ;; LBP-1210) PRINTER_DRIVER=CNCUPSLBP1210CAPTK.ppd ;; LBP-1120) PRINTER_DRIVER=CNCUPSLBP1120CAPTK.ppd ;; *) PRINTER_DRIVER=CNCUPS${PRINTER_NAME}CAPTK.ppd esac } setup() { local -i i=0 local -i STATUS=0 local -i count=1 echo echo "Performing setup driver for printer: $PRINTER_NAME" echo "Driver: $PRINTER_DRIVER" echo systemctl --quiet is-active org.cups.cupsd if [ $? -eq 0 ]; then systemctl stop org.cups.cupsd echo "Previous cups was running and has been stopped!" fi systemctl --quiet is-active ccpd if [ $? -eq 0 ]; then systemctl stop ccpd echo "Previous ccpd was running and has been stopped!" rm -rf /var/captmon rm -rf /var/ccpd fi systemctl start org.cups.cupsd sleep 1 echo -n "Registering the printer with the print spooler:" /usr/sbin/lpadmin -p $PRINTER_NAME -m $PRINTER_DRIVER -v ccp://localhost:59687 -E if [ $? -ne 0 ]; then exit 1 else echo_success fi echo echo "Registering the printer with the ccpd daemon..." if [ -z "$IP" ]; then /usr/sbin/ccpdadmin -p $PRINTER_NAME -o /dev/usb/lp0 else /usr/sbin/ccpdadmin -p $PRINTER_NAME -o "net:$IP" fi echo echo "Making a first-in first-out special file..." [ -d /var/captmon ] || mkdir -p /var/captmon [ -d /var/ccpd ] || mkdir -p /var/ccpd [ -e /var/ccpd/fifo0 ] || mkfifo /var/ccpd/fifo0 systemctl --quiet is-enabled ccpd if [ $? -ne 0 ]; then systemctl enable ccpd fi systemctl start ccpd sleep 2 count+=$(ccpdadmin | grep -c '\[[0-9]\+\]') STATUS=$(pidof /usr/sbin/ccpd | wc -w) while [ $STATUS -ne $count -a $i -lt 10 ]; do systemctl restart org.cups.cupsd systemctl restart ccpd sleep 2 STATUS=$(pidof /usr/sbin/ccpd | wc -w) i+=1 done echo [ $STATUS -eq $count ] && echo_success echo -e "\n." echo "Checking status..." pidof /usr/sbin/ccpd if [ $STATUS -eq $count ]; then echo -en "\\033[1;34m" echo -e "\nThe printer driver setup has been successful!" echo -e "Please do power on your printer and make sure it is plugged in the first usb port" echo -e "Be ready to print a test page.\n" echo -en "\\033[0;39m" else echo -en "\\033[1;31m" echo -e "\nSetup has not completed yet!" echo -en "\\033[0;39m" fi echo "." } [ $# -gt 2 ] && echo_color "\nToo many command-line arguments!\n" 31 && usage [ $# -eq 0 ] && echo_color "\nNo printer name!\n" 31 && usage while [ $# -ne 0 ]; do case X$1 in X-h|X--help) usage ;; X$(echo $1 | egrep -o "$(echo $PRINTER_FAMILY | tr " " "|")")) PRINTER_NAME=$1 ;; X$(echo $1 | egrep "$IP_REGEXP")) IP=$1 ;; *) WRONGPARAM=yes ;; esac shift done [ -z "$PRINTER_NAME" -a -n "$IP" -a -z "$WRONGPARAM" ] && echo_color "\nNo printer name!\n" 31 && usage [ -z "$PRINTER_NAME" ] && echo_color "\nThe printer name is not correct!\n" 31 && usage [ "$WRONGPARAM" = yes ] && echo_color "\nInvalid IP address!\n" 31 && usage #======================================================================== # # MAIN PROGRAM # check_rootuser name2driver setup