Skip to content

Instantly share code, notes, and snippets.

@cmattoon
Last active June 12, 2017 12:03
Show Gist options
  • Save cmattoon/985e44ae289aa26d10b14ff5e8e4742d to your computer and use it in GitHub Desktop.
Save cmattoon/985e44ae289aa26d10b14ff5e8e4742d to your computer and use it in GitHub Desktop.
Init.sh
#!/bin/bash
# wget <raw_url>
# chmod +x init.sh
# ./init.sh
if [ "${EUID}" != "0" ]; then
echo "You must be root"
exit 1;
fi
PRINTER_IP="192.168.1.7"
PPD_FILE="/usr/share/ppd/canonmx920.ppd"
CHROME_STABLE="google-chrome-stable"
CHROME_SOURCES_LIST="/etc/apt/sources.list.d/google-chrome.list"
PACKAGES=( cups emacs24-nox python-dev python-setuptools )
PRINTER_URL="http://${PRINTER_IP}/index.html"
PRITNER_GREP_TAG="Canon MX920 series"
log_msg() {
echo -e " [\033[32m+\033[0m] ${1}"
}
log_error() {
echo -e " [\033[31m!\033[0m] ${1}"
exit ${2:-1}
}
install_package() {
pkg=${1:-""}
if [ ! -z "${pkg}" ]; then
PKG_OK=$(dpkg-query -W --showformat='${Status}\n' "${pkg}" | grep "install ok installed")
if [ "" == "${PKG_OK}" ]; then
log_msg "Installing ${pkg}..."
apt-get --force-yes --yes-install "${pkg}"
else
log_msg "Skipping '${pkg}' (installed)"
fi
fi
}
install_chrome() {
CHROME=$(which "${CHROME_STABLE}")
if [ -z "${CHROME}" ]; then
log_msg "Installing google-chrome"
# Download/add public key (for signing)
wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | sudo apt-key add -
if [ ! -f "${CHROME_SOURCES_LIST}" ]; then
log_msg "Adding to ${CHROME_SOURCES_LIST}"
echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" > "${CHROME_SOURCES_LIST}"
log_msg "Updating repositories..."
apt-get update
fi
install_package "${CHROME_STABLE}"
fi
chrome_stable=$(which google-chrome-stable)
if [ -f "${chrome_stable}" ]; then
log_msg "Setting $(which google-chrome-stable)"
rm /etc/alternatives/x-www-browser
ln -s "$(which google-chrome-stable)" "/etc/alternatives/x-www-browser"
fi
}
log_msg "\033[43;90;1m :-P \033[0m"
echo 'alias letitgo="python -m webbrowser https://youtu.be/L0MK7qz13bU?t=1m4s"' >> ~/.bashrc
echo 'alias letitgo2="python -m webbrowser https://youtu.be/L0MK7qz13bU?t=2m5s"' >> ~/.bashrc
echo 'alias letitgo3="python -m webbrowser https://youtu.be/L0MK7qz13bU?t=3m2s"' >> ~/.bashrc
source ~/.bashrc
# Install necessary packages
for pkg in "${PACKAGES[@]}"
do
install_package "${pkg}"
done
driver=$(lpinfo -m | grep MX922)
if [ -z "${driver}" ]; then
echo -e " [\033[31m!\033[0m] Can't find printers for MX922\033[0m"
exit 2;
fi
log_msg "Found driver \033[1m${driver}\033[0m"
# Check if the printer drivers are installed.
# If not, download the tar.gz file, extract, and install
# the two *.deb files
if [ ! -f "${PPD_FILE}" ]; then
log_msg "Missing '${PPD_FILE}'. Downloading printer drivers..."
wget http://gdlp01.c-wss.com/gds/0/0100005170/01/cnijfilter-mx920series-3.90-1-deb.tar.gz
tar -zxvf cnijfilter-mx920series-3.90-1-deb.tar.gz
dpkg -i cnijfilter-mx920series-3.90-1-deb/packages/cnijfilter-common_3.90-1_amd64.deb
dpkg -i cnijfilter-mx920series-3.90-1-deb/packages/cnijfilter-mx920series_3.90-1_amd64.deb
fi
log_msg "Checking that printer is reachable at ${PRINTER_IP}"
html=$(curl -s "${PRINTER_URL}" | grep "${PRINTER_GREP_TAG}")
[ -z "${html}" ] && log_error "Can't find printer at ${PRINTER_URL}"
log_msg "Configuring Printer"
lpadmin -p "Canon-MX922" \
-v "ipp://${PRINTER_IP}" \
-P"${PPD_FILE}" \
-L "CLASSIFIED" \
-E
log_msg "Done."
log_msg "Launching CUPS Admin: http://localhost:631/printers"
THE_USER=$(ls /home | grep -v "lost+found" | grep -v "root")
sudo -u "${THE_USER}" bash -c 'python -m webbrowser "http://localhost:631/printers"'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment