のえら

技術備忘とかメモとか.間違いはつっこんでいただきたい所存.アフィリエイトはやっていません.

Cygwinのアレやコレ

Cygwinに関するTIPSがたまってきたのでメモする。
全部Windows Server 2008 R2で動作確認済み。

Cygwinのバージョンを確認する

Cygwinを起動し、以下のコマンドを実行する。

uname -a

パッケージ版であれば、以下のコマンドでも確認可能

cygcheck -c cygwin

参考URL:
http://cygwin.com/faq/faq.html#faq.what.version

Cygwinの削除

「プログラムの一覧と機能」に表示されない(アンインストーラがない)ので、手作業でファイルとレジストリを削除する必要がある。
参考URL:
http://cygwin.com/faq/faq.html#faq.setup.uninstall-all

まるっと引用:

Setup has no automatic uninstall facility. The recommended method to remove all of Cygwin is as follows: 

1.If you have any Cygwin services running, remove by repeating the instructions in http://cygwin.com/faq/faq.html#faq.setup.uninstall-service for all services that you installed. Common services that might have been installed are sshd, cron, cygserver, inetd, apache, postgresql, and so on. 

2.Stop the X11 server if it is running, and terminate any Cygwin programs that might be running in the background. Exit the command prompt and ensure that no Cygwin processes remain. Note: If you want to save your mount points for a later reinstall, first save the output of mount -m as described at http://cygwin.com/cygwin-ug-net/using-utils.html#mount. 

3.If you installed cyglsa.dll by running the shell script /usr/bin/cyglsa-config as described in http://cygwin.com/cygwin-ug-net/ntsec.html, then you need to configure Windows to stop using the LSA authentication package. You do so by editing the registry and restoring /HKEY_LOCAL_MACHINE/SYSTEM/CurrentControlSet/Control/Lsa/Authentication Packages back to it's original value of msv1_0, and then rebooting. 

4.Delete the Cygwin root folder and all subfolders. If you get an error that an object is in use, then ensure that you've stopped all services and closed all Cygwin programs. If you get a 'Permission Denied' error then you will need to modify the permissions and/or ownership of the files or folders that are causing the error. For example, sometimes files used by system services end up owned by the SYSTEM account and not writable by regular users. 

The quickest way to delete the entire tree if you run into this problem is to change the ownership of all files and folders to your account. To do this in Windows Explorer, right click on the root Cygwin folder, choose Properties, then the Security tab. If you are using Windows XP Home or Simple File Sharing, you will need to boot into Safe Mode to access the Security tab. Select Advanced, then go to the Owner tab and make sure your account is listed as the owner. Select the 'Replace owner on subcontainers and objects' checkbox and press Ok. After Explorer applies the changes you should be able to delete the entire tree in one operation. Note that you can also achieve this in Cygwin by typing chown -R user / or by using other tools such as CACLS.EXE. 

5.Delete the Cygwin shortcuts on the Desktop and Start Menu, and anything left by setup-x86{_64}.exe in the download directory. However, if you plan to reinstall Cygwin it's a good idea to keep your setup-x86{_64}.exe download directory since you can reinstall the packages left in its cache without redownloading them. 

6.If you added Cygwin to your system path, you should remove it unless you plan to reinstall Cygwin to the same location. Similarly, if you set your CYGWIN environment variable system-wide and don't plan to reinstall, you should remove it. 

7.Finally, if you want to be thorough you can delete the registry tree Software\Cygwin under HKEY_LOCAL_MACHINE and/or HKEY_CURRENT_USER. However, if you followed the directions above you will have already removed everything important. Typically only the installation directory has been stored in the registry at all. 

ざっくり書くと、関連サービス止めてフォルダとレジストリ削除という。

■homeディレクトリ配下のユーザフォルダを削除する

WindowsGUIにて home/[Windowsアカウント名] を削除しようとしても、「許可が必要です」というような警告が表示され、再試行しても削除できなかった。
※他のユーザが使っているアカウントだったのでアカウントを切り替えての作業ができなかった
(GUIからでは)プロセスが使用中、という警告によりアクセス権の変更も不可能。
また、Cygwinを起動して rm コマンドで削除しようとすると、Permission denied エラーになってしまう。
対象のフォルダおよびファイルは、cygwin起動時に新規で作成されるものを含めた以下の6つ。
・home/[username]
・home/[username]/.bashrc
・home/[username]/.bash_profile
・home/[username]/.inputrc
・home/[username]/.profile
・home/[username]/.bash_history

このとき、cygwinでpermissionを確認してみると???になっていた。

解決策:
http://stackoverflow.com/questions/3739477/undeletable-file-in-cygwin
Windowsコマンドから、いったん所有者を変更することで、削除が行えるようになる

手順:
1.コマンドプロンプトを「管理者権限」で起動する
2.所有者を変更するコマンドを実行

takeown /r /f DRIVE:\PATH

成功、となっていれば所有者がAdmin(コマンドプロンプトを実行したユーザ)になっている
3.指定したユーザにアクセス権を付与する
この後フォルダ削除を行うため、現在ログインしているアカウントに対してアクセス権を追加する

icacls DRIVE:\PATH /grant USERNAME:F /T

※コマンド補足
USERNAME ユーザアカウントに、DRIVE:\PATH より下にあるすべてのファイルとサブディレクトリに対してフルアクセス権を付与する
4.コマンド実行後、上記でアクセス権を追加したユーザアカウントでフォルダの削除を行う