Cygwin: Difference between revisions

From wikinotes
No edit summary
 
(29 intermediate revisions by the same user not shown)
Line 1: Line 1:
Cygwin is a fully separate (and native) unix system that can run within windows.  
Cygwin provides a unix-like environment to run processes under windows by translating unix syscalls.<br>
Cygwin emulates tools that are exclusive to linux (fork, mmap, ioctl, ...) by passing
It has no CLI package manager, but the installer can be scripted to install packages.
those calls to the cygwin.dll library.  


It's beautiful, you can even run an Xserver and have it integrate with your windows' windows.
= Notes =
You can also run a full linux desktop within your Xwindow (although it is much faster to just use a terminal).
 
Cygwin comes without a CLI package manager, but packages can still be installed automatically using the cygwin installer's commandline arguments.
 
= Install =
<blockquote>
<blockquote>
'''chocolatey installs cygwin to C:\programdata\chocolatey\cygwin\tools\cygwin'''
{|
 
| [[cygwin install]]
Cygwin is built to be able to be run in a portable way. You install, update, and get new packages by
re-running the cygwin installer.
 
Always install the 32 bit version of cygwin, unless you absolutely need it to be 64bit. It is much
more supported. Cygwin doesn't seem to require any registry keys to be set, the only things that
affect it's portability are some environment variables.
 
'''NOTE''' If you are using my package-setup script, always run it with a normal
cygwin http-repo as a source, reboot, then run with the private key for a cygports repo.
If you fail to do this, and run the cygports repo first, you may end up with corrupted packages.
</blockquote><!-- Install -->
 
= Package Management =
<blockquote>
{| class="wikitable"
!colspan=3| Best Sources
|-
|-
| http://lug.mtu.edu || || standard cygwin packages
| [[cygwin package management]]
|-
| http://mirrors.kernel.org/sources.redhat.com/cygwinports/  || || precompiled cygports (https://sourceware.org/cygwinports/)
|}
 
<syntaxhighlight lang="bash">
## Start Cygwin with GPG key for cygports
/path/to/setup-x86.exe -K http://cygwinports.org/ports.gpg
</syntaxhighlight>
 
 
''' CYGPORTS CONTAINS DWM, MPD, NCMPC, PYSIDE '''<br>
Cygwin doesn't have a traditional package manager. There are a few terminal programs you
can use to emulate apt-get, but since on Windows files cannot be deleted or overwritten while they
are running it is best to quit cygwin, and install programs using the installer.
 
Because of cygwin's limited options in the default repo, I find myself compiling packages myself
quite a lot. I created a git repo for compiled (and attempts at compiling) programs for quick (manual)
installations on new machines.
 
There is also a system loosely based on Gentoo's portage to assist in compilation. It is called cygports,
and can be installed from the main package manager.
 
<br>
<br>
 
</blockquote><!-- Package Management -->
 
= Common Problems =
<blockquote>
== rebase ==
<blockquote>
Almost all issues related to cygwin can be resolved by rebasing. You can do it
the quick/dirty way:
 
<syntaxhighlight lang="bash">
C:/cygwin/bin/dash.exe
/bin/rebaseall
 
</syntaxhighlight>
 
Or the full proper way:
<syntaxhighlight lang="bash">
 
- Open Task Manager and close any processes that look to be Cygwin related.
- Open C:\Cygwin\bin in Windows Explorer
  - Verify that dash.exe, ash.exe, rebase.exe, and rebaseall exist in this folder
      - If any of them are missing, re-run Cygwin setup and select the dash, ash, and rebase packages
 
    - right-click your C:\Cygwin folder, uncheck Read-only (if its checked), and press OK.
      - When an error about not being able to switch some files comes up, select "Ignore All". Wait for this process to complete.
 
    - Browse to C:\Cygwin\bin in Windows Explorer
    - Right click dash.exe and click "Run as Administrator". A command Prompt should appear with nothing but a $
    - Type /usr/bin/rebaseall -v, hit enter, and wait for the process to complete.
        - If you get errors about Cygwin processes running, try Step 1 again. If that still doesn't work, Restart your computer into safe mode and try these steps again.
        - A commenter noted that, depending on your settings, you may have to type cd /usr/bin && ./rebaseall -v instead.
    - Try opening Cygwin again.
</syntaxhighlight>
 
{| class="wikinotes"
|-
|-
| http://stackoverflow.com/questions/9300722/cygwin-error-bash-fork-retry-resource-temporarily-unavailable
| [[cygwin configuration]]
|-
|-
| http://cygwin.wikia.com/wiki/Rebaseall
| [[cygwin programs]]
|}
 
 
</blockquote><!-- rebaseall -->
 
</blockquote><!-- Common Problems -->
 
= Programs =
<blockquote>
Cygwin does not by default include a CLI package manager. Instead, you run cygwin.exe with the flag
'config', which updates your existing cygwin (labeled as installation, but only checks for missing/out
of date files). I have included the option of running 'CygwinPers.bat --config'. There are package
managers available for cygwin, such as apt-cyg, but they're pretty awful. It is much better to just
use the default installer.
 
Base Packages:
<syntaxhighlight lang="bash">
## Cygwin Packages
bc
offlineimap
msmtp
mutt
w3m
ncurses
abook
xclip
git, git-completion, gitk, tig
openssh
gcc
automake
python2
python3
 
xorg
rxvt-unicode
nc
nc6
tmux
zsh
irssi
rsync
 
 
## External Packages:
  urlview (win32) -- http://www.oocities.org/win32mutt/win32.html
  mutt with sidebar -- http://www.alexbr.com/wblog/?p=183
 
</syntaxhighlight>
 
== Terminal Programs ==
<blockquote>
{| class="wikitable"
|-
|-
| [[mintty]]
| [[cygwin troubleshooting]]
|-
|-
|}
|}
 
</blockquote><!-- Notes -->
For the bulk of my regular the terminal programs (irssi, pyradio etc),
see Archlinux documentation. This section is only for terminal programs
that require more complicated or different configuration when run in cygwin.
 
=== sshd ===
-----
<blockquote>
Autostarting openssh in cygwin on windows:
 
 
<syntaxhighlight lang="bash">
## Pre Setup Tasks
chmod +r /etc/passwd
chmod +r /etc/groups
chmod 555 /var
</syntaxhighlight>
 
<syntaxhighlight lang="bash">
#### From an ADMINISTRATOR cmd, start cygwin
ssh-host-config                  # and deal with all warnings
                                  # YOU DO NOT WANT SEPARATED AUTHENTICATION
 
ssh-user-config                  #generate all user keys
chmod +rx /bin/bash              #bash must be executable
 
cygrunsrv -S sshd                #test openssh
</syntaxhighlight>
 
<syntaxhighlight lang="bash">
### Troubleshooting
# if cygwin is not starting, or crashing, you can check the logs in
# /var/log/sshd.log
 
# make sure your user has a password (in cygwin):
#    passwd will
 
# if your user doesn't have a passwd entry, make one with
#    mkpasswd -l >> /etc/passwd
 
# cygwin's openSSH requires that the account is an administrator
# and that the windows user has a password in order for a user to login.
# (at least this is what is documented, I have reasons to doubt this)
 
# **NOTE**
# DESPITE THE FACT THAT WINDOWS DOESN'T DISTINGUISH BETWEEN UPPER AND LOWER CASE
# CYGWIN DOES. IF YOUR WINDOWS USER ACCOUNT HAS CAPITAL LETTERS, THE ENTRY IN
# /etc/passwd WILL ALSO HAVE CAPITALS. THIS WILL DENY YOUR LOGIN ATTEMPTS.
# ALSO, DESPITE WHAT IS SAID ON THE INTERNET/DOCUMENTATION, CYGWIN DOES NOT USE
# YOUR WINDOWS USER CREDENTIALS, AND INSTEAD USES THE CYGWIN PASSWD ENTRIES.
 
# make sure that bash is executable
# test if you can login as cyg_server@localhost. If that's working, then
# perhaps you should run ssh-host-config again without the privileged user
# separation. It's only windows after all... if someone really wants in...
 
##openSSH will start automatically on the next windows boot. (using windows services)
</syntaxhighlight>
</blockquote><!-- sshd -->
 
=== Mutt ===
-----
<blockquote>
<pre>
Reuse config files from agnes arch setup.
Install:
  mutt (source), msmtp, w3m,
  ncurses, libncurses-devel,
  abook, offlineimap,
  autobuild, autoconf, automake,
  make, makedepend, openssl,
  openssl-devel, libsasl2-devel
  gcc core, gdbm, libgdbm, libgdbm-devel
  patch, patch-devel,
 
# Do not need
procmail
</pre>
 
When installing mutt, check to install the source code {{{/usr/src/}}}
copy the sideBar patch modified for cygwin: http://www.alexbr.com/wblog/wp-content/uploads/2013/01/patch-cygwin-mutt-1.5.20-1-sidebar.txt
save sidebar patch to /usr/src/mutt*/muttSideBar
 
 
''' recompiling mutt with sideBar '''
<blockquote>
{| class="wikitable" with="70%"
| <pre>mutt-sidebar.patch</pre> || || [[mutt 1.5.22-1 mutt-sidebar.patch|mutt-sidebar.patch]] || mutt sidebar patch tested and working in cygwin
|}
<pre>
cd /usr/src/mutt*/
 
 
autoconf -f -Wall
./configure --enable-imap --enable-pop --with-ssl --enable-smtp --with-homespool=mailspool --enable-hcache --enable-debug --with-sasl
patch -p1 < muttSideBar
make
./mutt (to test)
make install
cp mutt.exe /usr/bin/mutt.exe
</pre>
</blockquote><!-- recompiling mutt with sidebar -->
 
 
''' compile urlview '''
<blockquote>
<pre>
cd /usr/src
git clone https://github.com/sigpipe/urlview
cd urlview
 
./configure
automake --add-missing  #to correct missing depcomp
make clean
make install
cp urlview.exe /usr/bin/
 
</pre>
</blockquote><!-- Cygwin:Mutt: compile urlview -->
 
 
''' offlineimap '''
<blockquote>
Offlineimap requires certificate authentication, and cygwin uses a different certificate file
than linux. Point offlineImap to cygwin's ca-certificate file:
<pre>
/etc/ssl/certs/ca-bundle.crt
</pre>
 
</blockquote><!-- Cygwin:Mutt offlineimap-->
 
 
''' gpg encryption '''
<blockquote>
GPG (GnuPrivacyGuard), the open source version of PGP (pretty good privacy) is encryption
software. It can be used on an entire disk, a directory, a set of files, or with emails
for publickey authentication.
 
My use for gpg at work isn't encrypted emails, but rather an encrypted Maildir.
The hard drive used at work will likely be used long after I am gone with all of
my files intact, I would rather avoid snooping if possible.
 
 
- gnupg (cygwin package) -
<pre>
cygwinpers --config
# search and install
gnupg
 
</pre>
 
 
- mysysgit -
Before I found cygwin's gpg encryption, I used mysysgit for gpg encryption.
Apparently cygwin comes installed with gpg, but I haven't been able to find it or use it.
Instead I'm using gpg from the MySysGit installation. To get this to work:
 
Setup:
<pre>
# Download and Extract to git/bin directory (or same location as gpg.exe)
ftp://ftp.gnupg.org/gcrypt/binary/libiconv-1.9.1.dll.zip
 
# gpg should now run in regular windows
# Will need to create shellscript to be able to run gpg in cygwin
</pre>
 
 
Usage:
<pre>
gpg -c file.txt                #encrypt file
shred -z --remove file.txt      #overwrite all file's bits, and delete
gpg file.txt                    #decrypt file
</pre>
</blockquote> <!-- cygwin:Mutt gpg encryption -->
 
 
''' fetchmail '''
<blockquote>
 
---NOT IN USE---
I had been having problems with ssl certificates using offlineimap, and I turned
to fetchmail as an alternative. You can get emails with fetchmail, and then move them
to their corresponding folder with procmail. This did not keep track of emails on the
imap server however, and I started receiving duplicate emails.
 
Eventually I was able to fix offlineimap by pointing it to cygwin's ca-certificate file:
{{{/etc/ssl/certs/ca-bundle.crt}}} Note that this was after using fetchmail. Perhaps this
accepted the certificate for me?
 
 
</blockquote><!-- Cygwin:Mutt fetchmail -->
</blockquote><!--mutt-->
 
 
=== pyradio ===
----
<blockquote>
Pyradio requires the curses library. It does not work well under windows,
but it works very well under cygwin. Make sure that VLC is copied to a location
on '$PATH' so that it can do all of the legwork in decoding the audio streams.
 
<syntaxhighlight lang="bash">
## create get-pip.py with contents of:
## https://bootstrap.pypa.io/get-pip.py
 
/usr/bin/python2 get-pip.py
pip2 install pyradio
cp $portable/VlCPortable/App/vlc/vlc.exe /usr/bin/cvlc.exe
 
</syntaxhighlight>
</blockquote><!-- pyradio -->
<br>
<br>
 
=== mpd, ncmpcpp ===
----
<blockquote>
There is a lot of dependencies, nice person on internet made script to simplify grabbing all dependencies/compiling.
 
<syntaxhighlight lang="bash">
https://github.com/ahodesuka/getmpd/blob/master/getmpd
 
## Use Cygports (redhat mirror kernel.org)
## setup-x86.exe -K http://cygwinports.org/ports.gpg
 
mpd, zzip, wrap, ncmpc, wavpack, libwavpack,
libvorbisfile, vorbisenc, sndfile, shout, samplerate,
pulse, alsa, opus, openal, dns_sd-1, audiofile-1,
libao
 
 
## cygwin doesn't use ALSA, pulseaudio is available,
## and also portaudio is apparently available (although I'm unsure if
## mpd supports it )
 
 
 
 
 
</syntaxhighlight>
 
</blockquote><!-- mpd, ncmpcpp -->
 
=== vim ===
------
<blockquote>
Vim works perfectly, but some of the plugins have quirks that will need to be rewritten.
These cygwin-specific issues will be  tracked under [[vim]].
 
''' NOTE '''<br>
If you install a plugin, and get errors about ^M line endings in it's source files,
You can fix in a very simple way. Simply open the sourcefile and execute:
<syntaxhighlight lang="vim">
:set ff=unix
:wq
</syntaxhighlight>
 
 
 
</blockquote><!-- vimya -->
</blockquote><!-- vim -->
 
=== utimer ===
------
<blockquote>
A little script for setting alarms from the commandline. I have it all integrated with tmux
though, and especially at work it would be useful to force myself to checkup on people every
now and then, or stretch.
 
https://launchpad.net/utimer
 
<syntaxhighlight lang="bash">
cygwin --config  --> pkgconfig, intltool
 
./configure
make
make install
 
## make install does install the manpage, but
## utimer doesn't seem to be in the correct place
## copy it to /usr/bin
cp src/utimer.exe /usr/bin/
 
</syntaxhighlight>
</blockquote><!-- utimer -->
 
=== unrar ===
------
<blockquote>
 
<syntaxhighlight lang="bash">
curl -#O http://www.rarlab.com/rar/unrarsrc-5.2.4.tar.gz
tar -xvf unrar*
cd unrar*
make -f makefile.cygmin (#doesn't exist)
(I don't have this working yet...)
</syntaxhighlight>
 
</blockquote>
 
=== vifm ===
------
<blockquote>
vifm is a super awesome, and speedy terminal filemanager. I like it a lot.
 
 
<syntaxhighlight lang="bash">
curl -#O http://sourceforge.net/projects/vifm/files/vifm/vifm-0.7.8.tar.bz2/download
tar -xvf vifm*
cd vifm*
./configure
make
cp vifm.exe /usr/bin/
 
</syntaxhighlight>
</blockquote><!-- vifm -->
 
=== ranger ===
------
<blockquote>
Ranger is a vim-style, tabbed, terminal filemanager that lets you browse
through your filesystem and preview files REALLY REALLY QUICKLY. Perfect
for jumping through the script directory.
 
<syntaxhighlight lang="bash">
## Make sure python2.6+ is installed
cd ~
curl -#O http://nongnu.org/ranger/ranger-stable.tar.gz
tar -xvf ranger-stable.tar.gz
cd ranger-X.XX
python setup.py install --optimize=1 --record=install_log.txt
cd ..
rm -rf ranger*
</syntaxhighlight>
</blockquote><!-- ranger -->
 
 
=== sshfs/fuse ===
------
<blockquote>
cygwin doesn't have sshfs per-se, however there are a couple of windows
ports of fuse/sshfs that work marvelously (although require a GUI unfortunately...).
Of the two, dokan is portable, so it will be my preference.
 
Dokan does not accept command-line flags, but a forum user showed his autohotkey
script that he used as a wrapper for it:
 
<syntaxhighlight lang="autohotkey">
Run "C:\Program Files (x86)\Dokan\DokanSSHFS\DokanSSHFS.exe"
sleep 1000
Send {tab}{tab}{tab}{tab}{tab}{tab}{tab}{tab}{tab}{tab}password{tab}{tab}{tab}{tab}{tab}{tab}{enter}
sleep 4000
Send {enter}
</syntaxhighlight>
 
 
{|
| http://dokan-dev.net/en/download/#sshfs
|-
| https://code.google.com/p/win-sshfs/downloads/detail?name=win-sshfs-0.0.1.5-setup.exe&can=2&q=
|}
 
</blockquote><!-- sshfs -->
 
=== ipython ===
------
<blockquote>
<syntaxhighlight lang="bash">
pip2 install ipython
 
 
</syntaxhighlight>
</blockquote><!-- ipython -->
 
 
=== PySide ===
------
<blockquote>
<syntaxhighlight lang="bash">
## Cygwin Install: qt4 (check many packages)
 
cp /usr/bin/qmake-qt4
 
 
git clone https://github.com/PySide/pyside-setup.git pyside-setup
pip2 install wheel
python2 setup.py bdist_wheel --qmake=/usr/bin/qmake-qt4 ## haven't had this work just yet
 
</syntaxhighlight>
</blockquote><!-- PySide -->
 
 
=== (python) schedule ===
-----
<blockquote>
This looks very promising as an alternative to cron that does not require the windows'
task scheduler.
 
{|
https://github.com/dbader/schedule
|}
</blockquote><!-- Schedule -->
 
=== disused ===
<blockquote>
==== statnot ====
------
<blockquote>
statnot is another minimal notifications system. It has less dependencies still than dunst.
 
STATNOT REQUIRES X TO BE RUNNING, WHICH I DON'T WANT TO BOTHER WITH. INSTEAD I'M JUST
USING MY PERSONAL TMUX NOTIFICATION SCRIPT RATHER THAN PASSING IT THROUGH NOTIFY-SEND.
NOTIFY-SEND IS ONLY REALLY USEFUL IN LINUX ANYWAYS IF I'M LOOKING AT A WEB BROWSER. I
CAN REWRITE MY ACTUAL NOTIFICATION SCRIPT TO CALL NOTIFY-SEND OR WINDOWS NOTIFICATIONS
DEPENDING ON THE OSTYPE.
 
<syntaxhighlight lang="bash">
cygwin --config --> python2, python-dbus, python-gtk
 
</syntaxhighlight>
</blockquote><!-- statnot -->
 
==== dunst ====
------
<blockquote>
Dunst is a notification system. I use it to pass messages to all my tmux sessions
so that I don't miss messages or important alarms. It can run headless (sweet).
 
DUE TO THE UNAVAILABILITY OF LIBXDG-BASEDIR IN CYGWN (ALTHOUGH BEING PORTED), I CANNOT USE
DUNST.
 
<syntaxhighlight lang="bash">
cygwin --config --> dbus, libxinerama, libxft, libxss, libnotify
 
# you'll also need to compile some other dependencies:
libxdg-basedir
 
</syntaxhighlight>
</blockquote><!-- dunst -->
</blockquote><!--disused Terminal Programs -->
 
== X Programs ==
<blockquote>
=== Xserver ===
<blockquote>
==== CygwinX ====
{| class="wikitable"
| <pre>%terminal%/cygwin/app/cygwin/cygwinXpers.bat</pre> || || [http://{{SERVERNAME}}/progs/config/cygwin/cygwinXpers.bat cygwinXpers.bat] || personal launcher script
|-
| <pre>~/.xstartwinrc</pre> || || [http://{{SERVERNAME}}/progs/config/cygwin/.startxwinrc .startxwinrc] || customize startup of xwin
|}
 
''' IMPORTANT NOTE'''
IF YOU ARE RUNNING WINDOWS AS A DIFFERENT USER THAN 'will' (ex: willp). My workaround for both
<code>.xinitrc</code>, and <code>.config/openbox</code>. was to use symbolic links to their locations
in will.
<syntaxhighlight lang="bash">
ln -s /home/will /home/willp
</syntaxhighlight>
 
 
<syntaxhighlight lang="bash">
# xorg-xerver
# win-xorg-clipboard
 
# There are options to customize startx and startxwin,
# I prefer to leave startxwin blank because when left alone,
# it can run ANY program as an argument, and it will create a
# windows' window for it.
#### ~/.startxwin ## Any instructions to be run every time startxwin is run
#### ~/.xinitrc ## Any instructions to be run every time startx is run
#### man xwin ## commandline flags for startxwin/startx
 
 
startx (programs to run) -- (xwin flags)
-rootless (no window decorations on xserver)
-keyhook (cygwin sees keypresses before windows) (allows windows key to be used)
 
ex:
startx /usr/bin/openbox  -- -rootless -keyhoook ## start openbox in same windowspace as windows
 
</syntaxhighlight>
<br>
<br>
 
==== WINAPI ====
I'm not entirely sure what this is, or how it works but this is how DWM is able to run
natively in windows, and manage win32 windows ( but not cygwin windows unless launched with
startxwin /usr/bin/<progrm> )
 
 
</blockquote><!-- Xserver -->
<br>
<br>
 
=== Fonts ===
<blockquote>
{|
| <pre>/usr/share/fonts/font.ttf</pre> || font dir
|-
| <pre>fc-list</pre> || list all fonts
|}
There is not a lot of options for fonts in the cygwin package repo, Here
are the fonts that I use most frequently:
 
<syntaxhighlight lang="bash">
## Droid-Sans-Mono (preference)
http://www.fontsquirrel.com/fonts/droid-sans-mono
 
## DejaVu
http://sourceforge.net/projects/dejavu/
 
## copy fonts to /usr/share/fonts/
fc-list ##List all currently available fonts
Urxvt.font: xft:Droid Sans Mono-10 ##Setting font for urxvt in ~/.Xdefaults
 
</syntaxhighlight>
</blockquote><!-- Fonts -->
 
=== feh ===
<blockquote>
feh is an awesome image viewer. requires imlib2
 
<syntaxhighlight lang="bash">
## CYGWIN DEPENDENCIES:
# imlib2, libcurl, libcurl-devel, libpng, libX11, libXinerama, libXt-devel
# make sure to install all imlib, imlib2, libiml, and devel packages from setup.exe
#
# note that when hunting down a package because of a compile error, you can use
# cygcheck for more info ex: cygcheck -p x11/Intrinsic.h
 
curl -#O http://feh.finalrewind.org/feh-2.12.tar.bz2
make
make install
cp feh.exe /usr/bin/
</syntaxhighlight>
 
</blockquote><!-- feh -->
</blockquote><!-- X Programs -->
</blockquote><!-- Programs -->

Latest revision as of 04:03, 2 July 2022

Cygwin provides a unix-like environment to run processes under windows by translating unix syscalls.
It has no CLI package manager, but the installer can be scripted to install packages.

Notes

cygwin install
cygwin package management
cygwin configuration
cygwin programs
cygwin troubleshooting